unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: guile-user@gnu.org
Subject: Re: or values bug?
Date: Mon, 05 Dec 2011 18:40:18 +0100	[thread overview]
Message-ID: <87obvmhq7x.fsf@gnu.org> (raw)
In-Reply-To: 20111205143331.GA2681@ccellier.rd.securactive.lan

Hi Cédric,

rixed@happyleptic.org skribis:

> Is it normal that this:
>
> (or (values 'a 'b) 'c)
>
> returns two values ('a and 'b)

This one gets optimized by peval:

  scheme@(guile-user)> ,optimize (or (values 1 2) 'b)
  $6 = (values 1 2)

That the second value isn’t truncated is a bug (see below.)

> while this:
>
> (or (values 'a (lambda (port) #f)) 'c)
>
> returns only one ('a)?

This one doesn’t:

  scheme@(guile-user)> ,optimize (or (values 1 (lambda () #t)) 'b)
  $5 = (begin
    (letrec*
      ()
      (let ((#{t 1263}# (values 1 (lambda () #t))))
        (if #{t 1263}# #{t 1263}# 'b))))

The ‘let’, which leads to the second value being ignored, comes from the
definition of ‘or’:

  (define-syntax or
    (syntax-rules ()
      ((_) #f)
      ((_ x) x)
      ((_ x y ...) (let ((t x)) (if t t (or y ...))))))

It’s normal that the second value is ignored because ‘or’ expects
expressions returning one value.

In theory, peval should really optimize the first form to 1, instead of
multiple-values, but I think it loses information about the context
somewhere.

Namely, when partial-evaluating <let> forms, I think it should:

   (let* ((vars (map (compose truncate lookup-var) gensyms))
          ...)
     ...)

where ‘truncate’ discards all values but the first of a <let-values>
form.

Andy?

Thanks,
Ludo’.




  reply	other threads:[~2011-12-05 17:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-05 14:33 or values bug? rixed
2011-12-05 17:40 ` Ludovic Courtès [this message]
2011-12-05 20:57   ` Andy Wingo
2011-12-05 21:00     ` Andy Wingo
2011-12-06 17:57       ` Ludovic Courtès
2011-12-06 18:23         ` Andy Wingo
2011-12-06  6:51 ` rixed

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=87obvmhq7x.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=guile-user@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).