Signo.SpecialForms (Signo v0.0.2)
View SourceMacro 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
.
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
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 -> ...)
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
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"))
()
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
Evaluates a (quoted) expression.
sig> (eval '(print 10))
10
#ok
Compiles and executes another file at runtime.
# example.sg
(print "hello from example.sg!")
sig> (include "example.sg")
hello from example.sg!
#ok
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 -> ...)
Assigns a symbol to a value for current scope.
sig> (let x 10)
10
sig> (* 2 x)
20