;;simple list contains atoms '(1 2 3) ; (1 2 3) ;;substitute ' for the word quote (quote (1 2 3)) ; (1 2 3) ;;atoms can be letters too '(a b c) ; (a b c) ;;atom returns true if something is an atom (atom 2) ; t ;;check if is an atom?? or apply atom to a (atom 'a) ; t ;;atom returns false for a list (atom '(3 4 5)) ; nil (atom '(atom 'a)) ; nil (atom (atom 'a)) ; t (atom (atom '(3 4 5))) ; t ; nil (atom nil) ; t ;;comparisons ;;compare undefined variables (eq 'a 'b) ; nil ;;compare avlues (eq 1 1) ; t ; comparison of lists will not return true (see eqlist function below) (eq '(2 3) '(2 3)) ; nil ;;car = head of list ;;cdr = tail of list (car '(4 5 6)) ; 4 (cdr '(5 6 7)) ; (6 7) (cdr '( (2 3) (1 2) (5 6 7))) ; ((1 2) (5 6 7)) ;;construct list from lists (cons '2 '(3 4 5)) ; (2 3 4 5) (cons '(1 2) '(3 4 5)) ; ((1 2) ;; conditional statements (cond ( (eq 'a 'b) '3) ((eq '2 '2) '4)) ; 4 ;;returns 4 because a doesn't equal b, but 2 does equal 2 ;;if a equalled b then it would return 3 ;;define a function = defun ;;function that doubles (defun double (x) (* 2 x)) (double 3) ; 6 ;;returns true if null, false if not null (null '()) ; t (null '(1)) ; nil ;;list of atoms function (defun lat (l) (cond ((null l) t) ((atom (car l)) (lat(cdr l))) (t nil) ) ) (lat '(1 3 3 4)) ; t (lat '(1 (2 3) 4)) ; nil ;;and returns true if everything is true (and (atom 2) (atom 'a)) ; t ;;eqlist function will return true for list of atoms comparisons recursively (defun eqlist (l1 l2) (cond ( (and (null l1) (null l2)) t) ( (eq (car l1) (car l2)) (eqlist (cdr l1) (cdr l2))) (t nil) ) ) (eqlist '(1 2 3 4 5) '(1 2 3 4 5)) ; t ;;will return if an atom exists in a list (defun member2 (x l) (cond ( (null l) nil) ( (eq x (car l)) t) ( t (member2 x (cdr l))) ) ) (member2 '6 '(1 2 3 4 5)) ; nil (member2 '6 '(2 6 8)) ; t ;;not will invert true/nil statements (not (eq 2 2)) ;nil (not (eq 1 2)) ;t ;;list of non-atoms, aka list of lists (defun nonlat (l) (cond ( (null l) t) ( (not (atom (car l))) (nonlat (cdr l))) ( t nil) ) ) (nonlat '(1 2 3)) ; nil (nonlat '((2 3) 4 5 (5))) ; nil (nonlat '((2 3) (2 4))) ; t