0% found this document useful (0 votes)
46 views8 pages

TP 6 Lisp

The document demonstrates the use of basic Lisp functions like car, cdr, cons, list, append to manipulate lists. It shows how to retrieve elements from nested lists, construct new lists by prepending or appending elements, and define simple functions to test properties of lists and values. Various list operations and functions are defined and applied to example data like lists of tools, birds, and temperatures to explore their behavior.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views8 pages

TP 6 Lisp

The document demonstrates the use of basic Lisp functions like car, cdr, cons, list, append to manipulate lists. It shows how to retrieve elements from nested lists, construct new lists by prepending or appending elements, and define simple functions to test properties of lists and values. Various list operations and functions are defined and applied to example data like lists of tools, birds, and temperatures to explore their behavior.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

TP N° 6

CL-USER 1 > (setq L '(m n o p))


(M N O P)

CL-USER) 2 > (car l)


M

CL-USER 3 > (setq l'())


NIL

CL-USER 4 > (car l)


NIL

CL-USER 5 > (cdr l)


NIL

CL-USER 6 > (setq l'((a b c) x y z))


((A B C) X Y Z)

CL-USER 7 > (car l)


(A B C)

CL-USER 8 > (car l)


(A B C)

CL-USER 9 > (car (car l))


A

CL-USER 10 > (cdr (car l))


(B C)

CL-USER 11 > (cdr (cdr (car l)))


(C)

CL-USER 12 > (cdr (cdr (cdr (car l))))


NIL

CL-USER 13 > (setq l'(((a b c)) (x) (y) (z)))


(((A B C)) (X) (Y) (Z))

CL-USER 14 > (car l)


((A B C))
CL-USER 15 > (cdr l)
((X) (Y) (Z))

CL-USER 16 > (car (cdr l))


(X)

CL-USER 17 > (cdr(car l))


NIL

CL-USER 3 : 2 > (set 'aves '(loro buitre gorrión pingüino águila fénix))
(LORO BUITRE GORRIÓN PINGÜINO ÁGUILA FÉNIX)

CL-USER 4 : 2 > aves


(LORO BUITRE GORRIÓN PINGÜINO ÁGUILA FÉNIX)

CL-USER 5 : 2 > (car aves)


LORO

CL-USER 6 : 2 > (cdr aves)


(BUITRE GORRIÓN PINGÜINO ÁGUILA FÉNIX)

CL-USER 7 : 2 > (cdr (cdr aves))


(GORRIÓN PINGÜINO ÁGUILA FÉNIX)

CL-USER 8 : 2 > (car (cdr aves))


BUITRE

CL-USER 9 : 2 > (car (car aves))

Error: Cannot take CAR of LORO.


1 (abort) return to debug level 2.
2 return to debug level 1.
3 Return to top loop level 0.

Type :b for backtrace or :c <option number> to proceed.


Type :bug-form "<subject>" for a bug report template or :? for other options.

CL-USER 10 : 3 > (cdr (cdr (cdr aves)))


(PINGÜINO ÁGUILA FÉNIX)

CL-USER 11 : 3 > (cdr (car aves))


Error: Cannot take CDR of LORO.
1 (abort) return to debug level 3.
2 return to debug level 2.
3 return to debug level 1.
4 Return to top loop level 0.

Type :b for backtrace or :c <option number> to proceed.


Type :bug-form "<subject>" for a bug report template or :? for other options.

CL-USER 12 : 4 > (car (cdr aves))


BUITRE

(MANZANA NARANJA PERA FRUTILLA)

CL-USER 3 > (car (cdr (cdr l)))


PERA

((MANZANA NARANJA) (PERA FRUTILLA))

CL-USER 8 : 1 > (car (car (cdr l)))


PERA

((MANZANA NARANJA) (PERA) (FRUTILLA))

CL-USER 11 : 1 > (car (car (cdr l)))


PERA

(MANZANA (NARANJA) ((PERA)) (((FRUTILLA))))

CL-USER 14 : 1 > (car(car(car(cdr(cdr frutas)))))


PERA

((((MANZANA))) ((NARANJA)) (PERA) FRUTILLA)

CL-USER 25 : 3 > (car (car (cdr (cdr frutas))))


PERA

((((MANZANA) NARANJA) PERA) FRUTILLA)

CL-USER 18 : 1 > (car (cdr (car p)))


PERA
4

CL-USER 1 > atom 'turquia


T

CL-USER 2 > atom 1492


T

CL-USER 3 > atom '(1492turquia)


NIL

CL-USER 4 > (eql (atom 'x)(atom 'z))


T

CL-USER 5 > (setq x 2)


2

CL-USER 6 > (setq z 2)


2

CL-USER 7 > (setq x 2)


2

CL-USER 8 > eql 'x'z


NIL

CL-USER 9 > (setq H 'hola)


HOLA

CL-USER 10 > (setq p 'mundo)


MUNDO

CL-USER 11 > (cons h p)


(HOLA . MUNDO)

CL-USER 12 > cons h ' p


(HOLA . P)

CL-USER 13 > cons 'h p


(H . MUNDO)

CL-USER 14 > (cons 'pan '(con manteca y azucar))


(PAN CON MANTECA Y AZUCAR)
CL-USER 17 : 1 > (cons '(pan con manteca) '(y azucar))
((PAN CON MANTECA) Y AZUCAR)

CL-USER 1 > (defun listavacia (l) (null l))


LISTAVACIA

CL-USER 2 > setq l'()


NIL

CL-USER 3 > listavacia l


T

CL-USER 4 > (defun atomo(p)(listp p))


ATOMO

CL-USER 5 > atomo 'p


NIL

CL-USER 6 > atomo 'l


NIL

CL-USER 7 > setq aves '(loro perro)


(LORO PERRO)

CL-USER 8 > atomo aves


T

CL-USER 2 > (defun falso (p) (equal p ()))


FALSO

CL-USER 3 > falso ()


T

CL-USER 4 > falso 21


NIL

CL-USER 10 > vacio()

Error: Undefined operator NIL in form (NIL N).


CL-USER 13 : 2 > (defun falso(n)(n = nil))
FALSO

CL-USER 14 : 2 > falso ()


(defun es_nil (sujeto) (equal sujeto nil)

Error: Undefined operator N in form (N = NIL).


6

CL-USER 15 : 3 > (defun fahrenheit(X) (/(- X 32)1.8))


FAHRENHEIT

CL-USER 16 : 3 > FAHRENHEIT 2


-16.666668

CL-USER 38 : 1 > (defun cero (p) (eql p 0))


CERO

CL-USER 39 : 1 > cero 1


NIL

CL-USER 40 : 1 > cero 0


T

8
CL-USER 1 > (defun par(p) (eql (rem p 2) 0))
PAR

CL-USER 2 > par 2


T

CL-USER 3 > par 3


NIL

CL-USER 4 > par 1000


T

CL-USER 5 > par 1001


NIL

9
CL-USER 6 > (append '(a b c) '())
(A B C)

CL-USER 7 > (append '(a b c) '(a b c))


(A B C A B C)

CL-USER 8 > (list '(a b c) ' ())


((A B C) NIL)

CL-USER 9 > (list 's 'o 'p 'r 'e)


(S O P R E)

CL-USER 10 > (cons '(a b c) '())


((A B C))

10
CL-USER 1 > (setq herramientas(list'martillo'destornillador))
(MARTILLO DESTORNILLADOR)

CL-USER 3 : 1 > herramientas


(MARTILLO DESTORNILLADOR)

CL-USER 4 : 1 > cons 'pinza herramientas


(PINZA MARTILLO DESTORNILLADOR)

CL-USER 6 : 1 > setq herramientas (cons 'pinza herramientas)


(PINZA MARTILLO DESTORNILLADOR)

CL-USER 7 : 1 > herramientas


(PINZA MARTILLO DESTORNILLADOR)

CL-USER 11 : 1 > append '(llave metro) herramientas


(LLAVE ETRO PINZA MARTILLO DESTORNILLADOR)

CL-USER 12 : 1 > herramientas


(PINZA MARTILLO DESTORNILLADOR)

CL-USER 13 : 1 > (setq herramientas (append '(llave metro) herramientas))


(LLAVE METRO PINZA MARTILLO DESTORNILLADOR)

CL-USER 14 : 1 > herramientas


(LLAVE METRO PINZA MARTILLO DESTORNILLADOR)

You might also like