Next: , Previous: , Up: The Language   [Contents][Index]

4.8 Lexical Conventions


4.8.1 Common-Lisp Read Syntax

Read syntax: #\token

If token is a sequence of two or more digits, then this syntax is equivalent to #.(integer->char (string->number token 8)).

If token is C-, c-, or ^ followed by a character, then this syntax is read as a control character. If token is M- or m- followed by a character, then a meta character is read. c- and m- prefixes may be combined.

Read syntax: #+ feature form

If feature is provided? then form is read as a scheme expression. If not, then form is treated as whitespace.

Feature is a boolean expression composed of symbols and and, or, and not of boolean expressions.

For more information on provided?, See Require in SLIB.

Read syntax: #- feature form

is equivalent to #+(not feature) expression.

Read syntax: #| any thing |#

Is a balanced comment. Everything up to the matching |# is ignored by the read. Nested #|…|# can occur inside any thing.

Load sytax is Read syntax enabled for read only when that read is part of loading a file or string. This distinction was made so that reading from a datafile would not be able to corrupt a scheme program using ‘#.’.

Load syntax: #. expression

Is read as the object resulting from the evaluation of expression. This substitution occurs even inside quoted structure.

In order to allow compiled code to work with #. it is good practice to define those symbols used inside of expression with #.(define …). For example:

#.(define foo 9)                        ⇒ #<unspecified>
'(#.foo #.(+ foo foo))                  ⇒ (9 18)
Load syntax: #' form

is equivalent to form (for compatibility with common-lisp).


4.8.2 Load Syntax

#! is the unix mechanism for executing scripts. See Unix Scheme Scripts for the full description of how this comment supports scripting.

Load syntax: #?line
Load syntax: #?column

Return integers for the current line and column being read during a load.

Load syntax: #?file

Returns the string naming the file currently being loaded. This path is the string passed to load, possibly with ‘.scm’ appended.


4.8.3 Documentation and Comments

procedure: procedure-documentation proc

Returns the documentation string of proc if it exists, or #f if not.

If the body of a lambda (or the definition of a procedure) has more than one expression, and the first expression (preceeding any internal definitions) is a string, then that string is the documentation string of that procedure.

(procedure-documentation (lambda (x) "Identity" x)) ⇒ "Identity"
(define (square x)
    "Return the square of X."
    (* x x))
⇒ #<unspecified>
(procedure-documentation square) ⇒ "Return the square of X."
Function: comment string1 …

Appends string1 … to the strings given as arguments to previous calls comment.

Function: comment

Returns the (appended) strings given as arguments to previous calls comment and empties the current string collection.

Load syntax: #;text-till-end-of-line

Behaves as (comment "text-till-end-of-line").


4.8.4 Modifying Read Syntax

Callback procedure: read:sharp c port

If a # followed by a character (for a non-standard syntax) is encountered by read, read will call the value of the symbol read:sharp with arguments the character and the port being read from. The value returned by this function will be the value of read for this expression unless the function returns #<unspecified> in which case the expression will be treated as whitespace. #<unspecified> is the value returned by the expression (if #f #f).

Callback procedure: load:sharp c port

Dispatches like read:sharp, but only during loads. The read-syntaxes handled by load:sharp are a superset of those handled by read:sharp. load:sharp calls read:sharp if none of its syntaxes match c.

Callback procedure: char:sharp token

If the sequence #\ followed by a non-standard character name is encountered by read, read will call the value of the symbol char:sharp with the token (a string of length at least two) as argument. If the value returned is a character, then that will be the value of read for this expression, otherwise an error will be signaled.

Note When adding new # syntaxes, have your code save the previous value of load:sharp, read:sharp, or char:sharp when defining it. Call this saved value if an invocation’s syntax is not recognized. This will allow #+, #-, and Uniform Arrays to still be supported (as they dispatch from read:sharp).


Next: , Previous: , Up: The Language   [Contents][Index]