There is two way to make a domain-specific language with a clojure back-end
:
- if you want the language to be an extension of Clojure, still to be used
in a REPL or by clojure source
-> you write macros. That's what I call embedded. There is a lot of
litterature on Embedded Domain Specific
Thanks Nicolas,
your first variant resembles the generated code much closer than my
initial approach, which is great. I need the eval though, to be able
to pass in non literals. In my real program I'm reading the
instructions from a binary file. So if I want to be able to do
something like this:
First a simple version, equivalent to yours but more readable.
(defmacro compile-instructions
[instructions]
(let [memory (gensym "memory-")]
`(fn [~memory]
~@(map (fn [[op m1 m2]]
`(aset ~memory ~m1 (~op (aget ~memory ~m1) (aget ~memory
~m2
inst
Recently, I implemented last year's ICFP problem. Part of it is
writing a VM that consists of memory slots, some registers and input
and input ports. It takes a list of instructions, works them off one
after the other, reading from input or memory, calculating something
and the changing registers o