lisp

Páginas: 2 (357 palabras) Publicado: 18 de septiembre de 2014
FUNCIONES LISP

1. (CONS X Y)
CL-USER 1 > (cons 'p 'q)
(P . Q)
CL-USER 2 > (cons 'p '(q r))
(P Q R)
CL-USER 3 > (cons 'p (cons 'q (cons 'r())))
(P Q R)2. (LIST X-1 .. X-N)
CL-USER 1 > (list 'p 'q 'r)
(P Q R)
CL-USER 2 > (list '(p q) '(r s))
((P Q) (R S))
CL-USER 3 > (list)
NIL

3. (APPEND L-1 … L-N)
CL-USER 1> (append '(p) '(q) '(r s) '(t u))
(P Q R S T U)

4. (ATOM x): Devuelve T si es átomo y NIL si no lo es.
CL-USER 7 > (atom 'a)
T
CL-USER 8 > (atom '(1 2))
NIL5. (CONSP x): Devuelve T si es una lista no vacía y NIL si no lo es.
CL-USER 1 > (consp '(a b))
T
CL-USER 2 > (consp nil)
NIL
CL-USER 3 > (consp '())
NIL6. (NULL x): Devuelve T si es una lista vacía y NIL si no lo es.
CL-USER 1 > (null '(a b c))
NIL
7. (AND x y)
CL-USER 1 > setq x 3
3
CL-USER 2 > setq y 88
CL-USER 3 > (and (= x 3) (= y 8))
T
CL-USER 4 > (and (= x 1) (= y 8))
NIL

8. IF:
Sintaxis: IF
Ejemplos:
CL-USER 1 > setq x 6
6CL-USER 2 > setq y 8
8
CL-USER 3 > if (= x 6) 1 0
1
CL-USER 4 > if (= y 2) 1 0
0
CL-USER 5 > if (= x 6) (+ x 1)
7
CL-USER 6 > if (= y 3) (+ y 2)
NIL
CL-USER 7 >if (= x 4) (+ x 5) (- y 3)
5

9. COND:
Sintaxis: COND …
Ejemplo:
CL-USER 1 > Defun eliminar (x lista) (cond ((endp lista) lista) ((equal x (carlista)) (cdr lista)) (T (cons (car lista) (eliminar x (cdr lista))))))
ELIMINAR
CL-USER 2 > eliminar 5 '(1 2 5)
(1 2)

10. DEFUN:
Sintaxis: DEFUN (parametro1, param2,…, param n) “comentarios” (cuerpo))
Ejemplo:
CL-USER 11 > defun cubo(x) "Cubo de un número" (* x x x)
CUBO
CL-USER 12 > cubo 3
27
CL-USER 13 > cubo 5
125
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • lisp
  • Lisp
  • lisp
  • lisp dicertacion
  • programación Lisp
  • Examen LISP
  • ejercicios de lisp
  • Programación con lisp

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS