From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.user Subject: Re: macroexpand-1 Date: Sun, 03 Jun 2018 10:04:12 -0400 Message-ID: <87h8mkarvn.fsf@netris.org> References: <87zi0iwlo0.fsf@netris.org> <877enmc5of.fsf@netris.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1528034640 30331 195.159.176.226 (3 Jun 2018 14:04:00 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 3 Jun 2018 14:04:00 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Cc: Guile User To: Catonano Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Jun 03 16:03:56 2018 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fPTbv-0007mo-Lq for guile-user@m.gmane.org; Sun, 03 Jun 2018 16:03:55 +0200 Original-Received: from localhost ([::1]:35435 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPTe2-0002rV-TL for guile-user@m.gmane.org; Sun, 03 Jun 2018 10:06:06 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48386) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPTdg-0002rC-AP for guile-user@gnu.org; Sun, 03 Jun 2018 10:05:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPTdc-00079G-7r for guile-user@gnu.org; Sun, 03 Jun 2018 10:05:44 -0400 Original-Received: from world.peace.net ([64.112.178.59]:48888) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fPTdc-00076Q-3v for guile-user@gnu.org; Sun, 03 Jun 2018 10:05:40 -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 1fPTdQ-0003dM-Oa; Sun, 03 Jun 2018 10:05:28 -0400 In-Reply-To: (Catonano's message of "Thu, 31 May 2018 10:21:19 +0200") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 64.112.178.59 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 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:14602 Archived-At: Hi, Catonano writes: > 2018-05-30 3:07 GMT+02:00 Mark H Weaver : > > This is just a toy, and not very useful in practice. > Here's the equivalent formulation for Guile: > > (use-modules (system syntax) > (srfi srfi-11)) > > (define (syntax-local-value id) > (let-values (((type value) (syntax-local-binding id))) > value)) > > (define-syntax expand1 > (lambda (stx) > (syntax-case stx () > [(_expand1 form) > (syntax-case #'form () > [(id . more) > (identifier? #'id) > (let ([transformer (syntax-local-value #'id)]) > (with-syntax ([expansion (transformer #'form)]) > #''expansion))] > [_ > #''form])]))) > > (I usually prefer to avoid using square brackets in this way, but for > sake of comparison, I used them in the definition of 'expand1' above.) > > Anyway, it works the same way as in Racket for this simple example: > > scheme@(guile-user)> (expand1 (or 1 2 3)) > $2 = (let ((t 1)) (if t t (or 2 3))) > > This is surprising to me > > When I saw that example made in Racket for the first time I instantly > identified "syntax-local-value" as problematic You're right, it is problematic, and it's good that you noticed that. It exposes internal details of Guile's implementation, which is quite likely to change in the future. Do not use this interface if you can avoid it, and expect code that uses it to break in future versions of Guile. That said, it can be useful for writing things like macro steppers. > Will Guile have anything equivalent ? I asked myself > > Now you show me the "(system syntax)" namespace (or module) > > I didn't suspect it existed > > Does the manual mention it anywhere ? I didn' t see it Do you know how to search the manual or its index? Press 'i' from either the Emacs or standalone info browsers to search the index, where you can find 'syntax-local-binding'. You can also search the entire manual text by pressing 's'. You can find (system syntax) that way. > Or maybe does it belong to any scheme standard ? No, certainly not. > Do any more (system ....) namespaces exist ? > > How would I know ? Look in the "module" subdirectory of the Guile source tree for modules that come with Guile itself, or more generally in the directories of %load-path after installation. The directory structure mirrors the module namespaces. The module (foo bar baz) is found in /foo/bar/baz.scm, where is a component of %load-path. For example, (system syntax) is in /system/syntax.scm. In the Guile source tree, it's in module/system/syntax.scm. Mark