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
+1
View File
@@ -17,3 +17,4 @@ todo.html
/manual/manual.pdf /manual/manual.pdf
/manual/manual.tex /manual/manual.tex
*.out *.out
/bin/slime
+6 -4
View File
@@ -113,9 +113,10 @@
(define (alist-set! alist key value) (define (alist-set! alist key value)
(mutate alist (pair (pair (pair key value) (mutate alist (set-type (pair (pair (pair key value)
(car alist)) (car alist))
()))) ())
:alist)))
(define (alist-set-overwrite! alist key value) (define (alist-set-overwrite! alist key value)
@@ -141,7 +142,8 @@
(plist-get-intern props prop))) (plist-get-intern props prop)))
(define (plist-set! plist prop value) (define (plist-set! plist prop value)
(mutate plist (pair (pair prop (pair value (first plist))) ()))) (mutate plist (set-type (pair (pair prop (pair value (first plist))) ())
:plist)))
(define (plist-set-overwrite! plist prop value) (define (plist-set-overwrite! plist prop value)
(let ((props (first plist))) (let ((props (first plist)))
+16 -14
View File
@@ -141,9 +141,6 @@ ithe sequence as arguemens."
(assert-types= @lambda-list) (assert-types= @lambda-list)
@body))) @body)))
(define-typed (ttt a :number b :alist)
(printf a b))
(define-syntax (define-package name :rest body) (define-syntax (define-package name :rest body)
`(define ,(string->symbol (concat-strings (symbol->string name) "->")) `(define ,(string->symbol (concat-strings (symbol->string name) "->"))
((lambda () ((lambda ()
@@ -157,7 +154,6 @@ ithe sequence as arguemens."
(eval op)))) (eval op))))
:package))))) :package)))))
(define (null? x) (define (null? x)
"Checks if the argument is =nil=." "Checks if the argument is =nil=."
(= x ())) (= x ()))
@@ -167,19 +163,25 @@ ithe sequence as arguemens."
(= (type obj) typ)) (= (type obj) typ))
(define (types=? :rest objs) (define (types=? :rest objs)
;; TODO make inner rec functoin to avoid evalutating every time (define (inner objs)
(if objs (if objs
(begin (let ((actual-type (type (first objs)))
(assert (keyword? (first (rest objs)))) (desired-type (first (rest objs))))
(if (type=? (first objs) (first (rest objs))) (if (= actual-type desired-type)
(apply types=? (rest (rest objs))) (inner (rest (rest objs)))
())) ()))
t)) t))
(inner objs))
(define (assert-types= :rest objs) (define (assert-types= :rest objs)
(break) (define (inner objs)
(unless (apply types=? objs) (when objs
(error "assert-types=: types do not match"))) (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) (define (number? x)
"Checks if the argument is a number." "Checks if the argument is a number."
+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 (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 (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)) (define (number? x) "Checks if the argument is a number." (type=? x :number))
+16
View File
@@ -0,0 +1,16 @@
(import "alist.slime")
(define-typed (tf n :number a :alist)
(printf n)
(pprint-alist a))
(define a (make-alist))
(alist-set! a 'a 1)
(alist-set! a 'b 2)
(tf 1 a)
(define (test a b)
(printf a b))
(test :ij :yes)
+1 -1
View File
@@ -3,7 +3,7 @@ SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
pushd $SCRIPTPATH > /dev/null pushd $SCRIPTPATH > /dev/null
# _DEBUG # _DEBUG
time clang++ src/main.cpp -g -o ./bin/slime --std=c++17 || exit 1 time g++ -fpermissive src/main.cpp -g -o ./bin/slime --std=c++17 || exit 1
echo "" echo ""
pushd ./bin > /dev/null pushd ./bin > /dev/null
+1 -8
View File
@@ -591,20 +591,13 @@ ithe sequence as arguemens.
\hrule \hrule
* =define-package= * =define-package=
- defined in :: =pre.slime:158:24= - defined in :: =pre.slime:155:24=
- type :: =:macro= - type :: =:macro=
- arguments :: : - arguments :: :
- postitional :: =name=: - postitional :: =name=:
- rest :: =body= - rest :: =body=
- docu :: none - docu :: none
\hrule \hrule
* =ttt=
- type :: =:lambda=
- arguments :: :
- postitional :: =a=, =b=
- docu :: none
\hrule
* =null?= * =null?=
- type :: =:lambda= - type :: =:lambda=
+1 -1
View File
@@ -199,7 +199,7 @@ proc visualize_lisp_machine() -> void {
case Lisp_Object_Type::Function: return draw_text("Function", "#aa1100"); case Lisp_Object_Type::Function: return draw_text("Function", "#aa1100");
case Lisp_Object_Type::CFunction: return draw_text("CFunction", "#11aa00"); case Lisp_Object_Type::CFunction: return draw_text("CFunction", "#11aa00");
default: default:
fprintf(stderr, "Do not know hot to visualize type %d\n", Memory::get_type(obj)); fprintf(stderr, "Do not know hot to visualize type %d\n", (int)Memory::get_type(obj));
return {0}; return {0};
} }
}; };