function contexts are fixed at declaration
This commit is contained in:
parent
b86a25b5bc
commit
f80aa7a8dc
|
@ -46,6 +46,7 @@
|
|||
(string/join (map stringify (keys value)) ", ")
|
||||
:ref (stringify (value :^value))
|
||||
:fn (string "fn " (value :name))
|
||||
:applied (string "fn " (value :name))
|
||||
:function (string "builtin " (string value))
|
||||
:pkg (dict-str value)
|
||||
))
|
||||
|
|
|
@ -359,25 +359,30 @@
|
|||
# For now, this should be enough to tall the thing
|
||||
(defn- fnn [ast ctx]
|
||||
(def {:name name :data clauses :doc doc} ast)
|
||||
(def the-fn @{:name name :^type :fn :body clauses :ctx ctx :doc doc})
|
||||
(def the-fn @{:name name :^type :fn :body clauses :ctx (table/to-struct ctx) :doc doc})
|
||||
(set (ctx name) the-fn))
|
||||
|
||||
(defn- is_placeholder [x] (= x :_))
|
||||
|
||||
(var call-fn nil)
|
||||
|
||||
(def name "foo")
|
||||
(eval ~(fn ,(symbol name) [] :foo))
|
||||
|
||||
(defn- partial [the-fn partial-args]
|
||||
(print "calling partially applied function")
|
||||
(def args (partial-args :args))
|
||||
(pp args)
|
||||
(def pos (find-index is_placeholder args))
|
||||
(def name (string (the-fn :name) "<partial>"))
|
||||
(fn [missing]
|
||||
(def name (string (the-fn :name) " *partial*"))
|
||||
(defn partial-fn [missing]
|
||||
(print "calling function with arg " (b/show missing))
|
||||
(pp partial-args)
|
||||
(def full-args (array/slice args))
|
||||
(set (full-args pos) missing)
|
||||
(print "all args: " (b/show full-args))
|
||||
(call-fn the-fn [;full-args])))
|
||||
(call-fn the-fn [;full-args]))
|
||||
{:^type :applied :name name :body partial-fn})
|
||||
|
||||
(defn- call-fn* [the-fn args]
|
||||
(print "calling " (b/show the-fn))
|
||||
|
@ -414,6 +419,8 @@
|
|||
|
||||
(set call-fn call-fn*)
|
||||
|
||||
(defn- call-partial [the-fn arg] ((the-fn :body) ;arg))
|
||||
|
||||
(defn- apply-synth-term [prev curr]
|
||||
(print "applying " (b/show prev))
|
||||
(print "to" (b/show curr))
|
||||
|
@ -424,6 +431,7 @@
|
|||
[:fn :tuple] (call-fn prev curr)
|
||||
[:fn :partial] (partial prev curr)
|
||||
[:function :tuple] (call-fn prev curr)
|
||||
[:applied :tuple] (call-partial prev curr)
|
||||
[:keyword :args] (get (first curr) prev :^nil)
|
||||
[:dict :keyword] (get prev curr :^nil)
|
||||
[:nil :keyword] :^nil
|
||||
|
@ -457,7 +465,6 @@
|
|||
(def last-fn (interpret last-term ctx))
|
||||
(call-fn last-fn [prev]))
|
||||
|
||||
# TODO for Computer Class
|
||||
(defn- pkg [ast ctx]
|
||||
(def members (ast :data))
|
||||
(def the-pkg @{:^name (ast :name) :^type :pkg})
|
||||
|
@ -613,10 +620,9 @@
|
|||
|
||||
(do
|
||||
(set source `
|
||||
let foo = 42
|
||||
let bar = :bar
|
||||
pkg Baz {foo, bar}
|
||||
Baz :fool
|
||||
fn myadd (x, y) -> add (x, y)
|
||||
let add = myadd(2, _)
|
||||
add (3)
|
||||
`)
|
||||
(def result (run))
|
||||
(b/show result)
|
||||
|
|
Loading…
Reference in New Issue
Block a user