[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiple values passed as single argument to procedure

From: Chris Marusich
Subject: Re: Multiple values passed as single argument to procedure
Date: Mon, 12 Jun 2017 01:19:48 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)

Hi Mark,

Regarding the Guile-specific behavior where passing multiple values as
an argument to a procedure causes only the first value to be used as the

> I would recommend against relying on this behavior, mainly because I
> would consider it a bit sloppy.  However, I also think it's very
> unlikely that we would ever remove this extension, because I don't
> anticipate a compelling reason to remove it, and it would surely break
> existing code.
>> I was hoping to find this behavior documented in either
>> "(guile) Multiple Values" or somewhere in "(guile) About Procedures".
>> Perhaps there's a better location.  In any case, I think it would be
>> helpful if this were documented in the manual.
> Agreed.  "(guile) Multiple Values" is probably the appropriate place.

OK.  I'll submit a patch later this week to update the manual with
information taken from this email thread.  Hopefully that will help
clarify the behavior for others in the future.

Regarding the behavior of composed procedures:

> The problem is that you implemented your 'manual' composition in a way
> that allows only one value to pass between the two procedures.  Remember
> that when a procedure call is made without 'call-with-values' (or some
> macro that uses it), and is not in tail position, then all but the first
> return value is discarded.  That's what's happening in your call to 'f'
> in (list (f)).  The call (f) is neither in tail position nor called
> using 'call-with-values', so only one of its values is kept.

I think I'm missing something here.  In (list (f)), the call to f
certainly looks like it's happening at a position that one might
intuitively call a "tail" position.  So, in this case, what disqualifies
f from being in tail position?  Can you give me an example of a call to
f that would be in tail position, so I can understand the difference?
Sorry if you've already provided such an example; I appreciate your
explanations, and I'm just trying to make sure I fully understand.

> Try this instead:
>   (let-values ((vals (f)))
>     (apply list vals))
> Or, more simply in the case where 'f' takes no arguments:
>   (call-with-values f list)

Am I correct in understanding that in these cases, the two values
returned by the 'f' procedure basically get "converted" into two
separate arguments that get passed to the 'list' procedure, as if I had
invoked (list 1 2)?

> I suppose you are thinking of 'compose' as being implemented like
>   (define (compose f g)
>     (lambda (x)
>       (f (g x))))

Yes, that's what I assumed.  I think I see now why my assumption was
incorrect for the case where g returns multiple values.  I think the
problem here was that I didn't understand how multiple values would be
handled under various situations, even after consulting the Guile

> The core Guile version of 'compose' is defined in ice-9/boot-9.scm.

Thank you!  It's helpful to see the implementation.  I see that it's
similar to one of the examples you gave for implementing 'compose' in a
way that supports procedures of arbitrary arity that return an arbitrary
number of values.


Attachment: signature.asc
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]