From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxime Devos Newsgroups: gmane.lisp.guile.devel,gmane.comp.gnu.guix.devel Subject: A lexical use-modules? Date: Sat, 26 Mar 2022 20:21:07 +0100 Message-ID: Mime-Version: 1.0 Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-qalLeVX3MuqOVsKi+GvW" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37877"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.38.3-1 To: guile-devel@gnu.org, guix-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Sat Mar 26 20:21:31 2022 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 1nYByd-0009gF-FV for guile-devel@m.gmane-mx.org; Sat, 26 Mar 2022 20:21:31 +0100 Original-Received: from localhost ([::1]:39652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nYByb-0001ze-Li for guile-devel@m.gmane-mx.org; Sat, 26 Mar 2022 15:21:29 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:59986) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nYByR-0001zN-3W for guile-devel@gnu.org; Sat, 26 Mar 2022 15:21:19 -0400 Original-Received: from [2a02:1800:120:4::f00:14] (port=37168 helo=xavier.telenet-ops.be) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nYByP-00064V-2v for guile-devel@gnu.org; Sat, 26 Mar 2022 15:21:18 -0400 Original-Received: from [172.20.10.5] ([213.119.168.171]) by xavier.telenet-ops.be with bizsmtp id B7MB270093iD4dh017MCWY; Sat, 26 Mar 2022 20:21:12 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r22; t=1648322472; bh=+FpZqnXXQClWuoISV/8+5lohrZEqBs5/KpZze7zQOh0=; h=Subject:From:To:Date; b=aVWLjI3g0G0+cNOjNFqgEqo8LaKpEhYfNN3hLiatFeDv1L9WEhA4iOsDOqB7Q8STG rWLRA9c+65lm1cNUTILQZTwR0LuO5gH4DJx5Tx0nbHOV0JGf3dPEWl00CGahMTsIU4 vfnQYPZgoK34xfFefQ8K1NAhsJvIyc/LXffy+Tz6DmyIwWzmtoyMEmZWg222oToDsS wLx6+gOunPyo8TrRHcdN1rDVDCTIwFwhlUBdE+xkTj4BCYlII0g9K/Nhasc+nYj6P5 IZsibRa8G8jGg6QySUQSw/XLU3hI36SbpXfTh8VnfcBNSJtL9/EeLxs0Gqm7nh54fi dBumSS+k0u9pg== X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a02:1800:120:4::f00:14 (failed) Received-SPF: pass client-ip=2a02:1800:120:4::f00:14; envelope-from=maximedevos@telenet.be; helo=xavier.telenet-ops.be X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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" Xref: news.gmane.io gmane.lisp.guile.devel:21177 gmane.comp.gnu.guix.devel:61971 Archived-At: --=-qalLeVX3MuqOVsKi+GvW Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, [ CC'ing guix-devel@ because this functionality could be useful in Guix package definitions ] Currently, use-modules cannot be meaningfully used inside procedures, unless '(current-module)' is always the module in which the procedure is defined. I wondered if some kind of 'lexical use-modules' was possible, with sufficient macroology and module reflection, and it looks like it is: (use-modules (srfi srfi-1)) (define-syntax use-module/lexical ;; todo: integrate into (use-modules ...)? (lambda (s) (syntax-case s () ((_ foo) (let* ((module-name (syntax->datum #'foo)) (interface (resolve-interface module-name))) (define (binding->import name variable) (define name-syntax (datum->syntax s name)) #`(define-syntax #,name-syntax (identifier-syntax (@ foo #,(datum->syntax #'irrelevant name))))) #`(begin #,@(module-map binding->import interface))))))) (define &exception 'top-level) (let () (use-module/lexical (ice-9 exceptions)) (pk 'inner &exception raise-continuable)) ;;; (inner # #) (pk 'outer &exception) ;;; (outer top-level) (pk 'unbound-variable raise-continuable) ;; a backtrace! Limitation: things like (define (foo) (use-module/lexical (platform-specific-constants)) (if on-linux? CONSTANT_ONLY_DEFINED_ON_LINUX CONSTANT_ONLY_DEFINED_ON_HURD)) won't work in cross-compilation contexts. Greetings, Maxime. --=-qalLeVX3MuqOVsKi+GvW Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYj9noxccbWF4aW1lZGV2 b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7pG+AP4vhC6duf6MMWr1/AebTP92dVSt KYqjkeAaqgyjepEnXgD/QwCFJGnnZQk3Ow2hirfV8WOQAlbdV3aRipBd/mhCIgM= =1yFl -----END PGP SIGNATURE----- --=-qalLeVX3MuqOVsKi+GvW--