Nuparu00

carthago delenda est

Nov 28th, 2021
921
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;Lecture 9
  2.  
  3. ;;1 - 20
  4.  
  5. ;;2  funcall (lambda (x) tělo) a ?? idk
  6.  
  7. ;;6
  8.  
  9. (defun accumulate (seq from to combiner null-val)
  10.   (if (< to from)
  11.       null-val
  12.     (funcall combiner
  13.              (mem seq from)
  14.              (accumulate seq (1+ from) to combiner null-val))))
  15.  
  16. (defun mem (seq index)
  17.   (funcall seq index))
  18.  
  19. (defun fib (n)
  20.   (cond ((= n 0) 0)
  21.         ((= n 1) 1)
  22.         (t (+ (fib (- n 2)) (fib (- n 1))))))
  23.  
  24. (defun mmax (seq from to)
  25.   (accumulate seq from to #'max 1))
  26.  
  27. ;;7
  28. (defun seq-to-list (seq len)
  29.   (labels ((stl (index)
  30.              (if (>= index len)
  31.                  '()
  32.                (cons (mem seq index)
  33.                      (stl (+ index 1))))))
  34.     (stl 0)))
  35.  
  36. (defun comp-seq-p (seq fun k)
  37.   (let ((list (seq-to-list seq k)))
  38.     (labels ((comp (list) (or (null list)
  39.                               (null (cdr list))
  40.                               (and (funcall fun (car list) (cadr list))
  41.                                    (comp (cdr list))))))
  42.       (comp list))))
  43.  
  44. (defun constant-seq-p (seq k)
  45.   (comp-seq-p seq #'= k))
  46.  
  47. ;;8                          
  48. (defun increasing-seq-p (seq k)
  49.   (comp-seq-p seq #'< k))
  50.                            
  51. ;;9
  52.  
  53. (defun even-members (seq)
  54.   (lambda (x) (funcall seq (* x 2))))
  55.  
  56. ;;10
  57.  
  58. (defun zero-row-p (tbl row)
  59.   (labels ((test (col) (or (> col 9)
  60.                            (and (funcall tbl row col)
  61.                                 (test (1+ col))))))
  62.     (test 0)))
  63.  
  64. ;;11
  65. (defun transpose-table (tbl)
  66.   (lambda (row col) (funcall tbl col row)))
  67.  
  68. (defun tbl-test (row col)
  69.   (* row (+ col 1)))
RAW Paste Data