GNU TeXmacsUser manualReferenceAboutEnglish
femtolisp: loading files, and the modules

1.What is loaded at the start

init-femtolisp.scm

is loaded with the load of femtolisp. It loads

r5rs-femtolisp.scm

, then

boot-femtolisp.scm

, both as plain global definitions; from there on load is the one of

boot-femtolisp.scm

. It then loads the module (kernel boot compat-femtolisp), and the

init-kernel.scm

and

init-texmacs.scm

which all the interpreters share.

2.A module is a set of renamed global names

femtolisp has one global environment, and the modules of TeXmacs define the same private names over and over (more than two hundred names are private to several modules). So the private definitions of a module are renamed. When the file of a module is loaded (%load-forms):

The public definitions are global under their own names: define-public, define-public-macro, provide-public, tm-define, tm-define-macro, tm-menu, tm-widget, menu-bind, tm-property, export. A name which a module defines both with a plain define and with tm-define stays private in it, as in Guile, where the binding of the module hides the one of the user module.

More exactly: only a name written as a plain define or define-macro at one of the places which are scanned is private. Every other definition is global, also the ones which a macro makes (define-table, define-preferences…). And a plain define of a name is made public only by a define-public, define-public-macro, provide-public, export or re-export of the same name in the file.

A module is the vector #(module name privates), kept in the table *modules*; privates is the table of its private names. In the user module *current-module* is #f and nothing is renamed; (current-module) then gives the symbol texmacs-user.

What differs from Guile:

3.tm-define

kernel/texmacs/tm-define.scm

has branches for femtolisp, close to those for S7:

4.When macros are expanded

femtolisp expands the macros of a form when it compiles it; Guile and S7 expand them when they first evaluate it. The code of TeXmacs relies on the second behaviour in three ways, each of which was a source of bugs:

The lazy function bodies of the next chapter answer the first two for the code inside functions: a body is expanded when it is first called. The third remains for the forms at the top level of a file, which are expanded when the file is loaded, whatever they test. Such macros were changed to have their effect when the code runs: lazy-format, lazy-keyboard, lazy-define. A new macro must do the same: its expansion may compute, it must not register anything.

With TEXMACS_FL_EAGER=1 the bodies are expanded when the file is loaded, as femtolisp does by itself. Two older devices then take over: a call of a name which is neither bound, nor a macro, nor defined by the file being loaded when it is compiled, is compiled at its first evaluation (the hook compile-unknown-call, patch 0010, and %late-call), and a macro whose expansion fails gives code which raises the error when it runs (*defer-macro-errors*, patch 0013).

5.The functions of the compiler are protected

The functions of system.lsp and compiler.lsp call each other by their global names, and TeXmacs defines public functions with the same names (make-label, print…), which broke the compiler. The boot image is therefore made by compiling these two files twice (patch 0009): the second time, their references to each other go to private names %fl:name, so TeXmacs may redefine the public ones.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".