From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.lisp.guile.user Subject: Re: or values bug? Date: Mon, 05 Dec 2011 18:40:18 +0100 Message-ID: <87obvmhq7x.fsf@gnu.org> References: <20111205143331.GA2681@ccellier.rd.securactive.lan> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1323106848 12408 80.91.229.12 (5 Dec 2011 17:40:48 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 5 Dec 2011 17:40:48 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Dec 05 18:40:45 2011 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RXcWy-0001H1-PL for guile-user@m.gmane.org; Mon, 05 Dec 2011 18:40:44 +0100 Original-Received: from localhost ([::1]:55640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXcWy-0001pb-Df for guile-user@m.gmane.org; Mon, 05 Dec 2011 12:40:44 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:38094) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXcWu-0001pS-SW for guile-user@gnu.org; Mon, 05 Dec 2011 12:40:41 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RXcWp-00017v-SX for guile-user@gnu.org; Mon, 05 Dec 2011 12:40:40 -0500 Original-Received: from lo.gmane.org ([80.91.229.12]:34932) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXcWp-00017a-Kd for guile-user@gnu.org; Mon, 05 Dec 2011 12:40:35 -0500 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1RXcWn-0001CS-JH for guile-user@gnu.org; Mon, 05 Dec 2011 18:40:33 +0100 Original-Received: from 193.50.110.208 ([193.50.110.208]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 05 Dec 2011 18:40:33 +0100 Original-Received: from ludo by 193.50.110.208 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 05 Dec 2011 18:40:33 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 61 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 193.50.110.208 X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 15 Frimaire an 220 de la =?iso-8859-1?Q?R=E9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu User-Agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.90 (gnu/linux) Cancel-Lock: sha1:QJbaiGlrG2P9KR8lbcvjnPGhb6I= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 80.91.229.12 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:9029 Archived-At: 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 forms, I think it should: (let* ((vars (map (compose truncate lookup-var) gensyms)) ...) ...) where ‘truncate’ discards all values but the first of a form. Andy? Thanks, Ludo’.