S-expression - Use in Lisp

Use in Lisp

When representing source code in Lisp, the first element of an S-expression is commonly an operator or function name and any remaining elements are treated as arguments. This is called "prefix notation" or "Cambridge Polish notation". As an example, the Boolean expression written 4 == (2 + 2) in C is represented as (= 4 (+ 2 2)) in Lisp's s-expr-based prefix notation.

As noted above, the precise definition of "atom" varies across LISP-like languages. A quoted string can typically contain anything but a quote, while an unquoted identifier atom can typically contain anything but quote, whitespace characters, parenthesis, brackets, braces, backslash, and semicolon. In either case, a prohibited character can typically be included by escaping it with a preceding backslash. Unicode support varies.

The recursive case of the s-expr definition is traditionally implemented using cons cells.

S-expressions were originally intended only for data to be manipulated by M-expressions, but the first implementation of Lisp was an interpreter of S-expression encodings of M-expressions, and Lisp programmers soon became accustomed to using S-expressions for both code and data. This means that Lisp is homoiconic, that is, the primary representation of programs is also a data structure in a primitive type of the language itself.

Read more about this topic:  S-expression

Famous quotes containing the word lisp:

    Taught me my alphabet to say,
    To lisp my very earliest word,
    Edgar Allan Poe (1809–1849)