何时在Scheme中使用(values ...) (define-values ...)
我已阅读有关返回和使用多个值的函数(例如值和定义值)的文档。我理解他们的所作所为。我不清楚你什么时候想使用这样的东西。
什么时候构建单个值列表并使用该单个值列表会很糟糕/不可能?
I have read documentation for functions such as values and define-values that return and consume multiple values. I understand what they do. It's not clear to me when you would want to use such a thing.
When would it be bad/impossible to build a single list of values and consume that single list of values instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
define-values 很方便,可以让您直接将变量绑定到表达式的结果。它可以节省您的输入时间,因为您不必显式解压列表。我认为在某些情况下构建单个值列表是不好的或不可能的。事实上,这比定义值更可移植。
define-values is a convenience that lets you directly bind variables to the results of a expression. It saves you some typing as you don't have to explicitly unpack a list. I don't think there are situations where it is bad or impossible to build a single list of values. In fact, that will be more portable than define-values.
这里是我关于该主题的原始帖子;复制如下。
在 comp.lang.scheme 的此主题中讨论了返回多个值的方法。 R6RS中似乎有3个解决方案:
Per Aziz和Aaron的观点;您应该使用向读者传达最多信息的方法。
Here is my original post on the topic; it is copied below.
In this thread in comp.lang.scheme the means to return multiple values are discussed. There are seemingly 3 solutions in R6RS:
Per Aziz and Aaron’s point; you should use the approach that communicates the most information to the reader.