unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: "Chris K. Jester-Young" <cky944@gmail.com>
To: guile-devel@gnu.org
Subject: Re: when and unless
Date: Wed, 7 Dec 2011 10:58:34 -0500	[thread overview]
Message-ID: <20111207155834.GA15815@yarrow.destinee.acro.gen.nz> (raw)
In-Reply-To: <87liqoivle.fsf@fencepost.gnu.org>

On Wed, Dec 07, 2011 at 10:23:25AM +0100, David Kastrup wrote:
> Lilypond is not Scheme but has a more complex syntax.  You can use
> Scheme in a lot of places with different implications on the grammar
> depending on the type of the expression.  It would not be feasible to
> create a separate Scheme calling operator for every possible type of
> expression.  And "called just for action" is one such type.

In that case, to be proper, you have to do what the REPL does, which is
to wrap the Scheme expression within a call-with-values wherever you
process the calling operator. Remember that the continuation can be a
case-lambda:

    (call-with-values
     (lambda () (values))
     (case-lambda
      (() "No return values")
      ((x) (format #f "Single value: ~a" x))
      (x (format #f "Multiple values: ~a" x))))

(Guile 2.0 has built-in (VM-level) support for case-lambda, which makes
this super awesome.)

> Well, you'd need to have
> 
> (call-with-values (lambda () *unspecified*) (lambda x (length x))) => 0
[...]
> That means that one _only_ needs to consider the implications on
> call-with-values continuations.

Correct. However, how would you detect whether you're in a context where
call-with-values is being used? Here are some things that won't work:

1. You can't walk the stack. Your void expression would be in tail
   position (it would transfer to the continuation directly, not return
   to call-with-values---try (call-with-values (lambda () (throw 'foo))
   (lambda () 42)) and see what the backtrace looks like).

2. Guile's continuations don't provide meaningful arities: (call/cc
   (lambda (k) (procedure-minimum-arity k))) always says it takes zero
   or more arguments. (Same deal applies with Racket, so I presume it's
   not "just a Guile quirk".)

> And it is not like Guile has a problem distinguishing content and
> package itself (at least Guile 1.8):
> 
> guile> (write *unspecified*)
> #<unspecified>guile> (write (values))
> #<values ()>guile> 

In Guile 2.0, multiple values is not a first-class object. Instead, it
works like Common Lisp: in any context where a single value is needed,
and multiple values are supplied, then only the first value is used,
and the rest are thrown away.

    scheme@(guile-user)> (+ (values 1 2 3) (values 4 5 6))
    $1 = 5
    scheme@(guile-user)> (+ (values 1 2 3) (values))
    ERROR: In procedure values:
    ERROR: Throw to key `vm-error' with args `(vm-run "Zero values returned to single-valued continuation" ())'.

> So I still don't quite see the problem that would arise from making
> (eq? *unspecified* (values)) => #t

Simply that (values) is not valid to pass to eq?, since eq? is a normal
function, that thus expects one value for every argument. That this may
possibly work for Guile 1.8 is simply an accident of its implementation
of multiple values.

Cheers,
Chris.



  reply	other threads:[~2011-12-07 15:58 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-30 10:44 when and unless Andy Wingo
2011-06-30 21:46 ` Ludovic Courtès
2011-07-01  7:50   ` Andy Wingo
2011-07-01 12:47     ` Ludovic Courtès
2011-12-05 20:23 ` Andy Wingo
2011-12-06  7:48   ` Marijn
2011-12-06  8:29     ` Alex Shinn
2011-12-06 11:17       ` David Kastrup
2011-12-06 16:25         ` Andy Wingo
2011-12-06 16:42           ` David Kastrup
2011-12-06 17:35             ` Andy Wingo
2011-12-06 22:08               ` David Kastrup
2011-12-06 23:05                 ` Chris K. Jester-Young
2011-12-07  9:23                   ` David Kastrup
2011-12-07 15:58                     ` Chris K. Jester-Young [this message]
2011-12-08  8:42                       ` David Kastrup
2011-12-08 15:34                         ` Chris K. Jester-Young
2011-12-08 16:10                           ` David Kastrup
2011-12-08 18:10                         ` Ian Price
2011-12-07 16:10         ` Chris K. Jester-Young
2011-12-06 19:05     ` Chris K. Jester-Young
2011-12-06 19:33       ` Andy Wingo
2011-12-06 14:39   ` Ludovic Courtès
2011-12-07 14:19     ` Ludovic Courtès
2011-12-07 14:27       ` David Kastrup
2012-01-07  0:16       ` Andy Wingo
2012-01-07 22:36         ` Ludovic Courtès
2012-01-20 20:19           ` Andy Wingo

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=20111207155834.GA15815@yarrow.destinee.acro.gen.nz \
    --to=cky944@gmail.com \
    --cc=guile-devel@gnu.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).