问题
I can't find it by searching, what is define*
in guile? You can find it for instance in this answer https://stackoverflow.com/a/24101699/387194
回答1:
You will find it in the documentation here: Creating advanced argument handling procedures.
6.10.4.1 lambda* and define*.
lambda* is like lambda, except with some extensions to allow optional and keyword arguments.
library syntax: lambda* ([var…]
[#:optional vardef…]
[#:key vardef… [#:allow-other-keys]]
[#:rest var | . var])
body1 body2 …
Optional and keyword arguments can also have default values to take when not present in a call, by giving a two-element list of variable name and expression. For example in
(define* (frob foo #:optional (bar 42) #:key (baz 73))
(list foo bar baz))
foo is a fixed argument, bar is an optional argument with default value 42, and baz is a keyword argument with default value 73. Default value expressions are not evaluated unless they are needed, and until the procedure is called.
Normally it’s an error if a call has keywords other than those specified by #:key, but adding #:allow-other-keys to the definition (after the keyword argument declarations) will ignore unknown keywords.
From:
https://www.gnu.org/software/guile/docs/master/guile.html/lambda_002a-and-define_002a.html#lambda_002a-and-define_002a
回答2:
In the Scheme standard define*
is not defined but the naming convention dictates that any symbol that ends in an asterix will provide very similar operation as the symbol without.
In the standard you have let
that binds variables and let*
which also binds variables but one at a time so that the created variables are available to the next bindings.
There are SRFIs that are a standard way of extending Scheme. Implementations implement many of the SRFIs native and those who don't can in many cases work with just downloading the reference implementation. SRFI-89 implements define*
and lambda*
and they provide Scheme with optional positional arguments. Looking at Guile's SRFI support SRFI-89 is not listed but the SRFI-89 itself mentions that Guile has them except it uses the notation #:key
instead of #!key
, thus not portable.
It's common for R5RS implementations to have more global bindings than the standard. If it's not a part of a SRFI you will be locked in by using such extensions.
来源:https://stackoverflow.com/questions/38103650/what-is-define-in-guile-or-scheme