什么是 define* 在 guile 或 scheme 中?
What is define* in guile or scheme?
我搜也找不到,define*
是什么鬼?例如,您可以在此答案
中找到它
您可以在此处的文档中找到它:创建高级参数处理过程。
6.10.4.1 lambda* 并定义*.
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.
发件人:
在 Scheme 标准中 define*
没有定义,但命名约定规定任何以星号结尾的符号将提供与没有星号的符号非常相似的操作。
在标准中,您有 let
绑定变量,let*
也绑定变量,但一次绑定一个变量,以便创建的变量可用于下一个绑定。
SRFI 是扩展 Scheme 的标准方式。实现实现了许多本地 SRFI,而那些在许多情况下不能通过下载参考实现来工作的 SRFI。 SRFI-89 implements define*
and lambda*
and they provide Scheme with optional positional arguments. Looking at Guile's SRFI support SRFI-89 未列出,但 SRFI-89 本身提到 Guile 有它们,只是它使用符号 #:key
而不是 #!key
,因此不可移植。
R5RS 实现通常具有比标准更多的全局绑定。如果它不是 SRFI 的一部分,您将被使用此类扩展程序锁定。
我搜也找不到,define*
是什么鬼?例如,您可以在此答案
您可以在此处的文档中找到它:创建高级参数处理过程。
6.10.4.1 lambda* 并定义*.
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.
发件人:
在 Scheme 标准中 define*
没有定义,但命名约定规定任何以星号结尾的符号将提供与没有星号的符号非常相似的操作。
在标准中,您有 let
绑定变量,let*
也绑定变量,但一次绑定一个变量,以便创建的变量可用于下一个绑定。
SRFI 是扩展 Scheme 的标准方式。实现实现了许多本地 SRFI,而那些在许多情况下不能通过下载参考实现来工作的 SRFI。 SRFI-89 implements define*
and lambda*
and they provide Scheme with optional positional arguments. Looking at Guile's SRFI support SRFI-89 未列出,但 SRFI-89 本身提到 Guile 有它们,只是它使用符号 #:key
而不是 #!key
,因此不可移植。
R5RS 实现通常具有比标准更多的全局绑定。如果它不是 SRFI 的一部分,您将被使用此类扩展程序锁定。