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 21:09:57 -0400 Message-ID: <87pnml8h7e.fsf@netris.org> References: <5f08685b-be5b-e584-af54-9f4244039b1a@gmail.com> <20190707193259.434e1a816c551ece292f45da@gmail.com> <871rz1fxr7.fsf@netris.org> <20190707211613.4a8a637da93e592b4f737a7f@gmail.com> <20190707232513.5d1cff70af7f8e97380749df@gmail.com> <875zoda2e4.fsf@netris.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="104909"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (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 03:10:56 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 1hkIBD-000R7E-5s for guile-user@m.gmane.org; Mon, 08 Jul 2019 03:10:55 +0200 Original-Received: from localhost ([::1]:37930 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkIBC-0007CL-7h for guile-user@m.gmane.org; Sun, 07 Jul 2019 21:10:54 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57794) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkIAl-0007Aa-Tu for guile-user@gnu.org; Sun, 07 Jul 2019 21:10:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkIAk-0005d2-Qh for guile-user@gnu.org; Sun, 07 Jul 2019 21:10:27 -0400 Original-Received: from world.peace.net ([64.112.178.59]:53412) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hkIAk-0005bu-Mb for guile-user@gnu.org; Sun, 07 Jul 2019 21:10:26 -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 1hkIAj-0006um-C5; Sun, 07 Jul 2019 21:10:25 -0400 In-Reply-To: <875zoda2e4.fsf@netris.org> (Mark H. Weaver's message of "Sun, 07 Jul 2019 18:46:59 -0400") 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:15613 Archived-At: Hello again, Chris Vine writes: > My version was hygienic when used in functions, but not when used as a > macro in a macro. Not to belabor the point, but I wanted to mention that the unhygienic '->' macro may fail when used in procedures, even when '->' is never used in the definition of another macro. Here's an example, where 'cut' and '->' are used in combination: --8<---------------cut here---------------start------------->8--- scheme@(guile-user)> ,use (srfi srfi-26) 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 foo (cut -> <> (format #t "~A\n"))) ;;; :17:12: warning: possibly unbound variable `t-15fc270a-2d' scheme@(guile-user)> (foo 4) :17:34: In procedure foo: In procedure module-lookup: Unbound variable: t-15fc270a-2d Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. scheme@(guile-user) [1]> ,q scheme@(guile-user)> ,expand (cut -> <> (format #t "~A\n")) $1 = (lambda (t-15fc270a-34-1) (format #t "~A\n" t-15fc270a-34)) scheme@(guile-user)> (define-syntax -> (syntax-rules () ((-> exp) exp) ((-> exp ... (op args ...)) (op args ... (-> exp ...))))) scheme@(guile-user)> (define foo (cut -> <> (format #t "~A\n"))) scheme@(guile-user)> (foo 4) 4 $2 = #t scheme@(guile-user)> ,expand (cut -> <> (format #t "~A\n")) $3 = (lambda (t-15fc270a-59) (format #t "~A\n" t-15fc270a-59)) scheme@(guile-user)> --8<---------------cut here---------------end--------------->8--- So, more generally, unhygienic macros may cause problems when they are used in combination with other macros. Since macros are so ubiquitous in Scheme, attempting to avoid such combinations is likely to be brittle. Best, Mark