Documentos de Académico
Documentos de Profesional
Documentos de Cultura
USER(3): (double 3)
Recursividad
(defun factorial (N)
Factorial de N."
(if (= N 1)
1
(* N (factorial (- N 1)))))
Operadores relacionales
(= x y)
(/= x y)
(< x y)
(> x y)
(<= x y)
(>= x y)
Recursividad mltiple
(defun fibonacci (N)
"N numero de Fibonacci."
(if (or (zerop N) (= N 1))
1
(+ (fibonacci (- N 1)) (fibonacci (- N 2)))))
Zerop es un predicado.
Operadores lgicos y funciones predefinidas
(1+ x) (+ x 1)
(1- x) (- x 1)
(zerop x) (= x 0)
(plusp x) (> x 0)
(minusp x) (< x 0)
(evenp x) (= (rem x 2) 0)
(oddp x) (/= (rem x 2) 0)
Constructor
Selector
Reconocedor
Constructores
Nil
(cons x L)
(quote (2 3 5 7 11 13 17 19))
'(2 3 5 7 11 13 17 19)
Selectores
(first '(2 4 8))
(if (null L)
0
(1+ (recursive-list-length (rest L)))))
USER(40): (trace recursive-list-length)
(RECURSIVE-LIST-LENGTH)
USER(41): (recursive-list-length '(2 3 5 7 11 13 17 19))
0: (RECURSIVE-LIST-LENGTH (2 3 5 7 11 13 17 19))
1: (RECURSIVE-LIST-LENGTH (3 5 7 11 13 17 19))
2: (RECURSIVE-LIST-LENGTH (5 7 11 13 17 19))
3: (RECURSIVE-LIST-LENGTH (7 11 13 17 19))
4: (RECURSIVE-LIST-LENGTH (11 13 17 19))
5: (RECURSIVE-LIST-LENGTH (13 17 19))
6: (RECURSIVE-LIST-LENGTH (17 19))
7: (RECURSIVE-LIST-LENGTH (19))
8: (RECURSIVE-LIST-LENGTH NIL)
8: returned 0
7: returned 1
6: returned 2
5: returned 3
4: returned 4
3: returned 5
2: returned 6
1: returned 7
0: returned 8
8
Smbolos
No diferencia maysculas y minsculas
`t = t
Ensimo
USER(59): (nth 0 '(a b c d))
A
USER(60): (nth 2 '(a b c d))
C
Member
USER(64): (member 'b '(hola)) ;
NIL
USER(65): (member y '( y hola)) ;
(y hola)
(= x y)
(eq x y)
(eql x y)
(equal x y)
(equalp x y)
Reverse L
USER(1): (reverse '(1 2 3 4))
(4 3 2 1)
USER(2): (reverse '(1 (a b) (c d) 4))
(4 (c d) (a b) 1)
USER(3): (reverse nil)
NIL
Estado del programa, variables.
(defparameter * contador * 0)
(defparameter *umbral* 4)
(defun contador ()
(if (>= (1+ *contador*) * umbral *)
(setf * contador * 0)
(setf * contador * (1+ * contador *))))
(defun valor ()
*counter*)
(defun valorumbral ()
*umbral*)