[e-lang] Guard-based pattern expansions

Mark S. Miller markm at cs.jhu.edu
Fri Apr 28 04:23:27 EDT 2006


In thinking about other possible expansions for the problematic patterns, I 
just now remembered what the fatal problem was that drove us away from the 
such-that pattern: It throws away the reason for failure, resulting in a loss 
of diagnostic information.

I think the via pattern is simply better than the such-that pattern in all 
ways but the one Chip pointed out: The only downside of the via pattern that I 
can see is that it seems similar to the guard pattern. Perhaps the answer is 
to make it more different, simply by giving it a syntax that doesn't suggest 
that it is like the guard pattern:

     pattern ::= 'via' '(' expr ')' '=~' pattern.

If the via pattern doesn't seem like the guard pattern, I cannot think of any 
other reason to prefer the such-that pattern over the via pattern.


> 'bind foo'  to  '_ :__Bind[foo__Resolver]'
would instead expand to
         'via (__bind(foo__Resolver)) =~ _'
or possibly
         'via (fn specimen, _ {foo__Resolver.resolve(specimen)}) =~ _'



> '["k" => p] | r'  to  '[p, r] :__Extract["k"]'
would instead expand to
         'via (__extract("k")) =~ [p, r]'

> '["k" => p default {e}] | r'  to  '[p, r] :__Extract["k", fn {e}]'
would instead expand to
         'via (__extract("k", fn {e})) =~ [p, r]'

deprecated:
> '["k" => p := e ] | r'  to  '[p, r] :__Extract.depr("k", e)'
would instead expand to
         'via (__extract.depr("k", e)) =~ [p, r]'



> 'foo`$x at y`'  to  '[y] :__MatchBind[foo__quasiParser.matchMaker("${0}@{0}"),
>                                    [x]]'
would instead expand to
         'via (__matchBind(foo__quasiParser.matchMaker("${0}@{0}"),
                           [x])) =~ [y]'
or possibly
         'via (fn specimen, optEjector {
                   foo__quasiParser.matchMaker("${0}@{0}").matchBind(
                       [x],
                       specimen,
                       optEjector)}) =~ [y]'



Still deprecated and eventually to be killed:
> 'p ? e'  to  '[p, :__SuchThat[e]] :__SuchThat'
would instead expand to
         'via (__suchThat) =~ [p, via (__suchThat(e)) =~ _]'
or possibly
         'via (fn specimen, _ {
                   [specimen, null]}) =~ [p, via (__suchThat(e)) =~ _]'

-- 
Text by me above is hereby placed in the public domain

     Cheers,
     --MarkM



More information about the e-lang mailing list