Smerl breakthough: metacurrying

David Hopwood <>
Sat Aug 19 18:10:37 CEST 2006


Yariv Sadan wrote:
> Hi,
> 
> I added a new capability to Smerl, allowing you to curry parameters
> for function forms in runtime, finally freeing us from having to know
> the Erlang abstract form!
> 
[...]
> http://yarivsblog.com/articles/2006/08/19/erlang-metaprogramming-breakthrough-metacurrying

This functionality is similar to Lisp's quasiquoting. It is generalized
by quasipatterns in E:
<http://www.erights.org/elang/grammar/quasi-overview.html>

(That page unfortunately assumes a lot of context that might be opaque
to people not familiar with E, but hopefully the main ideas will come
through.)

Quasipatterns are more general because, as well as being able to make
substitutions (what you call metacurrying), they also allow pattern
matching on programs without having to know the abstract form. For
example:

  /**
   * What's the derivative of expr with respect to var? I.e. what's
   * "d(expr)/d(var)"?
   */
  def deriv(expr, var) :any {
      switch (expr) {
          # ** means "to the power"
          match e`$var ** @exp` ? (isConst(exp)) {
              e`$exp * $var ** ($exp - 1)`
          }
          match e`@a + @b` {
              e`${deriv(a, var)} + ${deriv(b, var)}`
          }
          ...  # other differentiable expressions
      }
  }

Also, quasipatterns are designed to be able to process multiple languages,
and even mixtures of languages, while still being able to express simple
cases simply.

-- 
David Hopwood <>






More information about the erlang-questions mailing list