Differences between revisions 2 and 6 (spanning 4 versions)
Revision 2 as of 2006-01-18 17:09:14
Size: 1086
Editor: velociraptor
Comment:
Revision 6 as of 2006-01-18 17:43:42
Size: 3164
Editor: velociraptor
Comment:
Deletions are marked like this. Additions are marked like this.
Line 5: Line 5:
|| setf |||| (setf <name> <list>) creates a set called <name> that has the value <list> |||| (setf friends '(Dan Randy)) || || setf |||| (setf [<name> <list>]*) is an assignment of <list> to <name> |||| (setf friends '(Dan Randy) enemies '(Satan)) ||
Line 10: Line 10:
|| CARs CDRs |||| CAR == first, CDR == rest. Add a's or d's to string them to gether CADR == first rest |||| (CADR '(A B C)) --> B ||
|| True and False |||| T and NIL |||| ||
|| CONS |||| (CONS <exp> <list>) --> LIST == (exp list[1] ... list[n]) that is the contents of the list |||| (CONS 'a '(b c)) --> (a b c) ||
|| APPEND |||| (APPEND list list*) --> (content contents1 ... contentsn) |||| (append '(a b c) '(a e f)) --> (a b c a e f) ||
|| LIST |||| (LIST <exp>*) --> (exp1 ... expn) |||| (LIST 'a 'b 'c) --> (a b c) ||
|| NTHCDR |||| (NTHCDR <number> <list>) trims off the first <number> items from the list and returns the rest |||| (NTHCDR 2 '(a b c)) --> (c) ||
|| BUTLAST |||| (BUTLAST <number> <list>) trims off the last <number> itmes from the list and returns the rest |||| (BUTLAST 2 '(a b c)) --> (a) ||
|| LAST |||| (LAST <list>) --> (last-element) as a list |||| (LAST '(a b c)) --> (c) ||
|| LENGTH |||| (LENGTH <list>) --> number of items in the list |||| (LENGTH '(a b c)) --> 3 ||
|| REVERSE |||| (REVERSE <list>) --> reverses the order of the list |||| (REVERSE '(a b c)) --> (c b a) ||
|| Association list / a-list |||| A list of sublists where the first element in each sublist is used as a key for recovering the entire list. |||| (setf Patti '((height 5-10) (weight 124))) where height and weight are the keys ||
|| ASSOC |||| Is a way to access a-lists (ASSOC <key> <a-list>) |||| (ASSOC 'weight Patti) --> 124 ||
|| FLOAT |||| Forces a float result (FLOAT <exp>) --> float-value |||| (float (/ 22 7)) --> 3.14286 vs. (/ 22 7) --> 22/7 which is a ratio ||
|| ROUND |||| (ROUND <exp>) --> int remainder |||| (round (/ 22 7)) --> 3 1/7 ||
|| MAX |||| (MAX <list>) --> max element in list |||| (max '(1 2 3)) --> 3 ||
|| MIN |||| (MIN <list>) --> min element in list |||| similar ||
|| EXPT |||| Stand for exponent (expt number1 number2) --> number1^number2 |||| (expt 2 3) --> 8 ||
Line 13: Line 31:
                     |Number
                     |



                               |Integer
                               |
                     |Number---|Ratio
                     | |
                     | |Floating Point

Term

Definition

Example

Atoms

Like types: the fundamental items formed from bits

27, 3.14, This-Phrase

Lists

Sentence like objects containing atoms or other lists.

'(this that the other thing)

Symbolic expressions / or [s-]expressions

Atoms and lists collectively are called expressions.

setf

(setf [<name> <list>]*) is an assignment of <list> to <name>

(setf friends '(Dan Randy) enemies '(Satan))

Data Types

See Figure 1

FIRST

(FIRST LIST) returns the first expression in the list

(FIRST (A B C)) --> A

REST

(REST LIST) returns the expression after the first element of the list as a list

(REST (A B C)) --> (B C)

QUOTE

'(I J) will return a list with the elements I and J without trying to interpret I as a function

'(A B C) --> (A B C)

CARs CDRs

CAR == first, CDR == rest. Add a's or d's to string them to gether CADR == first rest

(CADR '(A B C)) --> B

True and False

T and NIL

CONS

(CONS <exp> <list>) --> LIST == (exp list[1] ... list[n]) that is the contents of the list

(CONS 'a '(b c)) --> (a b c)

APPEND

(APPEND list list*) --> (content contents1 ... contentsn)

(append '(a b c) '(a e f)) --> (a b c a e f)

LIST

(LIST <exp>*) --> (exp1 ... expn)

(LIST 'a 'b 'c) --> (a b c)

NTHCDR

(NTHCDR <number> <list>) trims off the first <number> items from the list and returns the rest

(NTHCDR 2 '(a b c)) --> (c)

BUTLAST

(BUTLAST <number> <list>) trims off the last <number> itmes from the list and returns the rest

(BUTLAST 2 '(a b c)) --> (a)

LAST

(LAST <list>) --> (last-element) as a list

(LAST '(a b c)) --> (c)

LENGTH

(LENGTH <list>) --> number of items in the list

(LENGTH '(a b c)) --> 3

REVERSE

(REVERSE <list>) --> reverses the order of the list

(REVERSE '(a b c)) --> (c b a)

Association list / a-list

A list of sublists where the first element in each sublist is used as a key for recovering the entire list.

(setf Patti '((height 5-10) (weight 124))) where height and weight are the keys

ASSOC

Is a way to access a-lists (ASSOC <key> <a-list>)

(ASSOC 'weight Patti) --> 124

FLOAT

Forces a float result (FLOAT <exp>) --> float-value

(float (/ 22 7)) --> 3.14286 vs. (/ 22 7) --> 22/7 which is a ratio

ROUND

(ROUND <exp>) --> int remainder

(round (/ 22 7)) --> 3 1/7

MAX

(MAX <list>) --> max element in list

(max '(1 2 3)) --> 3

MIN

(MIN <list>) --> min element in list

similar

EXPT

Stand for exponent (expt number1 number2) --> number1^number2

(expt 2 3) --> 8

                               |Integer
                               |
                     |Number---|Ratio 
                     |         |
                     |         |Floating Point
             |Atom---|
             |       |
Expressions -|       |Symbol
             |
             |LIST

Figure 1

LispNotes (last edited 2006-01-18 19:29:29 by velociraptor)