------------------------------------------------------------------------------
MC logo
Talking to Tom's Lisp
[^] Tom's Lisp
------------------------------------------------------------------------------
[Basic Input Format] [Lists, Pairs and Related Operations] [Conditional Evaluation] [Basic Function Definition] [Definitions and Scope] [Functions Which Take Functions] [String Functions] [Exception Handling] [Quoting And Evaluation] [Variable-Length Parameter Lists] [Macro Definitions] [Printing] [The Tomslsp command and its switches] [Index of Standard Functions]

To run the Tom's Lisp interpreter, give the command tomslsp. You will get a prompt. You may type Tom's Lisp expressions at the prompt, and it will evaluate them and return the result. For instance:

[tom@tomslap ~]$ tomslsp
Welcome to Tom's Lisp 0.95.  Recur well.
lsp>68
68
lsp>"Hi there"
"Hi there"
In this example, we simply entered an integer constant, found out that, remarkably, it evaluates to itself. The same with a string constant.

If you want to actually compute something, you must call a function. The Lisp syntax for this is a list, surrounded by parens, but not separated by commas. The first item is the operation, and the rest are the arguments. When it is evaluated, the function is called and sent the arguments. For instance, a little arithmetic:

lsp>(+ 5 9)
14
lsp>(- 10 (* 3 2))
4
lsp>(+ 4 2 11 (/ 5 2) (* 3 (- 5 3)))
25
lsp>(+ (* 3 (/ 10 3)) (% 10 3))
10
As you can see, the argument to a function can be the result of another function. All calls take the same form.

The +, -, *, / and % operators represent addition, subtraction, multiplication, division, and modulus, as you would expect. Addition and multiplication can be given any number of arguments, while the others must have exactly two.

Tom's lisp has integers, but no floating point numbers. Unlike most production Lisps, the integers are not of unbounded length, but are the ints of the C++ compiler that compiled Tom's Lisp. Usually 32 bits. Of course, division produces an integer without a fractional part.

Though string handling is not a strength of Tom's Lisp, it does have some basic operations:

lsp>(concat (substr "Fred is dead" 0 5) "lives!")
"Fred lives!"
(see String Functions.)

Another basic data item is the identifier. Identifiers are a bit trickier since they do not express their own value. While 17 is always 17, identifiers must have values assigned. Evaluating an identifier which has not been assigned is an error.

lsp>17
17
lsp>'17
17
lsp>fred
**** Error 1: Undefined fred ****
lsp>'fred
fred
The tick character (') causes the next item to be quoted. That means evaluation is suppressed, and the value is whatever you typed in. In the case of an integer, the tick makes little difference, because an integer evaluates to itself. The identifier fred has not been given a value, so its evaluation fails. (If you would like to give it a value, see the definitions page.)

Here's another:

lsp>'(+ 5 6)
(+ 5 6)
Same idea: the quote prevents the evaluation, which would add the 5 and 6. Instead, you get what you typed, which is a list. (More on those soon.)

Tom's Lisp, like most lisps, is fairly free about what characters may be part of an identifier. In Tom's Lisp, an identifier may contain any non-space character except (, ), ;, ., ' or ", and must contain at least one non-digit, though it can be anywhere.

lsp>'($%&^--_+=   999-333)
($%&^--_+= 999-333)

If for some peculiar reason you want to end your Tom's Lisp section, you can give keyboard EOF (generally ^D on Unix or ^Z in a DOS shell), or issue the (quit) command. It's a zero-argument Lisp function call, and you must type the parentheses. You can also use (exit n), where n is an integer, and invokes the C exit function with the indicated value.