Smerl breakthough: metacurrying

Yariv Sadan yarivvv@REDACTED
Tue Aug 22 21:01:27 CEST 2006


> 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.


Hi,

I added to Smerl a function called embed_params/2. It's more general
than metacurrying because it can substitute any parameter with a
variable in the body of a function, but it also requires more work
from the user because the names of the parameters must be provided as
well as their values.

Example:

M1 = smerl:new(foo),
{ok, M2} = smerl:add_func(M1, "bar(A,B,C) -> A+B*2+C*3."),
{ok, F1} = smerl:get_func(M1, bar, 3),
F2 = smerl:embed_params(F1, [{'A', 3}, {'C', 5}]),
{ok, M3} = smerl:add_func(M2, F2),
smerl:compile(M3),
foo:bar(2) = 22.


This may not be as powerful as quasiquoting, but I have found it
useful in my current project.

(I could also add some helper functions to reduce the LOC in this example.)

Best,
Yariv



More information about the erlang-questions mailing list