Implementing Scheme as DSL for D

Charlie charlie.fats at gmail.com
Mon Mar 12 17:05:07 PDT 2007


This looks like allot of fun, I look forward to following your progress 
:).  I don't see any show stoppers, but I only have a little experience 
with this.

Charlie

vsb wrote:
> I want to implement a library for D.
> It's better to show as I imagine it now:
> 
> mixin(scheme("
> (define my_plus (lambda (a b) (+ a b)))
> "));
> 
> int a = 1;
> int b = 2;
> writefln("%d + %d = %d", a, b, my_plus(a, b));
> 
> function scheme() is a function which translates code in Scheme to code in D. I'm planning that resulting D code will just reflect all the structure, except few cases such as defining new functions. 
> In the case above it would be translated in next code:
> 
> "
> SExpr my_plus(SExpr a, SExpr b) {
>     return new List(lambda, new List(a, b), new List(PLUS, a, b));
> }
> "
> 
> And after applying mixin() on this it introduces new function, which could be used naturally as plain D function. Of course it requires a supporting library.
> 
> Is there any things which could make my task impossible at all? As I see, functions which could be run in compile-time are restricted, but for simple parser (especially for such syntactically simple language as Scheme) they are powerful enough. Any ideas are welcome.



More information about the Digitalmars-d mailing list