25.11.2014 Views

Tema Lisp - Dpto. Ciencias de la Computación e Inteligencia Artificial.

Tema Lisp - Dpto. Ciencias de la Computación e Inteligencia Artificial.

Tema Lisp - Dpto. Ciencias de la Computación e Inteligencia Artificial.

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Introducción a <strong>Lisp</strong><br />

1<br />

1<br />

1<br />

Funciones<br />

> (<strong>de</strong>fun cuadrado (x)<br />

(* x x))<br />

CUADRADO<br />

> (cuadrado 4)<br />

16<br />

Los programas son funciones (paradigma funcional)<br />

Recursión<br />

> (<strong>de</strong>fun pertenece (x l)<br />

(if (endp l) ; caso base<br />

nil<br />

(if (= x (car l)) ; caso base<br />

l<br />

(pertenece x (cdr l))))) ; recursion<br />

PERTENECE<br />

> (pertenece 3 ’(1 4 3 5 6))<br />

(3 5 6)<br />

> (pertenece 8 ’(1 4 3 5 6))<br />

NIL<br />

IA-I 2003–2004 CcIa Introducción a <strong>Lisp</strong> <strong>Lisp</strong>.9

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!