From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Nala Ginrut Newsgroups: gmane.lisp.guile.user Subject: Re: custom module loading and compilation Date: Mon, 13 May 2024 22:54:21 +0900 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="2810"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user@gnu.org To: Paul Jarc Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Mon May 13 15:55:42 2024 Return-path: Envelope-to: guile-user@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 1s6W9W-0000WS-81 for guile-user@m.gmane-mx.org; Mon, 13 May 2024 15:55:42 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s6W8V-0007i3-TC; Mon, 13 May 2024 09:54:39 -0400 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 1s6W8U-0007hU-36 for guile-user@gnu.org; Mon, 13 May 2024 09:54:38 -0400 Original-Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s6W8S-0002tP-Bs for guile-user@gnu.org; Mon, 13 May 2024 09:54:37 -0400 Original-Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-2b3c711dfd3so3423103a91.2 for ; Mon, 13 May 2024 06:54:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715608474; x=1716213274; darn=gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=5uhot1KVl1Ymc7izMH7tCAH6FNJviAUsOTW1bdLQ858=; b=P80VQX02PCd7q0GX75Y25tEJAiYJdrPr8TsCWWrTet9WKydhPAyUB00KSoLy4DXqLU XoWOyiwaGF5nFFB2ZU2/ArjWJrJqeVHxPhXwg2IWfzgAHDl6RhYFhLiMb00zLWZBiFyP IrI1wBWWl9RH1CXPpjn2S5WyDzsd60J0MOih4PsmFM/QlZUoRKEPcvVA+IsBIIMaKQV7 pldcMM080ddLQjGM0tOZGPDULevDX0ZcV4xmnlP2NzUXfm7DjrBqnrdNEMdxiwN15V6R MeZ368D+MNU7qUf8mpQYs5i3KD0VMvpkrg5iajOQIcWeSt0ct/VRoRqNsarKR2zc3YVj pTLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715608474; x=1716213274; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5uhot1KVl1Ymc7izMH7tCAH6FNJviAUsOTW1bdLQ858=; b=EmWhHKzZCUGKWg99I3z/icBTmStqa+m/wO+iP9nxUFAUUTaX3wu7cKjPdFGd9GMWJg azOSVRyvKeI+PNvt3t5Rx24oDdgIYMd/04fnpoVKgiFbZVcnRHAInPpimAkaRtArwJX4 /RPbra1HZFJ+/mZLODkpC2yyfu90C1BXE4Fu2J7JupcJFxY21NakPx83DEJSThguE2ez mAk1nFeCtJB6R7fSncAqZzQofcqJ+Czqc+c+xwmD2zz8FdiZSrN6Orzs0BVJhXc/knZH 0en/+wRreyoJRd2hYxDG6T+RFbCeuRJB9tp3t2WT/e4nJnnxaXbFmcC9LFNVCYCcz/i9 aR8A== X-Gm-Message-State: AOJu0YxXQ+aixhjCuYOgNR0z53fc0biKbSfg9vfA6Ve2mK1dzVnrV7RZ L2O1JYYaTY3hd3hlnsbhHwxQDdccBIMGZl+94+uxh1JsZ0oZ4lWIYwf9cCn9wLFePWmwenfUgN0 O3z/VNaWxuCPIRX8z42pxGDSvbrQ= X-Google-Smtp-Source: AGHT+IHXZiL1SsGUNIbRzE6NAFbZVOVlMipO1sYvHcidJLO3E5m8iJCOGUrvRIaVVuyDowCwdJXHENxbNHkotVtEAMs= X-Received: by 2002:a17:90a:6786:b0:2b3:79ad:8572 with SMTP id 98e67ed59e1d1-2b6ccfef109mr6757742a91.49.1715608474035; Mon, 13 May 2024 06:54:34 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=nalaginrut@gmail.com; helo=mail-pj1-x102b.google.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, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.user:19643 Archived-At: Hi Paul! I don't know why you don't use the standard module definition and import/export interface, but if you do want to play modules with the introspection functions, here's a hint for you: --------------------------------------------------------------------------- (define (export-all-from-module! module-name) (let ((mod (resolve-module module-name))) (module-for-each (lambda (s m) (module-add! (current-module) s m)) mod)))) --------------------------------------------------------------------------- This function can be used to export all symbols from a specified module-name. You may modify it for your case. Best regards. On Sat, May 11, 2024 at 5:03=E2=80=AFPM Paul Jarc wrote: > Hi. I'm writing a custom module system that avoids the standard > search path and list-of-symbols naming scheme. Instead of using > use-modules and define-module, I have a roughly similar procedure, > let's call it my-load, that creates a module with make-module and > loads a file into it with primitive-load. I want to make my-load > automatically available within the modules I load so that they can use > it to load other modules too. So my-load adds itself to each new > module using module-define! before calling primitive-load. > > This works when I run Guile with --no-auto-compile, but with > compilation enabled, I get: > ;;; Unbound variable: my-load > How can I make the binding visible to the compiler? > > ;;main.scm > (define (my-load path-to-macros) > (let ((new-module (make-module 0 `(,(resolve-interface '(guile)))))) > (module-define! new-module 'my-load my-load) > (save-module-excursion > (lambda () > (set-current-module new-module) > (primitive-load path-to-macros))) > (let ((interface '(my-macro))) > (for-each (lambda (sym) > (module-define! (current-module) sym > (module-ref new-module sym))) > interface)))) > (eval-when (compile load eval) > (my-load "/path/to/macros1.scm")) > (display (my-macro 5)) > (newline) > > ;;macros1.scm > (eval-when (compile load eval) > (my-load "/path/to/macros2.scm")) > (display (my-macro 3)) > (newline) > > ;;macros2.scm > (define-syntax my-macro > (syntax-rules () > ((_ x) (+ x x)))) > >