Eclipse C: Lisp Syntax for C Programmers


ANSI Common Lisp defines a syntax used to some extent by the function read and directly used by only four functions: compile, compile-file, load, and eval. For the most part, if you don't use these functions, you do not need to know Lisp syntax.

However, there are examples in the Eclipse and ANSI documentation which do use Lisp syntax. It may be helpful to understand the following:

  1. There are no program statements in Lisp -- only expressions which have a value.

  2. There are two kinds of expressions in Lisp:
    1. An atom, which represents a single piece of data or a reference to a variable. Examples are:
      • foo-bar -- a variable. The value of the expression is the value of the variable named foo-bar.
      • 123 -- an integer. The value of the expression is the integer 123.
      • 123.4 -- a floating point number. The value of the expression is the floating point number 123.4.
      • "a string" -- a string. The value of the expression is the string "a string".
    2. A list, which represents some operation on subexpressions. The name of the operator always appears first (consistent prefix notation, as opposed to C/C++, which uses infix for operators, prefix for functions, and postfix for C++ members). Examples are:
      • (+ 1 2) -- a function call. The value of the expression is the result of calling the function named + with the following arguments:
        • the value of the expression 1
        • the value of the expression 2
      • (+ 1 foo-bar 2 (+ 1 2)) -- a function call. The value of the expression is the result of calling the function named + with the following arguments:
        • the value of the expression 1
        • the value of the expression foo-bar (a variable, see above)
        • the value of the expression 2
        • the value of the expression (+ 1 2) (a list expression, see above)
      • (if a b (+ 1 2)) -- a special operator form. The value of the expression is the value of the expression b if the value of the expression a is true. Otherwise, the value is the value of the expression (+ 1 2).

  3. There are a very small number of built-in special operators, including if, which do not necessarily evaluate all their subexpressions. Other special operators may be defined by the standard or by users.

  4. Another important special operator is quote. The value of (quote an-expression) is simply an-expression, without evaluating it. Thus the value of (quote foo-bar) is the symbol foo-bar. (Not the value of the variable foo-bar. Compare this with the expression foo-bar by itself, above.)

    The expression (quote an-expression) occurs so often, that it has a special syntax: 'an-expression is the same thing. Thus foo-bar produces the value stored in the variable named foo-bar, while 'foo-bar produces a value which is the symbol named foo-bar.

  5. Case does not matter for operator, variable, or symbol names.

[Previous] [Next] [Up] [Documentation Contents] [Eclipse Home Page]