Tip:
Highlight text to annotate it
X
At best, you get a feeling for the language, if it is used.
Therefore we start the free program "clisp".
You will see a greeting and a prompt.
First, let us deal with data types.
We'll start with numbers and simply enter just a '5'.
Entered 5 is recognized as a 5. :-)
What if we type a letter, eg 'k'?
Uppps! A fix appears ...
LISP recognizes this obviously as variable.
But that was not our desire!
So, we exit the troubleshooting dialog...
We start another attempt,
this time with quotes around the 'k'.
Hooray, it worked! :-)
But is that really for LISP the data type that we wanted?
How do we know what the printed means internal for LISP now?
The function "type-of" tells us the data type of an object.
So we have a STRING (chars).
And the number 5 is actually a number,
specifically a INTEGER (no decimal places).
LISP has a concept of symbols. Symbols are names for objects.
The apostrophe ' is the quoting character in LISP.
Then the following code is not evaluated.
A quoteted letter is evaluated as symbol.
An symbol may also be a word.
A symbol can name a variable and a function.
Depending on the context LISP then recognizes what names a symbol.
'k' is alone (without quoting) interpreted as a variable,
and has still get no value like LISP tells us now.
These were all simple data types (scalar / atomic).
LISP comes from "LISt Processing".
What is a list, and how we enter it?
A list is a "container" for different data types.
First we enter only an empty list.
The apostrophe tells LISP, not the list to evaluate as a function.
An empty list, we can write without apostrophe, too.
'NIL' is a symbol meaning "empty" / "nothing" or "wrong."
A list of data content should not be written this way...
LISP otherwise wants to run it as a function,
and the function '6' does not exist.
So once again, but this time with high-line (quoting)!
So we can fill the list with elements of any type
and any number of objects.
Note, incidentally,
k is not the same as "k"!
k is a symbol,
"K" is just text (STRING)!
We let ourselves confirm the data type of this list.
Ohh, what is 'CONS'?
This is the designation for a 2-element Object ("Cell").
It comes from 'Construct' and is the basic component of lists.
A CONS can be created with the command 'CONS'.
Note the point between 6 and 8.
It features a pair of two objects (numbers here).
Is the second object a pointer to a other CONS,
then you have a list!
A CONS is always composed of two parts!
A multi-part list consists only of 2 elements:
from an atomic value and ...
a list of the rest of the values.
We are treating that deeper later.
The function 'list' generates directly a list built with CONS's.
We can immediately enter any number of values.
And as we see in confirmation, it is also a CONS list!
Let's look at the list ...
We see no points between the values.
Because it has been connected CONS with pointers to a list!
So far we have generated much data
but we had to re-enter each time.
LISP can save us the values also.
For this we use the symbol to name variables.
Beautiful, 'm' now saves our number '8 '.
And 'k'?
Still has no value!
We assign 'k' the value of 'm'.
Works! ^ ^
'k' and 'm' are variable with integer numbers as content.
Of course, we can 'k' also re-assign a new value.
The variable values we see by entering its symbol name.
LISP evidence that the symbols 'k' and 'm', without parenthesis, are seen as variables.
So, we do it for today ...
Those who want can think what kind of data type the quoted 'm' has. Is that easy? ^ ^
I look forward to the next time when you came back since!
You are welcome to tell me suggestions, bugs or feature requests! :-)
Thanks for your attention! Greetings from Markus. :-)