Advertisement
Bobita

LAB9_LISP

Apr 26th, 2023
1,572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.90 KB | Source Code | 0 0
  1. #EX_LAB9:
  2.  
  3. > (setq m (make-array '(3 2)))
  4. #2A((NIL NIL) (NIL NIL) (NIL NIL))
  5. > (setf (aref m 0 0) 1)
  6. > (setf (aref m 0 1) 2)
  7. > (setf (aref m 1 0) 3)
  8. > (setf (aref m 1 1) 4)
  9. > (setf (aref m 2 0) 5)
  10. > (setf (aref m 2 1) 6)
  11. #2A((1 2) (3 4) (5 6))
  12.  
  13. _______[#EX_1]_______:
  14.  
  15. (defmacro dotimes (variable iterator result body)
  16.    `(do ((, variable 0 (+, variable 1)))
  17.     ((=, variable, iterator), result), body)
  18. )
  19.  
  20. (defun sum (matrice)
  21.     (let((sum 0))
  22.     (dotimes i(array-dimension matrice 0)
  23.            sum(dotimes j (array-dimension matrice 1))
  24.            'd (setq sum (+ (aref matrice i j) sum))
  25.     )
  26.     )
  27. )
  28. > (suma m)
  29. 21
  30.  
  31. _______[#EX_2]_______:
  32.  
  33. (defun show (mtr)
  34.     (dotimes i (array-dimension mtr 0)
  35.     'NIL (dotimes j (array-dimension mtr 1)
  36.                     (format 't "\n")
  37.                     (format 't "~A " (aref m i j))
  38.         )
  39.     )
  40. )
  41.  
  42. _______[#EX_3]_______:
  43.  
Tags: lisp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement