For example:
(pseudo
a = 0
b = 100
s = 0
for (i from a to b)
s = s + i
write(s)
)If such pseudo code can be embedded into SBCL it would generate fast machine code, also it would be possible to easily modify pseudo code syntax.
This lets you write things like:
(for var in form do ...
or
(for var in form collect ...
where form can be anything that has an iterator method defined on it.
There's also a macro I use called BINDING-BLOCK (BB for short) which subsumes a bunch of binding forms. So you can write things like:
(bb
x (...)
y (...)
:db (q r s) (...) ; Destructuring-bind
:mv (p q) (...) ; Multiple-value-bind
...
It's extensible so you can add your own clauses. Code is here:http://www.flownet.com/ron/lisp/rg-utils.lisp
(It's a little out of date. If you want the latest let me know and I'll update it.)
like in scheme: (write (let for ((i 0) (s 0)) (if (> i 100) s (for (+ 1 i) (+ i s)))))
why would you care for those a, b, or s variables in the first place when all you want is the sum? The above expression writes the sum as computed by a recursive approach using lexical bindings.
you may of course abstract it away into a function: (define (for from to doit result) (if (> from to) result (for (+ 1 from) to doit (doit from result))))
and use it: (write (let ((a 0) (b 100)) (for a b + 0)))
I didn't even need macros yet!
As school teacher on programming I'm limited in choice of programming languages. The only language which I can study is Pascal (a lot of other reasons on it). The problem is that Pascal have not any libraries (GUI, 2D/3D, Game Development Engines, programming micro-controllers, ...). Students can write only simple console applications. So, it was be ideal to have subset of Pascal as eDSL on top of Common Lisp or Clojure. In that way I can easily extend original Pascal to access some real world libraries.
I think also on top of Common Lisp we can develop some simpler eDSL as pseudo-code for beginner students.
PS: gone to learn Common Lisp...
It's not true. Lazarus (http://www.lazarus.freepascal.org/) gives pretty much everything Delphi has. Currently I develop OpenGL 2D analytical tool. Again GUI is on par with Delphi.
LOOP shows some of the practical problem. For example for LOOP one needs a custom highlighter in the IDE, because it has its own complex syntax, which does not follow the basic Lisp model. Same for indentation / code formatting. There maybe other problems.
There is another Iteration facility as a library for Common Lisp called ITERATE. It is very similar to LOOP, but the syntax is a bit more oriented towards Lisp.
---------------------------
I have found two examples:
1. Python in Lisp: http://github.com/franzinc/cl-python
2. Ruby on Lisp: http://jng.imagine27.com/articles/2010-10-07-084756_ruby_sub...
I will try to write little subset of Pascal as eDSL on Lisp.
The advantage of doing a "language X to CL" translator is that it's going to be much simpler than doing it in another language (the number of features offered by CL is a huge superset of that available in any other language; the only exception is continuations), the result will be faster (the example Ruby translator is faster than Ruby, cl-javascript is faster than SpiderMonkey, etc, mostly due to SBCL being a reasonably good compiler), and you will have access to really good debugging tools (Clozure is really good at this - see http://openmcl.clozure.com/ccl-documentation.html#watched-ob... for example).
I came to conclusion that it is easier to do external DSL, not embedded. Parse source code on Pascal and then translate it into S-expressions. Am I right?
Btw, if I'm gonna write external DSL, I can do that in any language for example on Python. So, what's the difference?
But I've also been astounded at how slow CPython is compared to SBCL (the Common Lisp implementation I use) when I have to do long runs to gather data. (For the things I've been playing around with, my Common Lisp implementations have been something like 5 to 20 times faster.)