Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.
- (defun fetch (key alist)
- (cond ((null alist) '?)
- ((equal (caar alist) key) (cadar alist))
- (t (fetch key (cdr alist)))))
- (print (fetch '(denisa misa) '((ana bana) (dana ioana) ((denisa misa) (boma toma)) (ionela ina))))
- 2.
- (defun list-keys (alist)
- (cond ((null alist) '())
- ((atom (caar alist)) (append (list (caar alist)) (list-keys (cdr alist))))
- (t (append (list-keys (car alist)) (list-keys (cdr alist))))))
- (print (list-keys '(((marius 1) (nadina 2)) (george 1))))
- 3.
- (setf (get 'toma 'dad) 'marius)
- (setf (get 'daniel 'dad) 'marian)
- (setf (get 'marius 'dad) 'adrian)
- (setf (get 'adrian 'dad) 'alex)
- (setf (get 'alex 'dad) 'darius)
- (defun grandpa (sym) (get (get sym 'dad) 'dad))
- (print (grandpa 'toma))
- 4.
- (defun adam (sym)
- (cond ((null (get (get sym 'dad) 'dad)) (get sym 'dad))
- (t (adam (get sym 'dad)))))
- (print (adam 'toma))
- 5.
- (defun mom (sym) (get sym 'mom))
- (defun dad (sym) (get sym 'dad))
- (defun ancestors (sym) (cond ((null sym) nil)
- (t (append (list sym) (ancestors (mom sym)) (ancestors (dad sym))))))
- (print (ancestors 'ana))
- 6.
- (defun list-to-array (l)
- (make-array (list (length l)
- (length (car l)))
- :initial-contents l))
- (print-array (list-to-array (list (list 0 0 0 ) (list 0 0 0) (list 0 0 0))))
- OR
- (setq m (make-array '(3 3) :initial-contents '((0 1 2 ) (3 4 5) (6 7 8))))
- (setq space '| |)
- (defun print-matrix (m)
- (do ((i 0 (+ 1 i)))
- ((= i (array-dimension m 0)) t)
- (do ((j 0 (+ j 1)))
- ((= j (array-dimension m 1)) )
- (prin1 (aref m i j))
- (princ space))
- (terpri)))
- (print-matrix m)
- 7.
- (defun find-dim2 (l)
- (cond ((null l) 0)
- ((atom l) 1)
- (t (apply '+ (mapcar 'find-dim2 (car l))))))
- (defun find-dim1 (l)
- (do ((i 0 (+ i 1)))
- ((null l) i)
- (setq l (cdr l))))
- (setq l '((1 2) (3 4) (5 6)))
- (defun make-matrix (l)
- (setq a (find-dim1 l))
- (setq b (find-dim2 l))
- (setq dim (list (find-dim1 l) (find-dim2 l)))
- (setq m (make-array dim))
- (do ((i 0 (+ i 1))
- (p (car l) (car l)))
- ((= i a) m)
- (do ((j 0 (+ j 1)))
- ((= j b))
- (setf (aref m i j) (car p))
- (setq p (cdr p)))
- (setq l (cdr l))))
- (print-matrix (make-matrix l))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement