From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Chris Vine Newsgroups: gmane.lisp.guile.user Subject: Re: Threading / Pipe Macro Date: Mon, 8 Jul 2019 01:10:42 +0100 Message-ID: <20190708011042.a4351568585c072da976c2d3@gmail.com> References: <5f08685b-be5b-e584-af54-9f4244039b1a@gmail.com> <20190707193259.434e1a816c551ece292f45da@gmail.com> <871rz1fxr7.fsf@netris.org> <20190707211613.4a8a637da93e592b4f737a7f@gmail.com> <87v9wd7a9w.fsf@netris.org> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="148057"; mail-complaints-to="usenet@blaine.gmane.org" Cc: guile-user@gnu.org To: Mark H Weaver Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Jul 08 02:11:43 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 1hkHFv-000cQR-7P for guile-user@m.gmane.org; Mon, 08 Jul 2019 02:11:43 +0200 Original-Received: from localhost ([::1]:37742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkHFt-0006CD-KM for guile-user@m.gmane.org; Sun, 07 Jul 2019 20:11:41 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47447) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkHF5-0006AP-Ew for guile-user@gnu.org; Sun, 07 Jul 2019 20:10:52 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkHF4-00070S-2X for guile-user@gnu.org; Sun, 07 Jul 2019 20:10:51 -0400 Original-Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:42143) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hkHF2-0006ug-Qh for guile-user@gnu.org; Sun, 07 Jul 2019 20:10:50 -0400 Original-Received: by mail-wr1-x436.google.com with SMTP id a10so13991343wrp.9 for ; Sun, 07 Jul 2019 17:10:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o0lt+AU2WJS+NKeEwwKulanvUhotYakwdDLW4AAf98c=; b=J9CsjdCcXiEfRJ83jZPzEn+NLAqVtdh/hsuiYS4ElQyjh8ciEuU0xZ6pZjtSHe8Pb7 OSSj3oA1kiXjYhasowF4/Pw7d7lGcybOH5UqfoJ0JFTz0H4dpaLjycdDJHTer+z3ckdC ZY8i90qicjL+p3TZW1W7XOEu+D8N1stZtN3LXb6PtFc255HTlFa+R5sEbh0xHZZUFmTl Wt9xsVI5uYsGbZjRtwMgKywS8tRo4jlj2X/P0POgUgXLs3B6KSMqx0IMh10Al0lQaBlg 3XRdM40VeQWAk4zZP7sRFYUA49n6mSn9Udhg9v2OUlGpN0dIDqZBMLUo26d21Bk/05p3 Ra1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o0lt+AU2WJS+NKeEwwKulanvUhotYakwdDLW4AAf98c=; b=O5BrBtLrhlFBqvgJDAvAEm5JvcMtl6ixsKTAywXo2iFsAb3dnXERux5KBcb2qg1jLI VyUoanX2biVoE9YHgzm4xJ5Ji+GJUEoRJyRrBqiw+Z1oVjEQqUnQr3tBnPGx5GnFCDWO unPS6gv91JibKYYr3EJ4WbK9C1lNNH2BxqlbLhs+Q7C9KICgS/eZWgwUHAQDbyGr2rc1 BLw1nFvVy62mOK7mZJVh1mmvcM1oqo8udovUoDs0vnpius/jc1V8V1QxclECLuF8J4KI 8yQhlL7tQlVCFRxbfV6W7D4SL3DMud0qedoqGVu2FkZaEU971QVd2Myir39cFojOZfbm 4HIQ== X-Gm-Message-State: APjAAAVjA6y2ZAtBc+ouuIp1gGjDEiYwpryIrQ/xRIux0rfT8Ow5odoL 8DMDtXFIaRIo2s2ww/9CJ3Vt9pEV X-Google-Smtp-Source: APXvYqyaSCZAl2UJFDspUzcjizKKnS0Je9nXThtDGECnhGeoUjzcXfuTjSp+2BuD62dxqx07AgshpQ== X-Received: by 2002:a5d:438e:: with SMTP id i14mr293266wrq.122.1562544644488; Sun, 07 Jul 2019 17:10:44 -0700 (PDT) Original-Received: from dell.homenet ([2002:545c:977f:10:e914:12bc:631d:b899]) by smtp.gmail.com with ESMTPSA id z9sm20894734wrs.14.2019.07.07.17.10.43 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 07 Jul 2019 17:10:43 -0700 (PDT) Original-Received: from dell.homenet (localhost [127.0.0.1]) by dell.homenet (Postfix) with SMTP id 77530425CE3; Mon, 8 Jul 2019 01:10:42 +0100 (BST) In-Reply-To: <87v9wd7a9w.fsf@netris.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-unknown-linux-gnu) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::436 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:15611 Archived-At: On Sun, 07 Jul 2019 18:24:32 -0400 Mark H Weaver wrote: > 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. You will have seen that your post crossed with mine which agreed with you. My assumption as it happens was that when all you were doing was rearranging input forms then it was not possible when using it to have "two distinct variables named 't'". I have been proved to be wrong in the case of your particular example of a macro in a macro. Anyway, the original poster now has two implementations of a pipeline operator which do work correctly, one using syntax-rules and one doing it the harder way with syntax-case. It had not occurred to me that syntax-rules could actually do it. It is a sufficiently useful macro that there seems to me to be a case for putting it in guile. As I mentioned, I use it frequently. Chris