Signo.SpecialForms (Signo v0.0.2)

View Source

Macro definitions for core language features.

Summary

Functions

Creates a callable function and assigns in in scope.

Evaluates all expression in a nested scope and then returns the value of the last expression.

An execution branch based a on the condition.

Similar to include/3, but where include/3 exposes and mutates global scope, import/3 executes the file in an isolated container and imports the resulting Signo.Env into global scope under a namespace.

Evaluates a (quoted) expression.

Compiles and executes another file at runtime.

Creates an (anonymous) callable function.

Assigns a symbol to a value for current scope.

Functions

_def(list, env, pos)

Creates a callable function and assigns in in scope.

sig> (def add (a b) (+ a b))
<lambda>(a b -> ...)
sig> (add 1 2)
3

This is syntatic sugar for:

sig> (let add (lambda (a b) (+ a b)))
<lambda>(a b -> ...)

_do(expressions, env, _)

Evaluates all expression in a nested scope and then returns the value of the last expression.

sig> (do (let x 10)
         (print 10))
10
#ok
sig> (print x)
[ReferenceError] x is undefined at nofile:2:8

_if(list, env, pos)

An execution branch based a on the condition.

If truthy, then gets evaluated. If falsy, otherwise gets evaluated. If otherwise is not passed, and condition evaluated to a falsy value, () gets returned.

sig> (if (== 2 (+ 1 1)) (print "math works") (print "universe is broken"))
math works
#ok

sig> (if (== 3 (+ 1 1)) (print "universe still broken"))
()

_import(args, env, pos)

Similar to include/3, but where include/3 exposes and mutates global scope, import/3 executes the file in an isolated container and imports the resulting Signo.Env into global scope under a namespace.

  sig> (import "math.sg" as math)
  sig> (math:fact 5)
  120

If unspecified, the namespace is derived from the given path.

  sig> (import "math.sg")
  sig> math:pi
  3.14159

eval(list, env, _)

Evaluates a (quoted) expression.

sig> (eval '(print 10))
10
#ok

include(list, env, pos)

Compiles and executes another file at runtime.

# example.sg
(print "hello from example.sg!")

sig> (include "example.sg")
hello from example.sg!
#ok

lambda(list, env, pos)

Creates an (anonymous) callable function.

sig> (lambda (a b) (+ a b))
<lambda>(a b -> ...)
sig> ((lambda (a b) (+ a b)) 1 2)
3

If the function takes only a single argument, the parentheses around the argument list can be omitted:

sig> (lambda n (* 2 n))
<lambda>(n -> ...)

let(list, env, pos)

Assigns a symbol to a value for current scope.

sig> (let x 10)
10
sig> (* 2 x)
20