Changeset 6090

Show
Ignore:
Timestamp:
02/03/08 08:33:55 (5 years ago)
Author:
mokehehe
Message:

Common Lisp の関数をいくつか追加

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/c/misc/mlisp/lib.l

    r5974 r6090  
    2323(defun caar (x) (car (car x))) 
    2424(defun cdar (x) (cdr (car x))) 
     25(defun cadr (x) (car (cdr x))) 
    2526 
    2627(defun >  (x y) (< y x)) 
     
    4647        (t (+ 1 (length (cdr ls)))))) 
    4748 
     49;;; mapcar �̒l����Ȃ���= each 
     50(defun mapc (fn ls) 
     51  (cond (ls 
     52         (fn (car ls)) 
     53         (mapc fn (cdr ls))))) 
     54 
     55;;; mapcar 
    4856(defun mapcar (fn ls) 
    4957  (cond ((eq ls nil) nil) 
     
    5159                 (mapcar fn (cdr ls)))))) 
    5260 
    53  
    5461(defun zerop (x) (eq x 0)) 
    5562(defun evenp (x) (eq (% x 2) 0)) 
    5663(defun oddp  (x) (eq (% x 2) 1)) 
    5764 
    58 (defun inc (x) (+ x 1)) 
    59 (defun dec (x) (- x 1)) 
     65(defmacro incf (x n) 
     66  `(setq ,x (+ ,x n))) 
    6067 
     68(defmacro decf (x n) 
     69  `(setq ,x (- ,x n))) 
    6170 
    6271; �Q�‚̃��X�g�������(defun concat (x y) 
     
    8796                   (cond (else (list (list t else))))))) 
    8897 
     98 
     99 
     100 
     101; �R�s�[ 
     102(setq eql eq) 
     103 
     104(defun member (obj lst) 
     105  (if (null lst) 
     106      nil 
     107    (if (eql (car lst) obj) 
     108        lst 
     109      (member obj (cdr lst))))) 
     110 
     111(defun nthcdr (n lst) 
     112  (if (zerop n) 
     113      lst 
     114    (nthcdr (- n 1) (cdr lst)))) 
     115 
     116(defun nth (n lst) 
     117  (car (nthcdr n lst))) 
     118 
     119;;; let 
     120;;;  On Lisp fig 11.1 (p148) 
     121(defmacro let (binds . body) 
     122  `((lambda ,(mapcar (lambda (x) 
     123                       (if (consp x) (car x) x)) 
     124                     binds) 
     125      ,@body) 
     126    ,@(mapcar (lambda (x) 
     127                (if (consp x) (cadr x) nil)) 
     128              binds)))