This library provides some useful macros using Sagittarius specific functions.
Defines name to be a macro whose transformer is procedure. The second form is a shorthand notation of the following form:
(define-macro _name_ (lambda _formals_ _body_ ...))
Given a list of values restargs, binds variables according to var-spec, then evaluates body.
Var-spec can be either a symbol, or a list of two elements and its car is a symbol. The symbol is the bound variable name. The values in _restargs_are bound to the symbol in order. If there are not as many values in restargs as var-spec, the rest of symbols are bound to the default values, determined as follows:
If var-spec is just a symbol, the default value is undefined.
If var-spec is a list, the default value is the result of evaluation of the second element of the list.
In the latter case the second element is only evaluated when there are not enough arguments. The binding proceeds in the order of var-spec, so the second element may refer to the bindings of previous var-spec.
In the second form, restvar must be a symbol and bound to the list of values whatever left from restargs after binding to var-spec.
It is not an error if restarg has more values than var-specs. The extra values are simply ignored in the first form.
This is a short version of let-optionals*
where you have only one
optional argument. Given the optional argument list restargs, this macro
returns the value of optional argument if one is given, or the result of
default otherwise.
If latter form is used, test must be procedure which takes one argument
and it will be called to test the given argument. If the test failed, it raises
&error
condition.
Default is not evaluated unless restargs is an empty list.
This macro is for keyword arguments. Var-spec can be one of the following forms:
(_symbol_ _expr_)
If the restrag contains keyword which has the same name as symbol, binds symbol to the corresponding value. If such a keyword doesn't appear in restarg, binds symbol to the result of expr.
(_symbol_ _keyword_ _expr_)
If the restarg contains keyword keyword, binds symbol to the corresponding value. If such a keyword doesn't appear in restarg, binds symbol to the result of expr.
The default value expr is only evaluated when the keyword is not given to the restarg.
If you use the first form, let-keyword
raises &error
condition
when restarg contains a keyword argument that is not listed in
var-specs. When you want to allow keyword arguments other than listed in
var-specs, use the second form.
In the second form, restvar must be either a symbol or #f. If it is a symbol, it is bound to a list of keyword arguments that are not processed by var-specs. If it is #f, such keyword arguments are just ignored.
(define (proc x . options)
(let-keywords options ((a 'a)
(b :beta 'b)
(c 'c)
. rest)
(list x a b c rest)))
(proc 0)
(0 a b c ())
(proc 0 :a 1)
(0 1 b c ())
(proc 0 :beta 1)
(0 a 1 c ())
(proc 0 :beta 1 :c 3 :unknown 4)
(0 a 1 3 (unknown 4))
Like let-keywords
, but the binding is done in the order of
var-specs. So each expr can refer to the variables bound by
preceding var-specs.
These let-keywords and let-keywords* are originally from Gauche.
The define-with-key
is synonym of define
.
See more detail Variable definitions.
Evaluate exp0, exp1, ..., then returns the result(s) of exp0.
A convenient macro when you have only one variable. Expanded as follows:
(let ((_var_ _expr_)) _body_ ...)
A convenient macro when you have only one variable and is the returning value. Expanded as follows:
(let ((_var_ _expr_)) _body_ ... _var_)
Imported from Common List. These are equivalent to the following forms, respectively.
(dotimes (variable limit result) body ...)
=>
(do ((tlimit limit)
(variable 0 (+ variable 1)))
((>= variable tlimit) result)
body ...)
(dolist (variable lexpr result) body ...)
=>
(begin
(for-each (lambda (variable) body ...) lexpr)
(let ((variable '())) result))
Conses item and the value of place. The place must be
either a variable or a form (proc arg ...), as the second argument of
set!
. The result will be the same as set!
.
Retrieves the value of place, sets its cde back to place.
Check the given val satisfies pred. If the pred returns
#f then &assertion
is raised.
The proc should be the procedure name which uses this macro and is for debugging purpose.
library must be a library name. ex. (srfi :1 lists)
exprs must be expressions.
Evaluate given expressions one by one in the specified library and returns the last result of the expressions.
This should not be used casually however you want to use some procedures or variables which are not exported, such as a procedure written in C but not exported or non exported record accessor. For thoese purpose, this might be a quick solution.
Execute body then execute cleanups and returns the result(s) of body.
It is not guaranteed to invoke the cleanups only once if a continuation is captured in body and call it.
Short form of syntax->datum
.
The macro is similar with with-syntax
, the only difference is
that this macro can refer previous pattern of p as if let*
can.
This can reduce nest level when users need to write multiple
with-syntax
to refer bound syntax object.
The alias of lambda
.
Shortened notation of (lambda (c) body ...)
. Where c
can be any character of lower case of ASCII alphabet.
(map (^z (* z z)) '(1 2 3 4 5))
(1 4 9 16 25)
Shortened notation of (lambda c body ...)
. Where c
can be any character of lower case of ASCII alphabet.
(map (^z* z*) '(1 2 3 4 5))
((1) (2) (3) (4) (5))