chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

require-extension and require-library


From: Erica Z
Subject: require-extension and require-library
Date: Wed, 22 Dec 2021 16:06:56 +0100

Hello all,

I’m trying to set up a project so it can be executed identically both through 
the interpreter and through the compiler, depending on my needs. The code is 
split in modules, and I’m looking for a way to structure them in a way csi and 
csc will understand; so far I’ve found no code in the manual that will make 
this seamless.

What does seem promising to me is the require-extension syntax in 
chicken.base. At first it was unclear what this macro actuall did; it refers 
to require-library, which refers to require (no mention of chicken.load, where 
that form is actually defined and documented). After doing some digging, I 
found it to be more or less what I was looking for; it would accept an import 
specification, figure out where it was actually provided, and then actually 
import it, all in a way that would make sense for the way the code was being 
run.

There are some snags, however. The documentation for require-extension states 
that it’s, in a sense, equivalent to require-library, even though I got 
completely different results when using both. I have three files:

extra.scm
    (module extra (do-the-thing)
      (import scheme)
      (define (do-the-thing) (display "Here's a test!\n"))
    )

main_a.scm
    (require-extension extra)
    (do-the-thing)

main_b.scm
    (require-library extra)
    (import extra)
    (do-the-thing)

As far as I can understand, main_a.scm and main_b.scm should behave 
identically. However, when I run them, only the latter woks:

$ csi -n main_a.scm
CHICKEN
(c) 2008-2021, The CHICKEN Team
(c) 2000-2007, Felix L. Winkelmann
Version 5.3.0 (rev e31bbee5)
linux-unix-gnu-x86-64 [ 64bit dload ptables ]

Type ,? for help.
; loading main_a.scm ...

Error: (import) during expansion of (import18 ...) - cannot import from 
undefined module: extra

        Call history:

        <syntax>          (##core#quote #f)
        <syntax>          (##core#require library chicken.base)
        <syntax>          (chicken.load#load-unit (##core#quote library) 
(##core#quote #f) (##core#quote #f))
        <syntax>          (##core#quote library)
        <syntax>          (##core#quote #f)
        <syntax>          (##core#quote #f)
        <syntax>          (##core#begin (##core#require expand 
chicken.syntax))
        <syntax>          (##core#require expand chicken.syntax)
        <syntax>          (chicken.load#load-unit (##core#quote expand) 
(##core#quote #f) (##core#quote #f))
        <syntax>          (##core#quote expand)
        <syntax>          (##core#quote #f)
        <syntax>          (##core#quote #f)
        <eval>    (chicken.load#load-unit (##core#quote library) (##core#quote 
#f) (##core#quote #f))
        <eval>    (chicken.load#load-unit (##core#quote library) (##core#quote 
#f) (##core#quote #f))
        <eval>    (chicken.load#load-unit (##core#quote expand) (##core#quote 
#f) (##core#quote #f))
        <syntax>          (require-extension extra)     <--

$ csi -n main_b.scm
CHICKEN
(c) 2008-2021, The CHICKEN Team
(c) 2000-2007, Felix L. Winkelmann
Version 5.3.0 (rev e31bbee5)
linux-unix-gnu-x86-64 [ 64bit dload ptables ]

Type ,? for help.
; loading main_b.scm ...
; loading ./extra.scm ...
Here's a test!
#;1>

Is there anything I’m missing? In any case, I believe the documentation should 
be much clearer in this regard.

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]