This commit is contained in:
1 parent
390fe16d90
commit
beb9bc3a4c
3 files changed
+75
-11
No files matched your search
@@ -7,3 +7,29 @@
|
||||
`(~f ~@(mapcat #(list (keyword %) %)
|
||||
syms))))
|
||||
|
||||
(defmacro todo
|
||||
([]
|
||||
`(throw (Exception. "todo")))
|
||||
([fmt & xs]
|
||||
`(throw (Exception (format (str "todo: " ~fmt) ~@xs)))))
|
||||
|
||||
(defn dbg> [x]
|
||||
(tap> x)
|
||||
x)
|
||||
|
||||
(defmacro dbg [x]
|
||||
`(let [x*# ~x
|
||||
{line# :line column# :column} ~(meta &form)]
|
||||
(tap> (vary-meta
|
||||
(list (symbol (format "%s:%s:%s"
|
||||
(str *ns*)
|
||||
line#
|
||||
column#))
|
||||
x*#)
|
||||
(fn [m#]
|
||||
(merge m#
|
||||
#:dbg {:line line#
|
||||
:column column#
|
||||
:ns *ns*
|
||||
:file (or *source-path* *file*)}))))
|
||||
x*#))
|
||||
@@ -107,19 +107,44 @@
|
||||
(scm/datum->syntax-recursive datum))
|
||||
(update-vals scm/syntax->datum)))
|
||||
|
||||
(defn transcribe [template unification]
|
||||
(defn strip-ellipsis [x depth]
|
||||
(match x
|
||||
[:ellipsis xs]
|
||||
(if (< 0 depth)
|
||||
[:ellipsis (map #(strip-ellipsis % (dec depth)) xs)]
|
||||
(throw (IllegalArgumentException. "점점점은 나쁘다.")))
|
||||
:else (if (zero? depth)
|
||||
x
|
||||
(throw (IllegalArgumentException.
|
||||
"depth는 영 아니지만 인수에 점점점이 남지 않는다.")))))
|
||||
|
||||
(defn- transcribe-rec [template unification depth]
|
||||
(match (scm/syntax-e template)
|
||||
(x :guard symbol?) (or (get unification x)
|
||||
(throw (Exception. "blah")))
|
||||
(_ :guard ellipsis?)
|
||||
(throw (IllegalArgumentException. "점점점은 여기 있으면 안 되다."))
|
||||
(x :guard symbol?)
|
||||
(match (get unification x)
|
||||
[:ellipsis xs] [:ellipsis xs]
|
||||
nil (throw (Exception. "nosymmm"))
|
||||
x-val x-val)
|
||||
|
||||
([x (_ :guard ellipsis?) & xs] :seq)
|
||||
(match (transcribe-rec x unification depth)
|
||||
[:ellipsis x*] (scm/datum->syntax x* template)
|
||||
:else (throw (IllegalArgumentException. "점점점은 나쁘다ㅠㅠ")))
|
||||
|
||||
([x & xs] :seq)
|
||||
(let [xs* (transcribe (scm/datum->syntax xs template) unification)]
|
||||
(let [xs* (transcribe-rec depth (scm/datum->syntax xs template) unification)]
|
||||
(scm/datum->syntax
|
||||
(cons (transcribe x unification) (scm/syntax-e xs*))
|
||||
(cons (transcribe-rec depth x unification) (scm/syntax-e xs*))
|
||||
template))
|
||||
|
||||
([] :seq)
|
||||
template))
|
||||
|
||||
(defn transcribe [template unification]
|
||||
(transcribe-rec template unification 0))
|
||||
|
||||
(defn transcribe*
|
||||
([template unification]
|
||||
(-> template
|
||||
@@ -132,10 +157,19 @@
|
||||
scm/syntax->datum)))
|
||||
|
||||
(comment
|
||||
(let [pattern 'x
|
||||
template 'x
|
||||
(let [pattern '(x ...)
|
||||
template '(x ...)
|
||||
datum '(1 2 3)]
|
||||
(-> template
|
||||
(transcribe* (unify (scm/datum->syntax-recursive pattern)
|
||||
(scm/datum->syntax-recursive datum)))
|
||||
#_scm/syntax->datum)))
|
||||
#_scm/syntax->datum))
|
||||
(let [pattern '((x y ...) ...)
|
||||
template '(x ...)
|
||||
datum '((1 2) (3 4 5))]
|
||||
(-> template
|
||||
(transcribe* (unify (scm/datum->syntax-recursive pattern)
|
||||
(scm/datum->syntax-recursive datum)))
|
||||
#_scm/syntax->datum))
|
||||
(unify* '((x y ...) ...)
|
||||
'((1 2 3) (3 4))))
|
||||
Reference in new issue
Block a user