[e-lang] Call patterns
Kevin Reid
kpreid at mac.com
Sun Jul 23 09:30:46 EDT 2006
On Jul 23, 2006, at 1:09, Mark S. Miller wrote:
> Kevin Reid wrote:
>> def a.b(c) := d expands to
>> via (__makeVerbFacet.curryCall(a, "match__b/1")) [c]
>>
>> The idea is that call patterns are a form of extensible pattern
>> which is more suitable than quasi-patterns for objects which do
>> not naturally have a (semi-) textual syntax.
...
> Let's decide on a pragma.enable/1 switch name for enabling it, so
> we can experiment with it before deciding to add it officially to
> E. How about
> pragma.enable("call-pattern")
> ?
E-on-CL already uses this switch.
> What's its BNF?
call-patt ::= ( <noun-expr> | <paren-expr> ) ( "." <verb> ) <paren-
params>
The ANTLR grammar in E-on-CL:
eqPatt: ...
| nounExpr ( parenParams pocket["call-pattern"]
{##=#
([FunCallPattern],##);}
| "."! verb parenParams pocket["call-pattern"]
{##=#
([CallPattern],##);}
| optGuard {##=#
([FinalPattern],##);}
)
...
| parenExpr ( quasiString {##=#
([QuasiPattern],##);}
| parenParams pocket["call-
pattern"]
{##=#
([FunCallPattern],##);}
| "."! verb parenParams pocket["call-
pattern"]
{##=#
([CallPattern],##);}
)
...
;
parenParams is a parameter list like "(a, [b, c])". nounExpr is
misnamed, and actually a noun, URI <scheme> or $@hole.
The abstract syntax:
CallPattern(@{recipient :EExpr},
@{verb :string},
@{args :List[Pattern]}*)
FunCallPattern(@{recipient :EExpr},
@{args :List[Pattern]}*)
The abstract syntax definition and expansion code in E-on-CL:
(defemacro |CallPattern| (|Pattern|) ((|recipient| t |EExpr|)
(|verb| nil string)
(|args| t (e-list |Pattern|)))
(:rest-slot t)
(mn '|ViaPattern|
(mn '|CurryExpr|
(mn '|CallExpr|
|recipient|
(format nil "match__~A/~A" |verb| (length |args|))))
(apply #'mn '|ListPattern| |args|)))
(defemacro |FunCallPattern| (|Pattern|) ((|recipient| t |EExpr|)
(|args| t (e-list |Pattern|)))
(:rest-slot t)
(apply #'mn '|CallPattern| |recipient| "run" |args|))
--
Kevin Reid <http://homepage.mac.com/kpreid/>
More information about the e-lang
mailing list