[e-lang] DSL fun with quasiliterals

Kevin Reid kpreid at switchb.org
Mon May 30 22:06:51 PDT 2011


So, I was pondering to what degree one could do full embedding-another-language in E with quasiliterals, if one accepts the idea of quasiliterals with side-effects.

Embedding an E expression whose free variables are external to the quasi-expression is easy enough, using the $ syntax.

But the fun part is when we want to use variables from the embedded language in an E subexpression:

foo`
  blah blah blah
  let bar = ...
  ...
  ${fn bar {
    ... E code ...
  }}
  ...
`

The quasi-parser can look at the inner function, *extract the variable names from its alleged type*, and provide appropriate bindings as function arguments! It can't do this until run-time, but single-cell memoization could reduce the inefficiency.

I only just thought of this idea, I have no actual uses for it, and it's probably overly surprising for maintainability.

(On the other hand, if it was actually useful, we could introduce a cheap special syntax to make it lighter and flag that the quasi-hole and fn are a unit: $fn <args> {...} without the outer braces. Or $(<args>) {...} perhaps.)

-- 
Kevin Reid                                  <http://switchb.org/kpreid/>




More information about the e-lang mailing list