Vaguery / klapaucius

A clean, tested, maintainable Push interpreter written in Clojure.
MIT License
31 stars 2 forks source link

pseudo-composition of instructions #168

Open Vaguery opened 6 years ago

Vaguery commented 6 years ago

take their :transaction steps and concatenate them, producing a new consolidated function on the fly.

For example,

(:scalar-add 9 :boolean-or :scalar-≤)

(consume-top-of :scalar :as :arg2)
(consume-top-of :scalar :as :arg1)
(calculate [:arg1 :arg2] +' :as :prelim)
(calculate [:prelim] #(if %1 (Double/isNaN %1) false) :as :nan)
(calculate [:nan :prelim] #(when-not %1 %2) :as :sum)
(return-item :sum)
(calculate [:nan] #(when %1 ":scalar-add produced NaN") :as :warning)
(record-an-error :from :warning)

(push-onto :scalar 9) ; <- the literal

(consume-top-of :bool :as :arg2)
(consume-top-of :bool :as :arg1)
(calculate [:arg1 :arg2] #(~operation %1 %2) :as :result)
(return-item :result)

(consume-top-of :scalar :as :arg2)
(consume-top-of :scalar :as :arg1)
(calculate [:arg1 :arg2] #(< (compare %1 %2) 1) :as :check)
(return-item :check)
Vaguery commented 6 years ago

Affected by #175