unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Chris Marusich <cmmarusich@gmail.com>
To: Mark H Weaver <mhw@netris.org>
Cc: guile-user@gnu.org
Subject: Re: Multiple values passed as single argument to procedure
Date: Mon, 12 Jun 2017 01:19:48 -0700	[thread overview]
Message-ID: <87mv9dy5wb.fsf@gmail.com> (raw)
In-Reply-To: <87a85d3k9n.fsf@netris.org> (Mark H. Weaver's message of "Mon, 12 Jun 2017 00:25:08 -0400")

[-- Attachment #1: Type: text/plain, Size: 3222 bytes --]

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
argument:

> 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
>this:
>
>   (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
manual.

> 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.

-- 
Chris

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

  reply	other threads:[~2017-06-12  8:19 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-11  7:56 Multiple values passed as single argument to procedure Chris Marusich
2017-06-11  8:28 ` David Kastrup
2017-06-11 20:36 ` Mark H Weaver
2017-06-11 21:31   ` Mark H Weaver
2017-06-12  0:19   ` Chris Marusich
2017-06-12  4:25     ` Mark H Weaver
2017-06-12  8:19       ` Chris Marusich [this message]
2017-06-12  8:55         ` Neil Jerram
2017-06-12  9:48           ` Neil Jerram
2017-06-12  9:39         ` David Kastrup
2017-06-12 11:31           ` Mark H Weaver
2017-06-12 14:24             ` David Kastrup
2017-06-13  2:26               ` Mark H Weaver
2017-06-13  3:09                 ` Mark H Weaver
2017-06-13  3:45                 ` Mark H Weaver
2017-06-13 11:17                 ` dsmich
2017-06-26 11:25                   ` Alex Vong
  -- strict thread matches above, loose matches on Subject: below --
2017-09-01 19:39 Chris Marusich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mv9dy5wb.fsf@gmail.com \
    --to=cmmarusich@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=mhw@netris.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).