CS 3723/3721
|
Lisp is an interpreted language, and as such it has flexibility and power not available to traditional compiled languages such as C, C++, or Java. In Lisp more decisions are made at run-time. In exchange for this flexibility and power, Lisp execution has always been much slower than the traditional languages. Modern Lisp systems have a compiler that improves performance considerably, though not to the level of traditional languages.
% lisp > 12 12 > (dribble 'file.out) ; turn on logging ;;; Dribble file "FILE.OUT" started T > (+ 3 4 ) 7 > (dribble) ; turn off logging ;;; Dribble file "FILE.OUT" finished T > (quit) % cat FILE.OUT ;;; Dribble file "FILE.OUT" started T > (+ 3 4 ) 7 > (dribble) ;;; Dribble file "FILE.OUT" finished
> 47 ;;; integer constant 47 > "Lisp" ;;; string constant "Lisp" > -.34e-2 ;;; float constant -0.0034 > t ;;; this is true in Lisp T > nil ;;; this is false NIL > () ;;; this is also false NIL > (equal () nil) ;;; they are equal! T
> (+ 8 5) 13 > (/ 355 113) 355/113 > (/ 355.0 113.0) ;;; clisp 3.141593 > (/ 355.0 113.0) ;;; gcl 3.1415929203539825
> (* (+ (* 5 4) (/ -4 2) ) 37) 666 > (+ (* 2 2) (* 3 3) (* 5 5) (* 7 7) (* 11 11) ;;; continue to next line (* 13 13) (* 17 17)) ;;; last ')' completes the S-expression 666
> (setq x (+ 7 40)) 47 > (+ 14 x) 61 > x 47 > y Error: The variable Y is unbound.
> (quote (a b c)) (A B C) > '(a b c) (A B C) > (a b c) Error: The function A is undefined.
> (car '(a b c)) ;;; first element is a A > (cdr '(a b c)) ;;; rest of list is (b c) (B C) > (car (cdr '(a b))) ;;; cdr gives (b), and car of that is b B > (car (a b c)) ;;; lisp tries to evaluate (a b c) Error: The function A is undefined.
> (cons 'a '(b c)) (A B C) > (cons (car '(a b c)) (cdr '(a b c))) (A B C)
+ - * / 1+ gcd lcm acos asin
atan cos cosh sin tan
abs ceiling exp floor log max min mod round sqrt
evenp minusp oddp plusp zerop
= /= < > <= >=
first (same as car) second third fourth ...
last rest (same as cdr)
caar cadr cdar cddr ... append list
member atom listp null eq eql equal numberp
(cond (pred1 result1) (pred2 result2) ... (t default))
Here predi is a predicate. If pred1 is true, the value of the cond is result1, and no more of the cond is evaluated. Otherwise if pred2 is true, the value of the cond is result2, and no more of the cond is evaluated, and so forth. If none of the predicates is true, then the value will be default.
(defun fname (v1 v2 ... vn) ;; body of function (sequence of S-expressions) ;; value of last one is value returned )
(fname arg1 arg2 ... argn)