Friday, July 9, 2010

通俗Lisp雜記

等同性

  1. eq - test if two are the same object
  2. eql - test if two are of same type
  3. equal - test if two represent the same structure and contents recursively
  4. equalp - less discriminating

結構

  (defstruct person
name
age
sex)

(let ( (p (make-person
:name "Kevin"
:age 20
:sex "Male")) )
(person-name p) ;; Kevin
(person-age p) ;; 20
(person-sex p) ;; Male
)

變數

  1. use defparameter or defvar to set global variable
  2. setq - set quoted blah
  3. setf - set a field
  4. use let or let* to create local scope and local variables
  5. use flet to create local function and local scope

串列操作

  1. basic: cons, car & cdr
  2. nth - get nth element
  3. push

No comments:

Post a Comment