Advertisement
Tavi33

CFLP #8

Apr 15th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.65 KB | None | 0 0
  1. ;Problema [1]
  2.  
  3. (defun fetch (x lista)
  4.  
  5.     (if (assoc x lista) (cadr (assoc x lista)) (format t "Proprietatea nu exista."))
  6. )
  7. ;EXEMPLU
  8. ;> (setq x '((temp 100) (pres 80 60) (p 10)))
  9. ;((TEMP 100) (PRES 80 60) (P 10))
  10. ;> (fetch 'temp x)
  11. ;100
  12. ;> (fetch 'test x)
  13. ;Proprietatea nu exista.
  14. ;____________________________________________________________________
  15.  
  16. ;Problema [2]
  17.  
  18. (defun chei (lista)
  19.  
  20.     (do ((l lista (cdr l)) (rez nil (append rez (list (caar l)))))
  21.  
  22.         ((null l) rez)
  23.     )
  24. )
  25. ;EXEMPLU
  26. ;> (setq x '((temp 100) (pres 80 60) (p 10)))
  27. ;((TEMP 100) (PRES 80 60) (P 10))
  28. ;> (chei x)
  29. ;(TEMP PRES P)
  30. ;____________________________________________________________________
  31.  
  32. ;Problema [3]
  33.  
  34. (defun bunic (x)
  35.  
  36.     (get (get x 'tata) 'tata)
  37. )
  38. ;EXEMPLU
  39. ;> (setf (get 'a 'tata) 'b)
  40. ;B
  41. ;> (setf (get 'b 'tata) 'c)
  42. ;C
  43. ;> (bunic 'a)
  44. ;C
  45. ;____________________________________________________________________
  46.  
  47. ;Problema [4]
  48.  
  49. (defun adam (x)
  50.  
  51.     (do ((l x (get l 'tata)))
  52.  
  53.         ((null (get l 'tata)) l)
  54.  
  55.     )
  56. )
  57.  
  58. ;EXEMPLU
  59. ;> (setf (get 'a 'tata) 'b)
  60. ;B
  61. ;> (setf (get 'b 'tata) 'c)
  62. ;C
  63. ;> (adam 'a)
  64. ;C
  65. ;> (adam 'b)
  66. ;C
  67. ;____________________________________________________________________
  68.  
  69. ;Problema [5]
  70.  
  71. (defun stramosi (x lista)
  72.  
  73.     (cond
  74.  
  75.         ((not (null x)) (setq lista (append lista (list x))) (stramosi (get x 'tata) lista))
  76.         (t lista)
  77.     )
  78. )
  79.  
  80. ;____________________________________________________________________
  81.  
  82. ;Problema [6]
  83.  
  84. (defmacro define (nume param corp)
  85.  
  86.     `(defun,nume,param,corp)
  87. )
  88.  
  89. ;____________________________________________________________________
  90.  
  91. ;Problema [7]
  92.  
  93. (
  94.  
  95. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement