define-typed working;; parsing keywords in lambdalists correctly next

This commit is contained in:
FelixBrendel
2019-07-06 00:35:55 +02:00
parent e0aaf351c5
commit 5716e83598
8 changed files with 44 additions and 32 deletions
+2 -4
View File
@@ -1,12 +1,10 @@
(define-typed (ttt a :number b :alist) (printf a b))
(define (null? x) "Checks if the argument is =nil=." (= x ()))
(define (type=? obj typ) "Checks if the argument =obj= is of type =typ=" (= (type obj) typ))
(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 (types=? :rest objs) (define (inner objs) (if objs (let ((actual-type (type (first objs))) (desired-type (first (rest objs)))) (if (= actual-type desired-type) (inner (rest (rest objs))) ())) t)) (inner objs))
(define (assert-types= :rest objs) (break) (unless (apply types=? objs) (error "assert-types=: types do not match")))
(define (assert-types= :rest objs) (define (inner objs) (when objs (let ((actual-type (type (first objs))) (desired-type (first (rest objs)))) (if (= actual-type desired-type) (inner (rest (rest objs))) (error "type missmatch" actual-type desired-type))))) (inner objs))
(define (number? x) "Checks if the argument is a number." (type=? x :number))