;;NOTIUNI DE BAZA pi 16 1.25 a ;unbound variable "Sir de caractere" () (a b c) (a (b (c))) (+ 1 2 3) (aceasta este o lista) ;;CONSTANTE t nil () ;;;; Calcul factorial ;;; (defun fact (n) ;; consitaia de oprire (if (zerop n) 1 ; 1<--(fact 0) ;;apel recursiv (* n (fact (- n 1))) ) ) ;;FUNCTII (+ 1 2 3) (* (+ 2 3) 10) (sqrt 4) (sqrt 3) (sqrt (sqrt 4)) (a 1 2) ; unbound function a ;;EVALUAREA (quote a) (quote (a b c)) 'a '(a b c) (eval '(+ 1 2)) (car '(+ 1 2)) (eval y) ;; x-->10, y-->x ;ATRIBUIREA SI LEGAREA VARIABILELOR (setq x 1 y '(a b c)) (setq x 1 y (+ x 2)) (setq x 10) (setq x 1 y (+ x 2)) ;;x=1, y=3 (setq x 10) (psetq x 1 y ( + x 2));;x=1 y=12 ;;OPERATII CU LISTE (car '(a b c)) (first '(a b c)) (second '(a b c d e)) (third '(a b c d e)) (4th '(a b c d e)) (car '((a (b c)) d ((e f) g) h)) (car 'a) (cdr '(a b c)) (cdr '((a (b c)) d ((e f) g) h)) (cdr 'a) (rest '(a b c)) (cons 'a '(b c)) (cons '(a) '(b c)) (cons 1 nil) (cons nil nil) (cons 1 2) (cons '(a b) 'c) (setq l '(a b c) (cons (car l) (cdr l)) (append '(a) '(b c)) (append '((a) b) '(c) '(d (e f))) (append 'a '(b c)) ;;error: bad argument type - a (append '((a)) '(b c) 'd) ;; ((a) b c . d) (append) (list 1 2 3) (list '(a b) 'c '((d e) f)) (list 1 '(2 . 3)) (list nil nil) (cons '(a) '(b c)) ;;((a) b c) (append '(a) '(b c)) ;;(a b c) (list '(a) '(b c)) ;;((a) (b c)) (last '(a b c d)) (last '(a b . c)) (last (a)) (reverse '(1 2 3 4 5)) (reverse '( a (b c d) e)) (length '(a b c)) (length '((a b (c)) (d e))) (length ()) (cond ((> x 0) x) ((< x 0) (- 0 x)) (t 0) ) (defun putere (x) (* x x)) ;;(or a b) = (cond (a) (b)) ;;(and a b) = (cond (a b))