interpret forward-declared functions, allowing mutual recursion
This commit is contained in:
parent
bc1eac46b8
commit
bbd41a0f74
|
@ -362,7 +362,6 @@
|
|||
(def the-fn @{:name name :^type :fn :body clauses :ctx ctx})
|
||||
(set (ctx name) the-fn))
|
||||
|
||||
# TODO
|
||||
(defn- is_placeholder [x] (= x :_))
|
||||
|
||||
(var call-fn nil)
|
||||
|
@ -389,6 +388,8 @@
|
|||
(print "Janet function")
|
||||
(break (the-fn ;args)))
|
||||
(def clauses (the-fn :body))
|
||||
(when (= :nothing clauses)
|
||||
(error {:node the-fn :value args :msg "cannot call function before it is defined"}))
|
||||
(def len (length clauses))
|
||||
(when (the-fn :match) (break ((the-fn :match) 0 args)))
|
||||
(defn match-fn [i args]
|
||||
|
@ -552,15 +553,18 @@
|
|||
# (when (has-errors? validated) (break (validated :errors)))
|
||||
# (def cleaned (get-in parsed [:ast :data 1]))
|
||||
# (pp cleaned)
|
||||
(interpret (parsed :ast) @{:^parent b/ctx})
|
||||
# (try (interpret (parsed :ast) @{})
|
||||
# ([e] (print "Ludus panicked!: "
|
||||
# (if (struct? e) (error (e :msg)) (error e)))))
|
||||
# (interpret (parsed :ast) @{:^parent b/ctx})
|
||||
(try (interpret (parsed :ast) @{})
|
||||
([e] (print "Ludus panicked!: "
|
||||
(if (struct? e) (error (e :msg)) (error e)))))
|
||||
)
|
||||
|
||||
(do
|
||||
(set source `
|
||||
let #{:a ay, :b (:ok, bee), ...c} = #{:a 1, :b (:ok, 42), :c 3}
|
||||
fn foo
|
||||
fn bar () -> foo ()
|
||||
fn foo () -> :foo
|
||||
bar ()
|
||||
`)
|
||||
(def result (run))
|
||||
# (b/show result)
|
||||
|
|
Loading…
Reference in New Issue
Block a user