(defcode-eval name & body)
(defcode-eval &form &env name & body)
Allows you to define functions that contain fif code, which can then be passed through a fif stack machine to be evaluated.
Example:
(defcode-eval import-add2-library fn add2 + 2 endfn)
(def custom-stack-machine (-> fif.core/default-stack import-add2-library))
(fif.core/with-stack custom-stack-machine (fif.core/reval 2 add2)) ;; => '(4)
Allows you to define functions that contain fif code, which can then be passed through a fif stack machine to be evaluated. Example: (defcode-eval import-add2-library fn add2 + 2 endfn) (def custom-stack-machine (-> fif.core/*default-stack* import-add2-library)) (fif.core/with-stack custom-stack-machine (fif.core/reval 2 add2)) ;; => '(4)
(set-word-function sm wname wfunc & {:keys [doc group]})
Creates a new word function in sm
with the symbol name wname
and
with the word function defined by wfunc
.
Notes:
wfunc
is a stack-machine function. Normal clojure functions can
be turned into stack-machine functions via
wrap-function-with-arity
and wrap-procedure-with-arity
.Creates a new word function in `sm` with the symbol name `wname` and with the word function defined by `wfunc`. Notes: - `wfunc` is a stack-machine function. Normal clojure functions can be turned into stack-machine functions via `wrap-function-with-arity` and `wrap-procedure-with-arity`.
(set-word-variable sm wname value & {:keys [doc group]})
Creates a new word variable in sm
with the symbol name wname
and
with the value value
. Optionally, you can include a docstring, and
a group key.
Notes:
value
is automatically wrapped for you. This is not the case
with set-word-definition
.Creates a new word variable in `sm` with the symbol name `wname` and with the value `value`. Optionally, you can include a docstring, and a group key. Notes: - `value` is automatically wrapped for you. This is not the case with `set-word-definition`.
(wrap-function-with-arity num-args f)
Wraps a clojure function f
which accepts num-args
, and returns
the function wrapped to be used in a stack machine.
The returned function accepts num-args
values on the stack, drops
num-args
after processing the wrapped function, and pushes the
result of (apply f args)
back onto the stack.
Notes:
This wrapper always returns a result on the stack. If you do not
wish to return a result, use fif.def/wrap-procedure-with-arity
instead.
Examples:
(defn add2 [x] (+ x 2)) (def my-stack-machine (-> (fif.stack/new-stack-machine) (fif.stack/set-word 'add2 (fif.def/wrap-function-with-arity 1 add2)))) (fif.core/with-stack my-stack-machine (fif.core/reval 1 add2)) ;; => '(3)
Wraps a clojure function `f` which accepts `num-args`, and returns the function wrapped to be used in a stack machine. The returned function accepts `num-args` values on the stack, drops `num-args` after processing the wrapped function, and pushes the result of `(apply f args)` back onto the stack. Notes: This wrapper always returns a result on the stack. If you do not wish to return a result, use `fif.def/wrap-procedure-with-arity` instead. Examples: (defn add2 [x] (+ x 2)) (def my-stack-machine (-> (fif.stack/new-stack-machine) (fif.stack/set-word 'add2 (fif.def/wrap-function-with-arity 1 add2)))) (fif.core/with-stack my-stack-machine (fif.core/reval 1 add2)) ;; => '(3)
(wrap-procedure-with-arity num-args f)
Wraps a clojure function f
which accepts num-args
, and returns
the function wrapped to be used in a stack machine.
The returned function accepts num-args
values on the stack, drops
num-args
after processing the wrapped function.
Notes:
This wrapper never returns a result on the stack. If you wish to
return a result, use fif.def/wrap-function-with-arity
instead.
Examples:
(def val (atom nil)) (defn set-val! [x] (reset! val x)) (def my-stack-machine (-> (fif.stack/new-stack-machine) (fif.stack/set-word 'set-val! (fif.def/wrap-procedure-with-arity 1 set-val!)))) (fif.core/with-stack my-stack-machine (fif.core/reval 1 set-val!) (deref val)) ;; => 1
Wraps a clojure function `f` which accepts `num-args`, and returns the function wrapped to be used in a stack machine. The returned function accepts `num-args` values on the stack, drops `num-args` after processing the wrapped function. Notes: This wrapper never returns a result on the stack. If you wish to return a result, use `fif.def/wrap-function-with-arity` instead. Examples: (def val (atom nil)) (defn set-val! [x] (reset! val x)) (def my-stack-machine (-> (fif.stack/new-stack-machine) (fif.stack/set-word 'set-val! (fif.def/wrap-procedure-with-arity 1 set-val!)))) (fif.core/with-stack my-stack-machine (fif.core/reval 1 set-val!) (deref val)) ;; => 1
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close