mirror of
https://github.com/janet-lang/janet
synced 2025-02-10 22:00:01 +00:00
Add clojure style threading macros.
This commit is contained in:
parent
e393e3dda0
commit
61645c82b1
@ -137,7 +137,8 @@ If no match is found, returns nil"
|
||||
{:more more :next (fn [] (f (next)))})
|
||||
|
||||
(defn reduce [f start s]
|
||||
(def {:more more :next next} (seq s))
|
||||
(def s (seq s))
|
||||
(def {:more more :next next} s)
|
||||
(if (more)
|
||||
(reduce f (f start (next)) s)
|
||||
start))
|
||||
@ -209,6 +210,28 @@ If no match is found, returns nil"
|
||||
newenv)
|
||||
(put _env '_env nil)
|
||||
|
||||
(defmacro ->
|
||||
[x & forms]
|
||||
(defn fop [last nextform]
|
||||
(def n (ast-unwrap1 nextform))
|
||||
(def [h t] (if (= :tuple (type n))
|
||||
[(get n 0) (array-slice n 1)]
|
||||
[n []]))
|
||||
(def parts (array-concat [h last] t))
|
||||
(apply tuple parts))
|
||||
(reduce fop x forms))
|
||||
|
||||
(defmacro ->>
|
||||
[x & forms]
|
||||
(defn fop [last nextform]
|
||||
(def n (ast-unwrap1 nextform))
|
||||
(def [h t] (if (= :tuple (type n))
|
||||
[(get n 0) (array-slice n 1)]
|
||||
[n []]))
|
||||
(def parts (array-concat [h] t last))
|
||||
(apply tuple parts))
|
||||
(reduce fop x forms))
|
||||
|
||||
(def run-context
|
||||
"Run a context. This evaluates expressions of dst in an environment,
|
||||
and is encapsulates the parsing, compilation, and evaluation of dst.
|
||||
|
Loading…
x
Reference in New Issue
Block a user