guix-devel
[Top][All Lists]
Advanced

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

Re: Semantics of circular imports


From: Maxime Devos
Subject: Re: Semantics of circular imports
Date: Sun, 27 Mar 2022 16:33:41 +0200
User-agent: Evolution 3.38.3-1

Philip McGrath schreef op zo 27-03-2022 om 10:12 [-0400]:
> (Also, what is a "compilation unit" in Guile? Is it ever something
> other  than a single module corresponding to a single file
> (potentially using  `include` to incorporate other files at expand
> time?)

(the following explanation ignores (guile)Eval when, which seems to
assign a different meaning)

IIUC, a compilation unit is what is turned into a .go file as a unit,
full of literals and code.  There are at least three situations:

  * (common):   If "foo.scm" is of the form

      (define-module (foo) #:use-module (bar)) ... (stuff)

    then, if, "foo.scm" is compiled "foo.go", "foo.go" contains code
    that constructs the value of global variables (procedures etc.),
    fix ups relocations, creates a module object, add the variables
    to the module object, and registers the module into the module
    system and runs (stuff)

  * (uncommon, discouraged):  "foo.scm" can, in principle, contain
    multiple modules:

    (define-module (bar) ...) ...
    (define-module (foo) ...) ...

    Then "foo.go" will contain code initialising both the modules.
    It can be rather confusing though, so I cannot recommend this.

  * (common):  It is also possible to compile Scheme files that don't
    define modules and only import some modules, e.g.

    (use-modules (fibonnaci))
    (for-each display (fibonacci-numbers #:upto 900))

    Then when "foo.go" is loaded, the fibonacci numbers are printed.

Greetings,
Maxime

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


reply via email to

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