Lisp/Scheme DSEL in C++?
Hello, I came across the following post on boost-users [1]:
hello all,
does anybody know of an existing spirit/lisp implimentation, and is there any interest in developing such a project in open source?
None yet, AFAIK.
I'll be writing an example for Spirit2 to complement the tiny-C virtual machine in there. What's equally interesting though is that scheme (or at least a subset of it) can be implemented in pure c++. No parsing, just pure DSEL in C++. Now, imagine a parser that targets this DSEL (through C++) -- a source to source translator. Essentially, your scheme code will be compiled into highly efficient C++.
I find this quite intriguing, and I'm naturally led to ask two questions: 1. Which subset of Scheme can be implemented in this way, with a DSEL? 2. Has anyone actually done this? Thanks! Nate [1] http://thread.gmane.org/gmane.comp.lib.boost.user/30512
On 11/15/2011 12:03 PM, Nathan Ridge wrote:
Hello,
I came across the following post on boost-users [1]:
hello all,
does anybody know of an existing spirit/lisp implimentation, and is there any interest in developing such a project in open source?
None yet, AFAIK.
There is now. There's a scheme subset implementation in the spirit examples dir.
I'll be writing an example for Spirit2 to complement the tiny-C virtual machine in there. What's equally interesting though is that scheme (or at least a subset of it) can be implemented in pure c++. No parsing, just pure DSEL in C++. Now, imagine a parser that targets this DSEL (through C++) -- a source to source translator. Essentially, your scheme code will be compiled into highly efficient C++.
I find this quite intriguing, and I'm naturally led to ask two questions:
1. Which subset of Scheme can be implemented in this way, with a DSEL?
2. Has anyone actually done this?
We've done this as well. Of course you understand that this does not really follow the lisp syntax, instead it's pure function call syntax. What's interesting is that the DSEL generates function objects which is interoperable with the scheme interpreter which also generates function objects. This was the subject of our BoostCon 2010 presentation. This scheme code: (define (factorial n) (if (<= n 0) 1 (* n (factorial (- n 1))))) Generates this C++ code (function objects that can be called in both C++ and scheme): lambda factorial; factorial = if_(lte(_1, 0), 1, times(_1, factorial(minus(_1, 1)))); See libs/spirit/example/scheme Regards, -- Joel de Guzman http://www.boostpro.com http://boost-spirit.com
What's equally interesting though is that scheme (or at least a subset of it) can be implemented in pure c++. No parsing, just pure DSEL in C++. Now, imagine a parser that targets this DSEL (through C++) -- a source to source translator. Essentially, your scheme code will be compiled into highly efficient C++.
I find this quite intriguing, and I'm naturally led to ask two questions:
1. Which subset of Scheme can be implemented in this way, with a DSEL?
2. Has anyone actually done this?
We've done this as well. Of course you understand that this does not really follow the lisp syntax, instead it's pure function call syntax.
But does a DSEL like this have the potential to support typical Scheme features like: - lazy evaluation (e.g. the "else" expression in an "if" is not evaluated if the condition is false) - pattern matching - macros ? Thanks, Nate
On 11/17/2011 12:34 PM, Nathan Ridge wrote:
What's equally interesting though is that scheme (or at least a subset of it) can be implemented in pure c++. No parsing, just pure DSEL in C++. Now, imagine a parser that targets this DSEL (through C++) -- a source to source translator. Essentially, your scheme code will be compiled into highly efficient C++.
I find this quite intriguing, and I'm naturally led to ask two questions:
1. Which subset of Scheme can be implemented in this way, with a DSEL?
2. Has anyone actually done this?
We've done this as well. Of course you understand that this does not really follow the lisp syntax, instead it's pure function call syntax.
But does a DSEL like this have the potential to support typical Scheme features like: - lazy evaluation (e.g. the "else" expression in an "if" is not evaluated if the condition is false)
Yes.
- pattern matching
Not sure. Probably, but I haven't looked into it.
- macros
No. Regards, -- Joel de Guzman http://www.boostpro.com http://boost-spirit.com
participants (2)
-
Joel de Guzman
-
Nathan Ridge