From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id iEsxGdUHQ2L0aAEAgWs5BA (envelope-from ) for ; Tue, 29 Mar 2022 15:21:25 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id gGeEFtUHQ2LUhAEA9RJhRA (envelope-from ) for ; Tue, 29 Mar 2022 15:21:25 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id CDFBEACDF for ; Tue, 29 Mar 2022 15:21:24 +0200 (CEST) Received: from localhost ([::1]:54554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZBmm-0007Qd-36 for larch@yhetil.org; Tue, 29 Mar 2022 09:21:24 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52298) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZBmE-0007PV-Ma; Tue, 29 Mar 2022 09:20:50 -0400 Received: from [2001:470:142:3::e] (port=35548 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZBmE-0002ZD-B7; Tue, 29 Mar 2022 09:20:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=ZpFtBoaK+hRqvnfb/sKolhKyt0jkGNn2GXHT+62daGI=; b=UFFNfNlbR5Cvo1V2Ymwb RgA1w2Fghb6qrUSHv3ol06t5mOnEIU8HLP16PYFhSngT4bRY9pbcxB6RMoQEX5+BhruqgbHhq6Glo k3FLdTKrTLSDIQoZeKe+MBIGHCCfDQkGZUYBoBteqmkQE4H33izbSNCG3OLIU+CAHCZGxM0wTTauq y/T5+k3ADriXgFbULMy6VP8yLeOfqwwP+ZCOJxgRkJZ2EVEOIXIXiMlcguvMkUGys38mgUAnK2cUm EquqjvSZsh0nrCt4w0TKrmXf8N2o0zJ94ucEL6vheeWa8qP7bT4on+g2AXtYKEA7eHdZTsda7ICsG UjBE1zrwAFEtkQ==; Received: from [193.50.110.177] (port=51532 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZBmD-0004oT-SJ; Tue, 29 Mar 2022 09:20:50 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Maxime Devos Subject: Re: A lexical use-modules? References: X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 9 Germinal an 230 de la =?utf-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Tue, 29 Mar 2022 15:20:48 +0200 In-Reply-To: (Maxime Devos's message of "Sat, 26 Mar 2022 20:21:07 +0100") Message-ID: <87wngcyjwv.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: guix-devel@gnu.org, guile-devel@gnu.org Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: "Guix-devel" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1648560084; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=ZpFtBoaK+hRqvnfb/sKolhKyt0jkGNn2GXHT+62daGI=; b=m3E+Btd5lprIRGz+3SGyAqCWOg5wJsHXzfzdcxdzYsMMMGLP7q9WEAFAHg4Jh3IcQe1GJf XECYe9aIA/Fej8poX7qetv7e9AuyfBHrIeRRlyxaSKF3YGmDPaOWb9jba0RDT8xjFObc9r 0v6UhscGL0Q5QZmtBIvZy8+v/qewQUAGDvR13VWAZZXvxJVkF3NaYp5KKcadF7YjjPxaLf qu+yjfZC8R4ngrZm4WngKEwc57HyQ3PdBOYkkM4a6EYLK5UfrVF4ijYxvkBZIQDWCFQrfN ba7b+sRyh3U2qhGeXFdCr4SBQ0h177lDJblX16NNhCU2XcmeCAMhub4Z9wMiDQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1648560084; a=rsa-sha256; cv=none; b=rCbMoTnFDEkEcolD64IwLBGMlOEseiDJyHfmjglwlfPAqmkfYTDCuJ1TjA+nEL1QFyd1Uy 6Pw3FyMyWIElsUkApglrKI0mE3tM/nq2bI3kfCKafSqCTSFyXehpFkvMJ2vHSEYXh9Ypee m98f9O/DfOqkE4luPkymvsDBebOIGKA4b++eiQFdrCZjYgvbDecBcPz92K7PtcOyfEmoFH d+dbW3sGFCzacmsg2qTpHqWTOVSqu2KxFypxyv+8qOPOokCJkClDUxb1b+pPtbMS7DlSgC A55rfUhe8eovukUFGLjlSiZcopaiOSVKSqMGoAE+SRwr9F/hyr5RCt/kRYUB7g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gnu.org header.s=fencepost-gnu-org header.b=UFFNfNlb; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -5.87 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gnu.org header.s=fencepost-gnu-org header.b=UFFNfNlb; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: CDFBEACDF X-Spam-Score: -5.87 X-Migadu-Scanner: scn0.migadu.com X-TUID: 4NUPmKkmGyGP Hi, Maxime Devos skribis: > I wondered if some kind of 'lexical use-modules' was possible, with > sufficient macroology and module reflection, and it looks like it is: I agree it would be useful. Just yesterday wrote this (my goal here was to allow dynamic module loading based on some condition); --8<---------------cut here---------------start------------->8--- (define-syntax with-modules (syntax-rules () "Dynamically load the given MODULEs at run time, making the chosen bindings available within the lexical scope of BODY." ((_ ((module #:select (bindings ...)) rest ...) body ...) (let* ((iface (resolve-interface 'module)) (bindings (module-ref iface 'bindings)) ...) (with-modules (rest ...) body ...))) ((_ () body ...) (begin body ...)))) --8<---------------cut here---------------end--------------->8--- =E2=80=A6 which can be used like this: --8<---------------cut here---------------start------------->8--- (with-modules (((fibers) #:select (spawn-fiber sleep)) ((fibers channels) #:select (make-channel put-message get-message))) (let ((channel (make-channel))) (spawn-fiber =E2=80=A6))) --8<---------------cut here---------------end--------------->8--- Unlike =E2=80=98use-modules=E2=80=99, its clearly limited to the lexical sc= ope of its body. IWBN to have a similar functionality in Guile proper, and it could probably be made more efficient. Ludo=E2=80=99.