Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (deftag compile [body] (quasiquote (eval-when-compile ~body)))
- #compile
- (import [hy.models [HyList HyDict HySymbol HyKeyword]])
- #compile
- (defn annotation-symbol? [form]
- (and (instance? HyKeyword form) (= (name form) ":")))
- #compile
- (defn ldrop [count coll] (list (drop count coll)))
- #compile
- (defn get-annotations [args annotations valid-args]
- (if
- (empty? args) None
- (= (len args) 1) (.append valid-args (get args 0))
- (annotation-symbol? (get args 1))
- (do
- (.append annotations (mangle (get args 0)))
- (.append annotations (get args 2))
- (.append valid-args (get args 0))
- (get-annotations (ldrop 3 args) annotations valid-args))
- (do
- (.append valid-args (get args 0))
- (get-annotations (ldrop 1 args) annotations valid-args))))
- (defmacro defna [name args expression]
- (do
- (setv annotations [])
- (setv valid-args [])
- (get-annotations args annotations valid-args)
- (quasiquote
- (do
- (defn ~name ~(HyList valid-args) ~expression)
- (assoc (. ~name __annotations__) ~@annotations)))))
- ;; Example
- (defna add+ [a :: int b :: int c] (+ a c))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement