(prog1 calcolo fattoriale
;fact.mar
;modificato da EXAMPLES:FACT.Lisp
(print"")

(defun fact(n) (cond ((eq n 0) 1)
                     (t (* n (fact (- n 1))))))
(print(fact 5))
(terpri)
(print(fact 6))
(terpri)
)

;gestione FUNZIONI
? ;per definire una funzione si deve fornire NOME ARGOMENTI
? ;ISTRUZIONI da eseguire VALORE da ritornare
? ;utile inserire una STRINGA DOCUMENTAZIONE per spiegare funzione
? ;---------------------------------------------------------------
? (defun ultimo(x)
"ritorna ultimo elemento di lista da fornire in input"
(car(reverse x)))
ULTIMO
? (ultimo'(a b c d))
D
? ;-------------------------------------------------------------
? (ultimo '(a b(c d)(e f g)))
(E F G)
? ;-------------------------------------------------------------
? (defun somma (x y z)(+ x y z))
SOMMA
4 (somma '1 '2 '3)
6
5 > (print(somma '10 '20 '30))

60 
60
5 > ;---------------------------------------
5 >(defun cubo(x)(print(* x x x)))
CUBO
7 > (cubo '2)

8 
8
7 > ;----------funzione1.lisp-----------------------------
7 > 

;esempio di ramificazioni con IF..THEN..ELSE...WHEN...UNLESS..COND
7 > ;--------------------------------------------------------------
7 > (if(eq '4 '4)(print 'vero)(print 'falso))

VERO 
VERO
7 > (if(eq '4 '5)(print 'vero)(print 'falso))

FALSO 
FALSO
7 > (if(eq '4 '5)(print 'vero))
NIL
7 >;---------------------------------------------------
8 > (when(eq '4 '4)(print 'vero)(print 'esatto)(print 'fine))

VERO 
ESATTO 
FINE 
FINE
8 > (when(eq '4 '5)(print 'vero)(print 'esatto)(print 'fine))
NIL
8 > ;--------------------------------------------------------
8 > (unless(eq '4 '4)(print 'vero)(print 'esatto)(print 'fine))
NIL
8 > (unless(eq '4 '5)(print 'vero)(print 'esatto)(print 'fine))

VERO 
ESATTO 
FINE 
FINE
8 > ;----------------------------------------------------------
8 > (cond((eq '4 '4)(print 'vero)(print 'esatto))
    ((eq '4 '5)(print 'errato)(print 'falso)))

VERO 
ESATTO 
ESATTO
8 > (cond((eq '4 '5)(print 'vero)(print 'esatto))
    ((eq '3 '3)(print 'esatto)(print 'vero)))

ESATTO 
VERO 
VERO
8 > (cond((eq '4 '5)(print 'veroprimo))
    ((eq '3 '6)(print 'verosecondo))
     ((eq '7 '7)(print 'veroterzo)))

VEROTERZO 
VEROTERZO
8 > (cond((eq '4 '5)(print 'veroprimo))
     ((eq '3 '6)(print 'verosecondo))
      ((eq '7 '8)(print 'veroterzo)))
NIL
8 > ;----------------funzione2.lisp----------------------
8 > 

ritorna