diff options
| author | Mistivia <i@mistivia.com> | 2025-07-22 15:34:57 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-07-22 15:35:11 +0800 |
| commit | ea5c15cbd628953e7b9d17b45ea685006a582cd4 (patch) | |
| tree | 0440a31d4fb2f73cd150fa11f19ac08fd23562f9 /src/prelude.lisp | |
| parent | d64a599af8c6b52223b20f727d76a59a562abb75 (diff) | |
change dir structure
Diffstat (limited to 'src/prelude.lisp')
| -rw-r--r-- | src/prelude.lisp | 132 |
1 files changed, 0 insertions, 132 deletions
diff --git a/src/prelude.lisp b/src/prelude.lisp deleted file mode 100644 index a1be068..0000000 --- a/src/prelude.lisp +++ /dev/null @@ -1,132 +0,0 @@ -(defvar nil '()) - -(defvar pi 3.1415926) -(defvar e 2.718281828) - -(defmacro incq (i) - `(setq ,i (+ ,i 1))) - -(defmacro decq (i) - `(setq ,i (- ,i 1))) - -(defun zero? (x) (= x 0)) -(defun plus? (x) (> x 0)) -(defun minus? (x) (< x 0)) - -(defmacro when (pred . body) - `(if ,pred - (progn ,@body) - nil)) - -(defmacro unless (pred . body) - `(if ,pred - nil - (progn ,@body))) - -(defun take (n lst) - (unless (integer? n) - (error "take: type error.")) - (unless (list? lst) - (error "take: type error.")) - (let ((i 0) - (newlst nil)) - (while (and (< i n) - (not (null? lst))) - (setq newlst (cons (car lst) newlst)) - (setq lst (cdr lst)) - (incq i)) - (nreverse newlst))) - -(defun drop (n lst) - (unless (integer? n) - (error "drop type error.")) - (unless (list? lst) - (error "drop: type error.")) - (let ((i 0)) - (while (and (< i n) - (not (null? lst))) - (setq lst (cdr lst)) - (incq i)) - lst)) - -(defun take-while (pred lst) - (unless (function? pred) - (error "take-while: type error.")) - (unless (list? lst) - (error "take-while: type error.")) - (let ((newlst nil)) - (while (and (not (null? lst)) - (funcall pred (car lst))) - (setq newlst (cons (car lst) newlst)) - (setq lst (cdr lst))) - (nreverse newlst))) - -(defun drop-while (pred lst) - (unless (function? pred) - (error "drop-while: type error.")) - (unless (list? lst) - (error "drop-while: type error.")) - (while (and (not (null? lst)) - (funcall pred (car lst))) - (setq lst (cdr lst))) - lst) - -(defun sublist (start end lst) - (unless (integer? start) - (error "sublist: type error.")) - (unless (integer? end) - (error "sublist: type error.")) - (unless (< start end) - (error "sublist: start must less than end.")) - (unless (list? lst) - (error "sublist: type error.")) - (drop start (take end lst))) - -(defun find (x lst) - (unless (list? lst) - (error "find: type error.")) - (while (not (null? lst)) - (when (equal? x (car lst)) - (return lst)) - (setq lst (cdr lst))) - nil) - -(defun contains? (x lst) - (unless (list? lst) - (error "contains?: type error.")) - (while (not (null? lst)) - (when (equal? x (car lst)) - (return #t)) - (setq lst (cdr lst))) - #f) - -(defun caar (x) (car (car x))) -(defun cadr (x) (car (cdr x))) -(defun cddr (x) (cdr (cdr x))) -(defun cdar (x) (cdr (car x))) - -(defun caaar (x) (car (caar x))) -(defun cadar (x) (car (cdar x))) -(defun cddar (x) (cdr (cdar x))) -(defun cdaar (x) (cdr (caar x))) -(defun caadr (x) (car (cadr x))) -(defun caddr (x) (car (cddr x))) -(defun cdddr (x) (cdr (cddr x))) -(defun cdadr (x) (cdr (cadr x))) - -(defun caaaar (x) (car (caaar x))) -(defun cadaar (x) (car (cdaar x))) -(defun cddaar (x) (cdr (cdaar x))) -(defun cdaaar (x) (cdr (caaar x))) -(defun caadar (x) (car (cadar x))) -(defun caddar (x) (car (cddar x))) -(defun cdddar (x) (cdr (cddar x))) -(defun cdadar (x) (cdr (cadar x))) -(defun caaadr (x) (car (caadr x))) -(defun cadadr (x) (car (cdadr x))) -(defun cddadr (x) (cdr (cdadr x))) -(defun cdaadr (x) (cdr (caadr x))) -(defun caaddr (x) (car (caddr x))) -(defun cadddr (x) (car (cdddr x))) -(defun cddddr (x) (cdr (cdddr x))) -(defun cdaddr (x) (cdr (caddr x))) |
