LISP Tutorial
By
Marc Schwarz
From the Forthcoming Text
Natural Language Computing Workbook
By
Ray C. Dougherty and Marc Schwarz
This web site is best viewed using Netscape Navigator 2.0 or later, and when your web browser's width is set to these dimensions
Return to NYU Natural Language Computing Project Online Tutorials
Return to NYU Natural Language Computing Project
Return to Research at NYU Linguistics
Table of Contents
I. LISP Fundamentals
1.0 Introduction
I. LISP Fundamentals
1.2 Resetting The Interpreter
User-defined Commands
Defun takes the form: (defun ProcedureName(Optional-Input-Variable-Seq) Procedure-Body).The procedure being defined in the above diagram is called, Trite. The Trite procedure takes 1 variable as input, and that variable has the name h. The (Optional-Input-Variable-Seq) sequence that immediately follows the ProcedureName is a list of zero or more atoms and/or lists. The entire procedure is itself a list; this is true for all legally formed procedures in LISP. Because procedures are themselves lists, they can be used as inputs into other procedures.
The standard format for an IF statement is: (if TEST Do_if_Test_Result_Not_NIL Do_if_Test_Result_Is_NIL)An If does the following: The TEST is first evaluated. If the value returned is not NIL, then Do_if_Test_Result_Not_NIL is evaluated. Otherwise, Do_if_Test_Result_Is_NIL is evaluated. If no explicit Do_if_Test_Result_Is_NIL is defined, then the system will return the value '() as its Do_if_Test_Result_Is_NIL.
|
> (ConjTest 'every) |
The standard format for a Let* is:
(let* ( (Name1 (evaluateable-S-Expression1)) ...
(NameN (evaluateable-S-ExpressionN))) Procedure-Body )
A Let* is always defined within the context of a procedure. The
variable Name1 here takes the value returned by an evaluation of
(evaluateable-S-Expression1). Name1 may then be used in place of
(evaluateable-S-Expression1) in the procedure body.
|
> (ConjTestII
'every) |
The standard syntax for setq is: (setq Name Input-Form)
> (setq nouns '(boy girl dog tree
lake)) |
(cond ((TEST1) (Do-if-TEST1-is-TRUE))
((TEST2) (Do-if-TEST2-is-TRUE))
((TEST3) (Do-if-TEST3-is-TRUE)) ...
((TEST_N) (Do-if-TEST_N-is-TRUE))
(t (Do-if-TEST1-to-TEST_N-are-FALSE)))
;;; left-hand-side right-hand-side
A cond clause is evaluated in a two-part process. Step One involves
evaluating a left-hand-side test clause, beginning from TEST1. The tests
are evaluated in order, until the system finds a test-clause that returns
the boolean value, TRUE. Step Two occurs once such a clause is identified.
At this point, the system evaluates the (Do-if-TEST*-is-TRUE)
right-hand-side that corresponds to the identified true test-clause. Once
a right-hand-side is evaluated, the system then exits the cond clause. If
none of the tests returns a true value, the system will return a cond
out-of-bounds error and halt all processing. To remedy this, it is
standard coding practice to include a TRUE-statement as the final test
condition on the left-hand-side. Cond If TEST1-is-TRUE THEN Do-THIS Else
If TEST2-is-TRUE THEN Do-THAT Else
If TEST_N-is-TRUE THEN Do-THE-OTHER-THING Else
TRUE THEN Do-SOMETHING-COMPLETELY-DIFFERENT
|
> (WordClass
'and) |
> (cons 'a '(1 2 3)) |
> (append '(a b) '(1 2 3)) |
|
> (Sans '1 '(1 2 3)) |
The remaining pages of this web site are best viewed when your web browser's width is set equal to that of the following violet bar:
Before continuing on to another page at this web site, please go to the OPTIONS or PREFERENCES on your browser's Menu, and modify the settings until your display's right edge is flush with the bar immediately above this paragraph.
Suggested Next Link: Sample LISP Programs
© Copyright 1996 Marc Schwarz & Ray C. Dougherty.
All Rights Reserved.
This document may be distributed for non-commercial use on the condition that it will be distributed intact, unaltered, and that any and all such distributions will include this copyright notice. All other uses of this document, including the use of it's design/concept, without the expressed and prior written consent of the authors is prohibited.