unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: prj@case.edu (Paul Jarc)
To: guile-user@gnu.org
Subject: custom module loading and compilation
Date: Sat, 11 May 2024 04:02:34 -0400	[thread overview]
Message-ID: <ozkdttj4ai91.fsf@case.edu> (raw)

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))))



             reply	other threads:[~2024-05-11  8:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-11  8:02 Paul Jarc [this message]
2024-05-13 13:54 ` custom module loading and compilation Nala Ginrut
2024-05-23 21:05 ` Paul Jarc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ozkdttj4ai91.fsf@case.edu \
    --to=prj@case.edu \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).