|
@@ -1,8 +1,9 @@
|
|
|
(ns (argyle generic)
|
|
|
- :replace (map)
|
|
|
:export (gen <gen-fn> gen-fn? xtnd type
|
|
|
len rev join cpy clr! kth))
|
|
|
(use (argyle base)
|
|
|
+ ((argyle base type)
|
|
|
+ :select ((str . _str)))
|
|
|
(argyle data)
|
|
|
(argyle data tbl)
|
|
|
(argyle data vec)
|
|
@@ -15,9 +16,8 @@
|
|
|
((name f) (id? #'name)
|
|
|
#'(def name (%gen-fn 'name (tbl 'def f))))
|
|
|
((name) (id? #'name)
|
|
|
- #'(def name (%gen-fn 'name (ret t (tbl)
|
|
|
- (when (defd? 'name)
|
|
|
- (t 'def name)))))))
|
|
|
+ #'(def name (%gen-fn 'name (when (defd? 'name)
|
|
|
+ (tbl 'def name))))))
|
|
|
|
|
|
(trans gen-fn (name tbl)
|
|
|
:init (%gen-fn name tbl)
|
|
@@ -29,7 +29,7 @@
|
|
|
(def resolve-fn (tbl args)
|
|
|
(loop lp ((for arg (in-list args))
|
|
|
(where t tbl (and=> t (\\ _ (type arg)))))
|
|
|
- => (cond ((and t (t 'fun)) (t 'fun))
|
|
|
+ => (cond ((and t (t 'fn)) (t 'fn))
|
|
|
((and t (t 'rst)) (t 'rst))
|
|
|
((tbl 'def) (tbl 'def))
|
|
|
(else (err "No generic fn for args1:" args)))
|
|
@@ -50,25 +50,26 @@
|
|
|
((name (arg1 ... . rest) body ...) (~(nil? #'rest))
|
|
|
(let-syn (args types) (split #'(arg1 ...))
|
|
|
#`(loop ((for type (in-list 'types))
|
|
|
- (where tbl (gen-fn-tbl name)
|
|
|
- (if (tbl type) (tbl type)
|
|
|
- (tbl type (mke-tbl)))))
|
|
|
- => (tbl 'rst (fn (#,@#'args . rest) body ...)))))
|
|
|
- ((name (arg1 ...) body ...) (defd? (syn->dat #'name))
|
|
|
+ (where type-tree (gen-fn-tbl name)
|
|
|
+ (or (type-tree type)
|
|
|
+ (do (type-tree type (mke-tbl))
|
|
|
+ (type-tree type)))))
|
|
|
+ => (type-tree 'rst (fn (#,@#'args . rest) body ...)))))
|
|
|
+ ((fn-name (arg1 ...) body ...) (defd? (syn->dat #'fn-name))
|
|
|
(let-syn (args types) (split #'(arg1 ...))
|
|
|
;; TODO: refactor
|
|
|
- #`(loop ((for type (in-list 'types))
|
|
|
- (where tbl (gen-fn-tbl name)
|
|
|
- (if (tbl type) (tbl type)
|
|
|
- (tbl type (mke-tbl)))))
|
|
|
- => (tbl 'fun (fn args body ...))))))
|
|
|
+ #`(loop ((for type (in-list 'types))
|
|
|
+ (where type-tree (gen-fn-tbl fn-name)
|
|
|
+ (or (type-tree type)
|
|
|
+ (do (type-tree type (mke-tbl))
|
|
|
+ (type-tree type)))))
|
|
|
+ => (type-tree 'fn (fn args body ...))))))
|
|
|
|
|
|
(gen len length)
|
|
|
(gen rev reverse)
|
|
|
(gen join append)
|
|
|
(gen cpy lst-cpy)
|
|
|
(gen clr! (fn (lst) (set-cdr! lst '())))
|
|
|
-(gen map (@ (srfi srfi-1) map))
|
|
|
|
|
|
(gen car)
|
|
|
(gen cdr)
|
|
@@ -76,34 +77,24 @@
|
|
|
(gen take)
|
|
|
(gen drop)
|
|
|
|
|
|
-(xtnd len (s <str>) (str-len s))
|
|
|
-(xtnd len (n <int>) (len (str n)))
|
|
|
+(defp str args
|
|
|
+ (reduce-right str-join "" (map _str args)))
|
|
|
+
|
|
|
(xtnd len (t <tbl>) (tbl-cnt (const #t) t))
|
|
|
(xtnd len (v <vec>) (vec-len v))
|
|
|
(xtnd len (q <q>) (q-len q))
|
|
|
(xtnd len (stream <strm>) (strm-len stream))
|
|
|
|
|
|
-(xtnd rev (v <vec>)
|
|
|
- (ret v* (mke-vec (vec-len v))
|
|
|
- (vec<-! v 0 (vec-len v) v* 0)))
|
|
|
(xtnd rev (s <str>) (string-reverse s))
|
|
|
|
|
|
(xtnd join (s1 <str> . rest) (apply str-join s1 rest))
|
|
|
-(xtnd join (v1 <vec> v2 <vec>)
|
|
|
- (w/ (l1 (vec-len v1) l2 (vec-len v2))
|
|
|
- (ret v (mke-vec (+ l1 l2))
|
|
|
- (vec->! v1 0 l1 v 0)
|
|
|
- (vec->! v2 0 l2 v l1))))
|
|
|
+
|
|
|
(xtnd join (strms <strm>) (strm-join strms))
|
|
|
|
|
|
(xtnd cpy (v <vec>) (vec-cpy v))
|
|
|
(xtnd cpy (q <q>) (%mke-q (q-len q) (q-hd q) (q-tl q)))
|
|
|
(xtnd clr! (t <tbl>) (tbl-clr! t))
|
|
|
(xtnd clr! (q <q>) (q-hd! q '()) (q-tl! q '()) (q-len! q 0))
|
|
|
-(xtnd map (f <fn> v <vec> . rst) (apply vec-map f v rst))
|
|
|
-(xtnd map (f <fn> s <str> . rst) (apply str-map f s rst))
|
|
|
-(xtnd map (f <fn> t <tbl>) (tbl-map->lst f t))
|
|
|
-(xtnd map (f <fn> s <strm> . rst) (apply strm-map f s rst))
|
|
|
|
|
|
(xtnd car (seq <strm>) (scar seq))
|
|
|
(xtnd car (seq <vec>) (seq 0))
|