[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: Sun, 11 Jun 2017 17:19:47 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)

Hi Mark,

Thank you for the detailed response!  I learn something new every day.

Mark H Weaver <address@hidden> writes:

> Use 'call-with-values', 'let-values', or 'receive' to call a procedure
> that returns multiple values (or no values).
> If you do not use one of the above forms (or a macro that expands to one
> of them) to call a procedure that returns multiple values, then Guile
> will discard all but the first result.  Note that this is a
> Guile-specific extension.  Other Scheme implementations may behave
> differently (e.g. report an error) if multiple values (or no values) are
> returned to a procedure call that was not done using one of the forms
> listed above.

I see.  So, this behavior is implementation-specific for Guile scheme.

Is this behavior documented in the Guile reference manual?  I looked,
but I couldn't find information about it.  So, it is not clear to me if
one should rely on this behavior, or if it is likely to change in the
future.  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.

Here's another question.  I've also noticed that when the 'list'
procedure is composed with a procedure f that returns multiple values,
the list that gets returned when calling the composition differs from
the list that results when "manually" invoking the same composition.  An
example will clarify what I mean:

--8<---------------cut here---------------start------------->8---
$ guile
GNU Guile 2.2.2
Copyright (C) 1995-2017 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> (define (f . _) (values 1 2))
scheme@(guile-user)> (f)
$1 = 1
$2 = 2
scheme@(guile-user)> (define g (compose list f))
scheme@(guile-user)> (g)
$3 = (1 2)
scheme@(guile-user)> (list (f))
$4 = (1)
--8<---------------cut here---------------end--------------->8---

In the above, I was surprised to find that $3 was not the same as $4.
To put this another way, I was surprised to find that the composition
via 'compose' (which returned $3) did not behave the same as the
'manual' composition (which returned $4).  What's going on here?  I
couldn't find the answer by looking at the documentation for the compose
((guile) Higher-Order Functions) or list ((guile) List Constructors)
procedures in the Guile manual.

Thank you for taking the time to help me understand this better.


Attachment: signature.asc
Description: PGP signature

reply via email to

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