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