狡猾或计划中的define *是什么? [英] What is define* in guile or scheme?

查看:116
本文介绍了狡猾或计划中的define *是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过搜索找到它,guile中的define*是什么?例如,您可以在以下答案中找到它 https://stackoverflow.com/a/24101699/387194

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

推荐答案

您将在以下文档中找到它:创建高级参数处理过程.

You will find it in the documentation here: Creating advanced argument handling procedures.

6.10.4.1 lambda *并定义*.

lambda *类似于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是固定参数,bar是带有默认值的可选参数 值42,而baz是关键字参数,默认值为73.默认 除非需要它们,否则不评估值表达式,直到 该过程被调用.

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.

如果通话中使用的关键字不是这些关键字,通常会出错 由#:key指定,但在定义中添加#:allow-other-keys (在关键字参数声明之后)将忽略unknown 关键字.

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.

发件人:

https://www.gnu.org/software/guile/docs/master/guile.html/lambda_002a-and-define_002a.html#lambda_002a-and-define_002a

这篇关于狡猾或计划中的define *是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆