Racket中多个值和普通元组之间的区别?

Ale*_*lex 5 scheme tuples multiple-value cons racket

valueslistcons在Racket或Scheme 之间有什么区别?什么时候使用一个比另一个好?例如,如果quotient/remainder返回(cons _ _)而不是(values _ _)

soe*_*ard 7

早在2002年,乔治·卡斯韦尔就在comp.lang.scheme中提出了这个问题.随后的线程很长,但有很多见解.讨论表明意见分歧.

https://groups.google.com/d/msg/comp.lang.scheme/ruhDvI9utVc/786ztruIUNYJ

我的回答是:

>    What are the motivations behind Scheme's multiple return values feature?
> Is it meant to reflect the difference in intent, or is there a
> runtime-practical reason?

I imagine the reason being this.

Let's say that need f is called by g. g needs several values from f.
Without multiple value return, f packs the values in a list (or vector),
which is passed to g. g then immediately unpacks the list.

With multple values, the values are just pushed on the stack. Thus no
packing and unpacking is done.

Whether this should be called an optimization hack or not, is up to you.

--
Jens Axel Søgaard

We don't need no side-effecting         We don't need no allocation
We don't need no flow control           We don't need no special-nodes
No global variables for execution       No dark bit-flipping for debugging
Hey! did you leave the args alone?      Hey! did you leave those bits alone?
(Chorus)                  -- "Another Glitch in the Call", a la Pink Floyd
Run Code Online (Sandbox Code Playgroud)