From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.user Subject: Re: Threading / Pipe Macro Date: Sun, 07 Jul 2019 18:24:32 -0400 Message-ID: <87v9wd7a9w.fsf@netris.org> References: <5f08685b-be5b-e584-af54-9f4244039b1a@gmail.com> <20190707193259.434e1a816c551ece292f45da@gmail.com> <871rz1fxr7.fsf@netris.org> <20190707211613.4a8a637da93e592b4f737a7f@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="18942"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) Cc: guile-user@gnu.org To: Chris Vine Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Jul 08 00:27:16 2019 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hkFcm-0004lS-Nn for guile-user@m.gmane.org; Mon, 08 Jul 2019 00:27:12 +0200 Original-Received: from localhost ([::1]:37262 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkFcl-0005Zm-OA for guile-user@m.gmane.org; Sun, 07 Jul 2019 18:27:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55098) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkFcW-0005Zg-N7 for guile-user@gnu.org; Sun, 07 Jul 2019 18:26:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkFcV-0006Sv-Lj for guile-user@gnu.org; Sun, 07 Jul 2019 18:26:56 -0400 Original-Received: from world.peace.net ([64.112.178.59]:53120) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hkFcV-0006GF-I2 for guile-user@gnu.org; Sun, 07 Jul 2019 18:26:55 -0400 Original-Received: from mhw by world.peace.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hkFcJ-00069S-OB; Sun, 07 Jul 2019 18:26:43 -0400 In-Reply-To: <20190707211613.4a8a637da93e592b4f737a7f@gmail.com> (Chris Vine's message of "Sun, 7 Jul 2019 21:16:13 +0100") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.112.178.59 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.org gmane.lisp.guile.user:15609 Archived-At: Hi Chris, Here's a complete, unedited transcript with Guile 2.2.6: --8<---------------cut here---------------start------------->8--- mhw@jojen ~$ guile GNU Guile 2.2.6 Copyright (C) 1995-2019 Free Software Foundation, Inc. Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'. This program is free software, and you are welcome to redistribute it under certain conditions; type `,show c' for details. Enter `,help' for help. scheme@(guile-user)> (define-syntax -> (lambda (x) (syntax-case x () [(k exp0 . exps) (let* ([reversed (reverse (cons (syntax->datum #'exp0) (syntax->datum #'exps)))] [out (let loop ([first (car reversed)] [rest (cdr reversed)]) (if (null? rest) first (let ([func (car first)] [args (cdr first)]) (append `(,func ,@args) (list (loop (car rest) (cdr rest)))))))]) (datum->syntax #'k out))]))) scheme@(guile-user)> (define t 'global-t) scheme@(guile-user)> (define-syntax-rule (foo x) (-> x (format #t "[t=~A] ~A\n" t))) scheme@(guile-user)> (let ((t 'inner-t)) (foo t)) [t=global-t] global-t $1 = #t scheme@(guile-user)> (define-syntax -> (syntax-rules () ((-> exp) exp) ((-> exp ... (op args ...)) (op args ... (-> exp ...))))) scheme@(guile-user)> (let ((t 'inner-t)) (foo t)) [t=global-t] inner-t $2 = #t scheme@(guile-user)> --8<---------------cut here---------------end--------------->8--- Chris Vine writes: > How strange. Both your and my macro gives 'global-t' when I test them, Can you show me a complete, unedited transcript that demonstrates what you're seeing? > which is the result I would expect. (Maybe I am missing something here, > but a result of 'inner-t' would seem to me to imply unhygiene.) (foo EXPR) is supposed to print "[t=global-t] VAL", where VAL is the result of evaluating EXPR. With this in mind, (let ((t 'inner-t)) (foo t)) The argument to 'foo' here should refer to the lexical binding of 't', i.e. the variable with value 'inner-t'. I'm curious what would make you expect otherwise. On the other hand, the reference to 't' in the template of the 'foo' macro should refer to the toplevel variable 't', because the template does not appear within the 'let'. This is a good example of why syntax objects are needed, to distinguish between these two references to distinct variables named 't'. When you convert the references to datums, the distinctions are lost. Regards, Mark