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.

Funciones como argumentos <strong>de</strong> entrada: FUNCALL y APPLY<br />

1<br />

La función FUNCALL<br />

(FUNCALL FN E-1 ... E-N)<br />

(funcall #’+ 1 2 3) => 6<br />

(funcall #’cuadrado 4) => 16<br />

(funcall #’(<strong>la</strong>mbda (x) (* 2 x)) 3) => 6<br />

1<br />

La función APPLY<br />

(APPLY FN ARGS)<br />

(apply #’+ ’(1 2 3)) => 6<br />

(apply #’max ’(4 5 7)) => 7<br />

(apply #’(<strong>la</strong>mbda (x y) (* 2 x y)) ’(3 4)) => 24<br />

1<br />

Observaciones:<br />

✉<br />

El primer argumento <strong>de</strong> funcall y <strong>de</strong> apply <strong>de</strong>be ser algo cuyo valor sea una función<br />

✉<br />

Uso <strong>de</strong> #’ para forzar a obtener el valor funcional<br />

✉<br />

A veces es necesario symbol-function<br />

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

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

Saved successfully!

Ooh no, something went wrong!