guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: or values bug?


From: Ludovic Courtès
Subject: Re: or values bug?
Date: Mon, 05 Dec 2011 18:40:18 +0100
User-agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.90 (gnu/linux)

Hi Cédric,

address@hidden 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 via email to

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