.emacs-my
changeset 1018 94b0ca71a583
parent 1017 7b1ae3e0c9e3
child 1019 cbc477acb47e
equal deleted inserted replaced
1017:7b1ae3e0c9e3 1018:94b0ca71a583
    77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    78 (message "my defun, defmacro, defvar")
    78 (message "my defun, defmacro, defvar")
    79 
    79 
    80 (defmacro my-filter (pred list)
    80 (defmacro my-filter (pred list)
    81   "Construct list with elements from LIST which satisfy PRED."
    81   "Construct list with elements from LIST which satisfy PRED."
    82   `(let ( (r '(nil)) )
    82   (let ( (r (make-symbol "r_")) )
    83      (mapc (lambda (item)
    83     `(let ( (,r (list nil)) )
    84              (when (,pred item)
    84        (mapc (lambda (item)
    85                (nconc r (cons item nil))))
    85                (when (,pred item)
    86            ,list)
    86                  (nconc ,r (cons item nil))))
    87      (cdr r)))
    87              ,list)
       
    88        (cdr ,r))))
    88 
    89 
    89 (defun my-fold (f x list)
    90 (defun my-fold (f x list)
    90   "Recursively applies (F i j) to LIST starting with X.
    91   "Recursively applies (F i j) to LIST starting with X.
    91 For example, (fold F X '(1 2 3)) computes (F (F (F X 1) 2) 3)."
    92 For example, (fold F X '(1 2 3)) computes (F (F (F X 1) 2) 3)."
    92   (let ((li list) (x2 x))
    93   (let ((li list) (x2 x))