embedding other languages in source code (was: regexp escapes)

Vlad Dumitrescu <>
Fri Jun 5 10:03:30 CEST 2009


On Fri, Jun 5, 2009 at 08:04, Richard O'Keefe <> wrote:
>
> On 5 Jun 2009, at 1:33 am, Vlad Dumitrescu wrote:
>> The xml might work because it's a very
>> simple structure, but who can write js parse trees directly?
>
> Every Lisp programmer on the planet?

Lisp is a very special case. It has almost no syntax, code=data and
the macros can make the most complicated think look like a simple
call.

Actually, the third solution I presented before is very much alike the
way Lisp does it, the difference is that the parse tree is represented
in the target language itself, not in the host language. I mean,

for (var i = 0; i < ~N; ++i) {
  document.write(i + "<br/>");
}

where N is a variable inherited from the environment, would look just
like that instead of

`(for (var i 0) (< i ,N) (++ i)
  (document.write (+ i "<br/>")))

or

{for, {{var, i}, {int, 0}}, {expr, '<', {var, i}, {int, N}}, {expr,
'++', {var, i}}, [
{call, 'document.write', [{expr, '+', {var, i}, {string, "<br/>"}}]}
]]

or

js:for(js:var(i), 0, js:expr('<', js:var(i), N), js:expr('++', js:var(i)),
        fun()->
            js:call('document.write', [js:expr('+', [js:var(i), "<br/>"])])
          end
     )

The result of parsing each of the snippets above should be the same
(well, not mixing Lisp and Erlang, of course).

best regards,
Vlad


More information about the erlang-questions mailing list