STklos Reference Manual
1. Introduction


1.1 Overview of STklos

STklos is the successor of STk [7], a Scheme interpreter which was tightly connected to the Tk graphical toolkit [12]. STk had an object layer which was called STklos. At this time, STk was used to denote the base Scheme interpreter and STklos was used to denote its object layer, which was an extension. For instance, when programming a GUI application, a user could access the widgets at the (low) Tk level, or access them using a neat hierarchy of classes wrapped in STklos.

Since the object layer is now more closely integrated with the language, the new system has been renamed STklos and STk is now used to designate the old system.

Compatibility with STk: STklos has been completely rewritten and as a consequence, due to new implementation choices, old STk programs are not fully compatible with the new system. However, these changes are very minor and adapting a STk program for the STklos system is generally quite easy. The only programs which need heavier work are programs which use Tk without objects, since the new preferred GUI system is now based on GTK+ [2]. Programmers used to GUI programming using STklos classes will find that both system, even if not identical in every points, share the same philosophy.

1.2 Lexical Conventions

1.2.1 Identifiers

In STklos, by default, identifiers which start (or end) with a colon ":" are considered as keywords. For instance :foo and bar: are STklos keywords, but not:key is not a keyword. Alternatively, to be compatible with other Scheme implementations, the notation #:foo is also available to denote the keyword of name foo. See section Keywords for more information.

The reader behavior, concerning keywords, can also be changed by the following directives:

  • the #!keyword-colon-position-none tells the reader that colon in a symbol should not be interpreted as a keyword;
  • the #!keyword-colon-position-before tells the reader that a symbol starting with a colon should be interpreted as a keyword;
  • the #!keyword-colon-position-after tells the reader that a symbol ending with a colon should be interpreted as a keyword;
  • the #!keyword-colon-position-both tells the reader that a symbol starting or ending with a colon should be interpreted as a keyword
In any case, the notation #:key is always read as a keyword.

By default, STklos is case sensitive as specified by R7RS. This behavior can be changed by

  • the --case-insensitive option used for the commands stklos or stklos-compile
  • the directive #!fold-case. This directive can appear anywhere comments are permitted but must be followed by a delimiter. This directive (and the #!no-fold-case) are treated as comments, except that they affect the reading of subsequent data from the same port. The #!fold-case directive causes subsequent identifiers and character names to be case-folded as if by string-foldcase. It has no effect on character literals. The #!no-fold-case directive causes the reader to a non-folding behavior.


There are four types of comments in STklos:

  • a semicolon ";" indicates the start of a comment. This kind of comment extends to the end of the line (as described in R5RS).
  • multi-lines comment use the classical Lisp convention: a comment begins with "#|" and ends with "|#". This form of comment is now defined by SRFI-30 (Nested Multi-line Comments).
  • a sharp sign followed by a semicolon "#;" comments the next Scheme expression. This is useful to comment a piece of code which spans multiple lines
  • comments can also be introduced by "#!"''. Such a comment extends to the end of the line which introduces it. This extension is particularly useful for building STklos scripts. On most Unix implementations, if the first line of a script looks like this:
     #!/usr/local/bin/stklos -file 
    then the script can be started directly as if it was a binary program. STklos is loaded behind the scene and executes the script as a Scheme program. This form is compatible with the notation introduced in SRFI-22 (Running Scheme Scripts on Unix)

    Note that, as a special case, that the sequences "#!key", "#!optional" and "#!rest" are respectively converted to the STklos keywords ":key", ":optional" and ":rest". This permits to Scheme lambdas, which accepts keywords and optional arguments, to be compatible with DSSSL lambdas [11].

1.2.3 Here Strings

Here strings permit to easily enter multilines strings in programs. The sequence of characters #<< starts a here string. The characters following this sequence #<< until a newline character define a terminator for the here string. The content of the string includes all characters between the #<< line and a line whose only content is the specified terminator. No escape sequences are recognized between the starting and terminating lines.

Example: the sequence


is equivalent to the string

"abc\ndef\n  ghi"

1.2.4 Other Notations

STk accepts all the notations defined in R5RS plus

  • #true and #false are other names for the constants #t and #f as proposed by R7RS.
  • "[]" Brackets are equivalent to parentheses. They are used for grouping and to build lists. A list opened with a left square bracket must be closed with a right square bracket (see section Pairs and lists).
  • ":" a colon at the beginning or the end of a symbol introduces a keyword. Keywords are described in section Keywords.
  • #n= is used to represent circular structures. The value given of n must be a number. It is used as a label, which can be referenced later by a #n# notation (see below). The scope of the label is the expression being read by the outermost read.
  • #n# is used to reference some object previously labeled by a #n= notation; that is, #n# represents a pointer to the object labeled exactly by #n=. For instance, the object returned by the following expression
    (let* ((a (list 1 2))
           (b (cons 'x a)))
      (list a b))
    can also be represented in this way:
    (#0=(1 2) (x . #0#))

1.3 Basic Concepts

See the original R5RS document for more informations on the basic concepts of the Scheme Programming Language.

This Html page has been produced by Skribe.
Last update Wed Nov 24 17:57:13 2021