Re: Can (export ...) be used reliably from inside a macro expansion?

Peter Bex via Chicken-users <[email protected]>
Newsgroups gmane.lisp.scheme.chicken
Message-ID <aKmpCIzq8f1_Zjdf@doggett>
On Fri, Aug 22, 2025 at 09:51:20AM -0700, Rolando Abarca via Chicken-users wrote:
> So my question is: is it possible in CHICKEN to dynamically generate export
> declarations from inside a macro expansion, or is the module system
> designed in such a way that the export list must be known before macro
> expansion?

This should work.  I struggled a bit myself before realizing that the
documentation says an export should always *precede* its definition.
Maybe you missed that too.

For instance, this works:

  (module foo ()
    (import scheme (chicken module))
  
    (define-syntax define&export
      (syntax-rules ()
        ((_ ?name ?value)
         (begin (export ?name)
                (define ?name ?value)))))
  
    (define&export x 1))

  (import foo)
  (print x)

Hope this helps!

Cheers,
Peter
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.