GNU TeXmacsUser manualReferenceAboutEnglish
femtolisp: Scheme and Guile on femtolisp

femtolisp is close to Scheme, with names of its own (aref, string.sub, table, trycatch…), strings which know UTF-8, and a small library. Two files give TeXmacs the R5RS and the Guile 1.8 which its code is written for.

1.
r5rs-femtolisp.scm
: the language

Global definitions, loaded before the modules exist.

Redefining a builtin

The builtins of femtolisp are constants, and the compiler compiles the set! of a constant as nothing. define-override makes the name redefinable when it is expanded, before the definition is compiled; define-public does it too. The original is kept under a name starting with %fl- when the new definition needs it (%fl-eval, %fl-read, %fl-write…).

Symbols and keywords

:foo is a keyword and not a symbol, as in Guile with keywords written with a colon. symbol? is false for the keywords and for the unspecified value, which femtolisp makes a symbol, #<unspecified> (patch 0019).

Numbers

There are no exact rationals: (/ 1 2) is 0.5, and string->number reads 1/2 as an inexact number; written in a source file, 1/2 is read as a symbol. The exact integers have 64 bits: a larger one in a source file is read as an inexact number, string->number gives #f for it, and an operation which overflows wraps around without an error ((expt 2 70) is 0). quotient, remainder and modulo have the signs of R5RS; >, <=, >= take any number of arguments (< and = do in femtolisp, patch 0017). With two arguments which are variables or constants, they are compiled as instructions (patch 0026), and a comparison with a NaN is false.

Builtins under other names

vector-ref, vector-set!, vector-length, char->integer, integer->char are the builtins aref, aset!, length, fixnum, wchar, bound by

fl_core.c

as constants (so that the compiler makes them instructions): an error names the builtin, and a redefinition needs define-override. for-each is a builtin too; with several lists, it stops at the end of the shortest.

Complex numbers

A complex number is the vector #(%complex re im). + - * / = stay the fast instructions of femtolisp: for an operand which is not a number they call *arith-fallback* (patch 0020), defined here. number? is false for a complex number, and the other functions on numbers do not handle one: some raise an error (sqrt), others give a result without meaning (abs, <).

Characters and strings

A character is a byte and a string a string of bytes, in the Cork encoding: string-length counts bytes, char-upcase and char-alphabetic? know ASCII only, as in Guile 1.8. The basic functions on strings (string-length, string-ref, substring, string-set!, make-string, list->string, string->list, the search and the comparison) are C builtins of

fl_core.c

; the others are written in Scheme on them. femtolisp reads the octal characters of Guile wrongly (#\04 is read as the character 0 followed by 4): write (integer->char 4).

Control

call/cc only escapes: a continuation cannot be entered again. dynamic-wind, delay and force are there.

Errors

An error is the list (key . args), as in Guile: (throw 'my 1 2) is caught as (my 1 2). The errors of error and scm-error are (key subr message args rest); those of the glue have no rest. The errors of femtolisp itself (type-error, unbound-error…) are translated by %guile-error, for the handlers of catch and for the C++ code. catch, throw, error, scm-error, false-if-exception.

Reading and writing

The ports are the streams of femtolisp. write writes on one line, with labels only for cycles (*print-shared*, patch 0005) and closures as #<procedure f> (*print-closures*, patch 0018); the bytes from 128 of a string are written as they are (patch 0006). display and write without a port write to the output of TeXmacs (tm-output), as with Guile; this is done in

boot-femtolisp.scm

.

2.
compat-femtolisp.scm
: the library

The module (kernel boot compat-femtolisp), modelled on

compat-s7.scm

: the hash tables of Guile on the tables of femtolisp, the association lists, SRFI-1 (fold, filter-map, partition…) and the sorts, the string functions of SRFI-13, the character sets (a tagged vector which holds 256 booleans), object-property, procedure-name, procedure-source, procedure-arity, format (~a ~s ~% ~~), pretty-print, records, and the while of Guile with break and continue.

Two rules for this file:

3.What differs from Guile

4.Branches in the shared Scheme code

(femtolisp-scheme?) is #t here and #f with the other interpreters. Elsewhere femtolisp runs the code written for Guile, except in a few files which have a branch for it:

kernel/boot/prologue.scm

The modules are loaded by

boot-femtolisp.scm

, as for S7.

kernel/boot/ahash-table.scm

The ahash- functions are directly on the tables of femtolisp.

kernel/regexp/regexp-select.scm

select as on MinGW, without the select of Guile.

kernel/texmacs/tm-define.scm

Global definitions, see the modules.

prog/scheme-autocomplete.scm

The symbols come from the environment of femtolisp.

check/define-test.scm
,
check/macro-drd-test.scm

Two tests skip checks, as they do for S7: that :use restricts the names, and dates computed with the functions of Guile.

Keep such branches rare: a difference is better hidden in the two files above, so that the Scheme code of TeXmacs stays the same for all the interpreters.

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".