From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "yarl baudig" Newsgroups: gmane.lisp.guile.devel Subject: Re: define-module, #:export and export Date: Fri, 6 Jan 2023 14:31:43 +0100 (CET) Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21852"; mail-complaints-to="usenet@ciao.gmane.io" To: jean@abou-samra.fr, "Maxime Devos" , guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Fri Jan 06 14:33:01 2023 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pDmqC-0005OI-PN for guile-devel@m.gmane-mx.org; Fri, 06 Jan 2023 14:33:01 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pDmpl-0003Es-8d; Fri, 06 Jan 2023 08:32:34 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pDmpJ-0003BL-6v for guile-devel@gnu.org; Fri, 06 Jan 2023 08:32:08 -0500 Original-Received: from msg-1.mailo.com ([213.182.54.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pDmpD-0006Gx-H0 for guile-devel@gnu.org; Fri, 06 Jan 2023 08:32:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1673011903; bh=Pi1GCEPnjk7G6W+VJC44lodLXlpoCo1zMxdUyEKHe1g=; h=X-EA-Auth:From:To:Date:Subject:MIME-Version:X-Mailer:Message-ID: In-Reply-To:Content-Type:Content-Transfer-Encoding; b=dJq/rbgF5ekYsIPTA7cvHT6xjgg/HRAaomWlLyPEc9MDqMzOY16b/dkx/DPARHPm9 nFIzLKwcLsxn3lXiCvtNX8Idtb9cuTDMMahL6oLUd6MwQNXD0E3Hs+zP19rYxfSN7W J3FiR9T8DCeDOmqLqx5K/+2AWtPMOKvoW/5hjyUE= Original-Received: by www.mailo.com with http webmail; Fri, 6 Jan 2023 14:31:43 +0100 (CET) X-EA-Auth: uhIhPIME5+qmLWivsUVYUUiIW+sZOmT6Iwp86UBXED4Bmgs76o512zOF08FxyKOfBZJMRTZeQzP43+8mQMAqfLVAS5d1OdQw X-Priority: 3 X-Mailer: COMS/EA22.05/r20221103 In-Reply-To: Received-SPF: pass client-ip=213.182.54.11; envelope-from=yarl-baudig@mailoo.org; helo=msg-1.mailo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:21542 Archived-At: >=20 > That is also my understanding, confirmed by >=20 > $ cat lib.scm > (define-module (lib) > =C2=A0 #:export (test)) >=20 > (define-syntax test > =C2=A0 (lambda (sintax) > =C2=A0=C2=A0=C2=A0 (syntax-case sintax () > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ((test id) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (datum->syntax sintax (free-identi= fier=3D? #'id #'thing)))))) >=20 > $ cat test.scm > (define-module (main) > =C2=A0 #:use-module (lib) > =C2=A0 #:export (thing) > =C2=A0 ) >=20 > (display (test thing)) > (newline) >=20 > (define thing 5) >=20 > $ guile3.0 -L . test.scm > #f >=20 >=20 > If you comment out #:export (thing), the result changes to #t. >=20 > To put it perhaps more simply, the use of #:export causes Guile to=20 > understand early that there will be a variable 'thing' in this module,= =20 > and makes the identifier 'thing' refer to this variable that is not yet= =20 > defined. However, hygiene implies that you want to be able to use=20 > keywords as if they were not keywords if they are rebound, e.g. the=20 > 'else' here doesn't cause the cond clause to be taken: >=20 > (let ((else #f)) (cond (#f 'bla) (else 'foo) (#t 'bar))) > $1 =3D bar >=20 > The way this is done is by comparing with the original identifier given= =20 > to syntax-rules. Technically, they are compared with free-identifier=3D?= .=20 > This means that a use of the identifier matches the keyword iff both are= =20 > unbound, or both are bound to the same lexical binding. However, this=20= > isn't the case here, as the keyword in the macro was unbound, but at the= =20 > point of use, it has been bound by #:export. >=20 > Honestly, I think it is better to choose a different way of writing=20 > these macros that avoids this confusing issue. Try defining the=20 > operations at the same time as the enum so that the macro giving an enum= =20 > member refers to the bindings of the operators. If you give more context= =20 > on what you're trying to do, we could help more. >=20 > Best, > Jean >=20 >=20 Thank you both. I am trying to process this. I (re-)read 6.8 Macros and re= ad tspl4. I don't understand why you use "datum->syntax". I heard your suggestion. I am only trying to grasp things for now. I reali= ze I don't know enough (on guile and on guix) to go on a concrete goal yet.= I need to work more on this in order to understand but I wanted to thank y= ou for answering that quickly!