[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: call-with-values and primitives
From: |
Andy Wingo |
Subject: |
Re: call-with-values and primitives |
Date: |
Fri, 11 Jan 2013 17:56:27 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) |
On Fri 11 Jan 2013 15:23, address@hidden writes:
> (call-with-values * -)
> ⇒ -1
So it's like:
(call-with-values producer consumer)
The producer is called with no arguments, then the results of that call
are passed to the consumer.
So first `*' is called with no arguments, like this:
(*)
Calling `*' always returns just one value, so in this case it's
equivalent to binding a single value, so the original expression is
completely equivalent to:
(let ((tmp (*)))
(- tmp))
Reducing this further:
=> (let ((tmp 1))
(- tmp))
=> (- 1)
=> -1
See the R5RS for more, including the definition of (*) and (+).
> (call-with-values + +)
> 0
(let ((tmp (+)))
(+ tmp))
> (call-with-values + -)
> 0
(let ((tmp (+)))
(- tmp))
> (call-with-values - -)
(let ((tmp (-)))
(- tmp))
> ERROR: Wrong number of arguments to -
> ABORT: (wrong-number-of-args)
(-) has no sensible answer.
Happy hacking,
Andy
--
http://wingolog.org/