- Do function definitions start with a semicolon?
No, comments start with semicolons. It is a good idea to put a comment above each function definition.
- How do you use LISP?
When you start up a LISP system, it comes up in an interpreter. You give commands to the interpreter.
- How can we run a program?
To run a function interactively, type in parentheses enclosing the function name and arguments, then hit enter. The value returned will be displayed on your screen.
- Everything is in parentheses.
Yes. They all match up.
- Are any of the parentheses in gcdprint optional?.
No. All are required.
- Is recursion supported?
Yes. You can see that tail recursion (rather than a loop) is used to define gcd.
- Is cond the conditional statement?
Yes.
- Why is the gcd code indented that way?
It is customary. It helps people to read it. However, none of it is necessary; whitespace is ignored.
- Spaces are considered as separators?
Yes, spaces and parentheses.
- Lisp is not case sensitive.
I believe that is correct.
- Does it have built-in functions? Can you define functions?
Yes, yes.
- What does defun mean?
DEfine FUNction.
- Do function definitions start with a semicolon?
No, comments start with semicolons. It is a good idea to put a comment above each function definition.
- Are functions first-class objects?
Yes, No distinction is made between function and objects, and you can even write a literal function using the keyword lambda.
- How do you refer to a function (not call it)
To send a function as a parameter to another function, write a single quote before the function name: 'gcd
- Are operators, like + called "functions"?
Yes.
- Is this a prefix language?
Yes.
- Do functions have a fixed number of parameters?
Clearly, the gcd function has a fixed number, 2, of parameter NAMES, therefore, only two parameters can be USED in the code. I will find out whether multiple definitions for the same function can be given, with different numbers of parameters. The + function can accept variable-length parameter lists: (+ a 4 b c 3)
- No types are declared for the parameters..
Yes. Lisp is "untyped", but every function checks operands types at run time.
- What is parameter binding? Is it call by value or by reference?
By value. The parameter name is bound to the value of the argument expression.
- What happens to function results?
Every function has a result; it is the value of the last expression evaluated in the body of the function. Unlike FORTH, that result is not put onto a stack; it is displayed on the screen.
- What data types are supported?
Numbers, atoms, lists, string literals, and functions. There are two types of numbers: rational and real numbers. Integers are a subset of rational numbers
- Are variables declared?
No, but symbols are declared, as in Lambda Calculus. A declaration binds a symbol's name to a meaning. In "pure" lisp, that name remains bound to that meaning until the symbol goes out-of-scope.
- A distinction IS made between locals and globals, and local names must be declared and bound to a meaning.
- You can put a value in a name by either a function call or by declaring a name and initializing it. There is no direct assignment
|