From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.lisp.guile.devel Subject: Re: summary: lilypond, lambda, and local-eval Date: Fri, 16 Dec 2011 10:59:44 +0100 Organization: Organization?!? Message-ID: <871us44z1r.fsf@fencepost.gnu.org> References: <87r506uodd.fsf@pobox.com> <87pqfpj7e3.fsf@netris.org> <87liqcamrf.fsf@pobox.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1324029616 25656 80.91.229.12 (16 Dec 2011 10:00:16 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 16 Dec 2011 10:00:16 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Dec 16 11:00:12 2011 Return-path: Envelope-to: guile-devel@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 1RbUaJ-0005U2-VS for guile-devel@m.gmane.org; Fri, 16 Dec 2011 11:00:12 +0100 Original-Received: from localhost ([::1]:58195 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RbUaJ-0001c6-F5 for guile-devel@m.gmane.org; Fri, 16 Dec 2011 05:00:11 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:36502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RbUaG-0001Zn-AX for guile-devel@gnu.org; Fri, 16 Dec 2011 05:00:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RbUaB-0007Ws-FB for guile-devel@gnu.org; Fri, 16 Dec 2011 05:00:08 -0500 Original-Received: from lo.gmane.org ([80.91.229.12]:43488) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RbUaB-0007WX-2H for guile-devel@gnu.org; Fri, 16 Dec 2011 05:00:03 -0500 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1RbUaA-0005Qg-50 for guile-devel@gnu.org; Fri, 16 Dec 2011 11:00:02 +0100 Original-Received: from p508edf03.dip.t-dialin.net ([80.142.223.3]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 16 Dec 2011 11:00:02 +0100 Original-Received: from dak by p508edf03.dip.t-dialin.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 16 Dec 2011 11:00:02 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 116 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: p508edf03.dip.t-dialin.net X-Face: 2FEFf>]>q>2iw=B6, xrUubRI>pR&Ml9=ao@P@i)L:\urd*t9M~y1^:+Y]'C0~{mAl`oQuAl \!3KEIp?*w`|bL5qr,H)LFO6Q=qx~iH4DN; i"; /yuIsqbLLCh/!U#X[S~(5eZ41to5f%E@'ELIi$t^ Vc\LWP@J5p^rst0+('>Er0=^1{]M9!p?&:\z]|;&=NP3AhB!B_bi^]Pfkw User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) Cancel-Lock: sha1:AqPDudPJgiP0ysta0f1XqROhPEk= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 80.91.229.12 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:13133 Archived-At: Andy Wingo writes: > What are the meanings of these expressions: I found it amusing to see what my definitions using with-current-continuation will produce here. > ;; Toplevel > (local-eval '(define foo 42) (the-environment)) guile> (my-eval '(define foo 42) (my-env)) guile> foo 42 > ;; Lexical, tail context > (local-eval '(define foo 42) (let ((x 100)) (the-environment))) guile> (my-eval '(define foo 42) (let ((x 100)) (my-env))) Backtrace: In standard input: 1: 0* [my-eval (define foo 42) ... 1: 1* (let* ((x 100)) (# (define foo 42))) 1: 2 (begin #) 1: 3 [# ... 1: 4* (define foo 42) standard input:1:11: In procedure memoization in expression (define foo 42): standard input:1:11: In file "standard input", line 0: Bad define placement (define foo 42). ABORT: (syntax-error) guile> > ;; Lexical, tail context -- but with a definition > (local-eval '(begin (define foo 42) foo) (let ((x 100)) (the-environment))) guile> (my-eval '(begin (define foo 42) foo) (let ((x 100)) (my-env))) Backtrace: In standard input: 6: 0* [my-eval (begin (define foo 42) foo) ... 6: 1* (let* ((x 100)) (# (begin # foo))) 6: 2 (begin #) 6: 3 [# ... 6: 4* (begin (define foo 42) foo) 6: 5* (define foo 42) standard input:6:18: In procedure memoization in expression (define foo 42): standard input:6:18: In file "standard input", line 5: Bad define placement (define foo 42). ABORT: (syntax-error) guile> > ;; Lexical, tail context -- but with a definition, and nested reference > (local-eval '(begin (define foo 42) (bar)) > (let ((x 100)) (define (bar) foo) (the-environment))) guile> (my-eval '(begin (define foo 42) (bar)) (let ((x 100)) (define (bar) foo) (my-env))) Backtrace: In standard input: 13: 0* [my-eval (begin (define foo 42) (bar)) ... 13: 1* (let* ((x 100)) (letrec (#) (# #))) In unknown file: ?: 2 (letrec ((bar #)) (# (begin # #))) In standard input: ... 13: 3 [# ... 13: 4* (begin (define foo 42) (bar)) 13: 5* (define foo 42) standard input:13:18: In procedure memoization in expression (define foo 42): standard input:13:18: In file "standard input", line 12: Bad define placement (define foo 42). ABORT: (syntax-error) > ;; Lexical, not a definition context > (local-eval '(define foo 42) (let ((x 100)) not-a-definition (the-environment))) guile> (my-eval '(define foo 42) (let ((x 100)) "hello" (my-env))) Backtrace: In standard input: 12: 0* [my-eval (define foo 42) ... 12: 1* (let* ((x 100)) "hello" (# (define foo 42))) 12: 2 (begin #) 12: 3 [# ... 12: 4* (define foo 42) standard input:12:11: In procedure memoization in expression (define foo 42): standard input:12:11: In file "standard input", line 11: Bad define placement (define foo 42). ABORT: (syntax-error) guile> > What about this one: > > ;; Keeping in mind that `or' expands to (let ((t ...)) (if t t ...)), > ;; hygienically > (local-eval 't '(let ((t 42)) (or #f (the-environment)))) Assuming that the second quote mark is a typo. guile> (my-eval 't (let ((t 42)) (or #f (my-env)))) 42 guile> Now of course, the continuation based approach that just hijacks the expander and jumps in and out of it is not really a measure of how things should work. But it makes clear that (the-environment) is a bit of a chimera: it captures content at a level conceptually relevant for (define), but returns a value and has to be placed accordingly, like in a function call or at the providing side of a binding construct. If those different syntactic aspects prove to be too hard to conciliate, it might help to look at the kind of interface that some other chimeras like call-with-values or call-with-current-continuation have taken. -- David Kastrup