unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: David Kastrup <dak@gnu.org>
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 16:24:25 +0200	[thread overview]
Message-ID: <87h8zl7086.fsf@fencepost.gnu.org> (raw)
In-Reply-To: <87wp8h1lyh.fsf@netris.org> (Mark H. Weaver's message of "Mon, 12 Jun 2017 07:31:34 -0400")

Mark H Weaver <mhw@netris.org> writes:

> I'm sorry David, but _everything_ that you wrote below is incorrect.

Well, let me try again.  It's not all that easy to understand.

> David Kastrup <dak@gnu.org> writes:
>
>> Chris Marusich <cmmarusich@gmail.com> writes:
>>
>>> 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.
>>
>> It is,
>
> No it isn't.
>
>> but list does not take multiple values
>
> Yes it does.  'list' accepts an arbitrary number of values
> (arguments).

In my book, multiple values/arguments are different things but I admit
that this is a quagmire to me and strictly speaking what I call
"multiple values" (namely the unmitigated return value from calling
values) never occurs in the position of an argument (at least when not
looking at the C API and/or Guile 1.x).

dak@lola:/usr/local/tmp/lilypond$ guile-2.0 
GNU Guile 2.0.13
Copyright (C) 1995-2016 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)> (list (values 1 2 3))
$1 = (1)
scheme@(guile-user)> 

>> and thus discards additional values returned by f.
>
> 'list' does not discard anything.  The additional values are discarded
> before 'list' is called.

Ok.  Because a function call cannot take multiple values.  It does take
multiple _arguments_.

A function call can appear to return multiple values by using call/cc
(which is essentially what (values ...) does) and the construct
call-with-values can salvage them as long as they are only passed
through tail calls (or rather tail returns):

(call-with-values
  (lambda () (call/cc (lambda (c) (c 1 2 3))))
  list) => (1 2 3)

Basically call-with-values is a mechanism that lets the continuation
delivered by call/cc be a function accepting multiple arguments.  An
ordinary function call doesn't.

> I will try to clarify all of this in another message.

Well, I probably messed up things a whole lot more now.  But at least it
should be an excellent opportunity for correcting the half-truths and
misconceptions that Scheme's procedure/continuation model might inspire
in people (like me) without a firm grasp of its concepts.

-- 
David Kastrup



  reply	other threads:[~2017-06-12 14:24 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
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 [this message]
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=87h8zl7086.fsf@fencepost.gnu.org \
    --to=dak@gnu.org \
    --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).