GNU TeXmacsUser manualReferenceAboutEnglish
TeXmacs abbreviations

The TeXmacs Scheme kernel defines a few abbreviations and control structures which are used throughout the Scheme code of TeXmacs. Most of them are defined in

kernel/boot/abbrevs.scm

,

kernel/boot/srfi.scm

and

kernel/boot/ahash-table.scm

(relative to

src/TeXmacs/progs/

). Since they are loaded at boot time, they are available in all modules.

Predicates

(== x y)

(!= x y)
(structural equality)

== is an abbreviation for equal? and != for its negation.

(nnull? x), (npair? x), (nlist? x), (nstring? x), (nsymbol? x)
(negated predicates)

Negations of the corresponding standard predicates.

(list-1? x), (list-2? x), (list-3? x), (list-4? x), (list>0? x), (list>1? x)
(lists of given lengths)

Test whether x is a list of length \(1\), \(2\), \(3\), \(4\), \(> 0\) resp. \(> 1\). The negations are nlist-1?, etc.

(in? x l)

(nin? x l)
(membership)

Test whether x is (not) a member of the list l (using equal?). The routine (cons-new x l) adds x in front of l unless it is already a member.

Control structures

(when cond body …)

(unless cond body …)
(conditional execution)

Execute body if cond holds resp. does not hold.

(with var val body …)
(local binding)

Abbreviation for (let ((var val)) body …). If var is a list of variables, then val should evaluate to a list whose elements are bound to these variables, as in

(with (x y) (list 1 2) (+ x y))
(and-with var val body …)
(local binding of a non-false value)

Bind var to val and evaluate body only if val is not #f; otherwise return #f.

(and-let* (clause …) body …)
(sequential conditional bindings (SRFI-2))

Each clause is either of the form (var expr), (expr) or a variable. The clauses are evaluated in sequence and #f is returned as soon as one of them evaluates to #f; otherwise, body is evaluated with the bindings made by the clauses. For instance:

(and-let* ((t (tree-innermost 'frac))
           (num (tree-ref t 0))
           ((tree-atomic? num)))
  (tree->string num))
(receive vars expr body …)
(multiple values (SRFI-8))

Bind the multiple values returned by expr to vars and evaluate body. The kernel also provides the SRFI constructs case-lambda, cut and cute.

(with-global var val body …)
(temporary assignment)

Temporarily set the (global) variable var to val while evaluating body, and restore the old value afterwards. The value of the last expression of body is returned.

(with-result result body …)
(return a value computed beforehand)

Evaluate result, then body, and return the value of result.

(for (x l) body …)

(for (i start end) body …)

(for (i start end step) body …)
(loops)

The first form evaluates body for each element x of the list l. The other forms evaluate body for \(\text{\tt{\text{{\ttfamily{i}}}}} = \text{\tt{\text{{\ttfamily{start}}}}}, \text{\tt{\text{{\ttfamily{start}}}}} + \text{\tt{\text{{\ttfamily{step}}}}}, \ldots\), as long as \(\text{\tt{\text{{\ttfamily{i}}}}} < \text{\tt{\text{{\ttfamily{end}}}}}\) (or \(\text{\tt{\text{{\ttfamily{i}}}}} > \text{\tt{\text{{\ttfamily{end}}}}}\) if step is negative); the default step is \(1\). The related macros (repeat n body …) and (twice body …) evaluate body n times resp. twice.

(.. start end)

(… start end)
(ranges)

Return the list of integers from start to end, with end excluded resp. included. An optional third argument specifies the step.

(toggle! var)
(toggle a boolean variable)

Abbreviation for (set! var (not var)).

Hash tables

TeXmacs uses its own names for hash tables based on equal?, so as to be independent of the underlying Scheme implementation:

(make-ahash-table)

(ahash-ref h key)

(ahash-set! h key val)

(ahash-remove! h key)
(basic operations)

Create a new table, look up a key (#f is returned for missing keys), set resp. remove an entry. Further routines are ahash-size, ahash-fold, (ahash-ref* h key default), ahash-table->list, list->ahash-table, ahash-table-map, ahash-table-invert, ahash-table-append and ahash-table-difference.

(define-table name (key val …) …)
(global tables)

Define a public hash table name (if not yet defined) and add the given entries to it: each key is associated to the list (val …). The entries are quasi-quoted.

Strings and lists

Among the many small utilities on strings and lists defined in

kernel/library/base.scm

and

kernel/library/list.scm

, let us mention string-starts?, string-ends?, string-contains?, string-tail, string-split-lines, string-decompose, list-filter, list-find, list-remove-duplicates. The C++ glue provides further string routines, such as string-search-forwards, string-search-backwards and string-replace.

Running external programs

(eval-system cmd)

(var-eval-system cmd)
(run a shell command)

Run the shell command cmd and return its standard output as a string. The variant var-eval-system removes trailing newlines.

(evaluate-system args fd-in in fd-out)
(run a program with redirections)

Run the program whose name and arguments are given by the list of strings args, without passing through a shell. The strings in the list in are written to the file descriptors in the list fd-in, and the output on the file descriptors in the list fd-out is collected. The result is a list whose first element is the exit code (as a string), followed by the collected outputs. For instance:

(evaluate-system (list "sort") '(0) (list "b\na\n") '(1 2))

returns ("0" "a\nb\n" "").

(async-eval-system cmd call-back)
(asynchronous shell command)

Start the shell command cmd in the background and call call-back with its output when it has finished. Returns #t on error.

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