alists and plists now

This commit is contained in:
FelixBrendel
2019-07-05 01:26:00 +02:00
parent d576e7324f
commit e0aaf351c5
14 changed files with 646 additions and 106 deletions
+20 -10
View File
@@ -1,22 +1,30 @@
(define (null? x) "Checks if the argument is =nil=." (= x nil))
(define-typed (ttt a :number b :alist) (printf a b))
(define (number? x) "Checks if the argument is a number." (= (type x) :number))
(define (null? x) "Checks if the argument is =nil=." (= x ()))
(define (symbol? x) "Checks if the argument is a symbol." (= (type x) :symbol))
(define (type=? obj typ) "Checks if the argument =obj= is of type =typ=" (= (type obj) typ))
(define (keyword? x) "Checks if the argument is a keyword." (= (type x) :keyword))
(define (types=? :rest objs) (if objs (begin (assert (keyword? (first (rest objs)))) (if (type=? (first objs) (first (rest objs))) (apply types=? (rest (rest objs))) ())) t))
(define (pair? x) "Checks if the argument is a pair." (= (type x) :pair))
(define (assert-types= :rest objs) (break) (unless (apply types=? objs) (error "assert-types=: types do not match")))
(define (string? x) "Checks if the argument is a string." (= (type x) :string))
(define (number? x) "Checks if the argument is a number." (type=? x :number))
(define (lambda? x) "Checks if the argument is a function." (= (type x) :lambda))
(define (symbol? x) "Checks if the argument is a symbol." (type=? x :symbol))
(define (macro? x) "Checks if the argument is a macro." (= (type x) :macro))
(define (keyword? x) "Checks if the argument is a keyword." (type=? x :keyword))
(define (special-lambda? x) "Checks if the argument is a special-lambda." (= (type x) :dynamic-macro))
(define (pair? x) "Checks if the argument is a pair." (type=? x :pair))
(define (built-in-function? x) "Checks if the argument is a built-in function." (= (type x) :built-in-function))
(define (string? x) "Checks if the argument is a string." (type=? x :string))
(define (lambda? x) "Checks if the argument is a function." (type=? x :lambda))
(define (macro? x) "Checks if the argument is a macro." (type=? x :macro))
(define (special-lambda? x) "Checks if the argument is a special-lambda." (type=? x :dynamic-macro))
(define (built-in-function? x) "Checks if the argument is a built-in function." (type=? x :built-in-function))
(define (callable? x) (or (lambda? x) (special-lambda? x) (macro? x) (built-in-function? x)))
@@ -32,6 +40,8 @@
(define (length seq) "Returns the length of the given sequence." (if (null? seq) 0 (+ 1 (length (rest seq)))))
(define (member? elem seq) (when (pair? seq) (if (= elem (first seq)) t (member? elem (rest seq)))))
(define (sublist-starting-at-index seq index) (cond ((< index 0) (error "sublist-starting-at-index: index must be positive")) ((null? seq) ()) ((= 0 index) seq) (else (sublist-starting-at (rest seq) (- index 1)))))
(define (list-without-index seq index) (cond ((or (< index 0) (null? seq)) (error "list-remove-index!: index out of range")) ((= 0 index) (rest seq)) (else (pair (first seq) (list-without-index (rest seq) (- index 1))))))