This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: values (Re: R5RS)
Jim Blandy <jimb@red-bean.com> writes:
> > Could you please explain how exactly the implementation given
> > above would break?
>
> Well:
> And (call-with-values (lambda ()
> (call-with-current-continuation
> (lambda (k) (k 2 3 4))))
> list)
> is (2 3 4), not an error.
Ok, thanks for the explanation :)
[great explanation snipped]
Thanks for this very nice summary :]
> What I'd like is a way to call a function with only as many arguments
> as it expects. That is, I've got five arguments I could pass, but if
> the function only takes three, that's cool, just pass the first three.
> Then, I could apply this to `values', and return only as many values
> as the caller expects. So I could have a division function which
> returns the remainder too, but only if the caller was prepared for two
> return values.
Hmm.
I don't know wether i'd like that. The idea sounds nice, the way
you want to use it sounds nice too, but ... dunno, it passes a
hidden state which sounds ugly. It also breaks referential
transparency, in a way.
Yes, i consider perls want_array pretty ugly, too.
(btw:
(define (div n1 n2 . r)
(if (null? r)
(quotient n1 n2)
(values (quotient n1 n2)
(remainder n1 n2))))
this actually does what you want, without behind-the-scenes-magic, you
just have to pass another argument. I guess it depends on your
personal tastes which version is nicer.)
-- forcer
--
((email . "forcer@mindless.com") (www . "http://forcix.cx/")
(irc . "forcer@#StarWars (IRCnet)") (gpg . "/other/forcer.gpg"))