Re: for-must-match

Kevin Reid <kpreid-M/[email protected]> Tue, 25 Oct 2011 07:05:35 -0400
Newsgroups gmane.comp.lang.e.general
Message-ID <[email protected]>
On Oct 24, 2011, at 5:53, Thomas Leonard wrote:

> However, I didn't use the match syntax for this because, thinking
> about it further, I don't think using pattern bindings is a good way
> to test for a condition.
> 
> Consider a list of pairs [String,boolean] where we want to process all
> the true values. With pattern matching (current E syntax), we'd write:
> 
> for [name :String, ==true] in pairs { ... }
> 
> But this only covers two cases (match and no-match). There are really
> three cases:
> 
> match [name :String, ==true] => process this item
> match [_ :String, _:boolean] => skip this item
> match _ => report error
> 
> For switch statements and object definitions, this isn't a problem
> because when a pattern doesn't match it falls though to the next case
> and will eventually be reported or handled. But in for loops errors
> are silently ignored.

This -- that some things expressible as patterns are expectations/assertions and some things are match failures -- is a significant observation.

Perhaps we *should* have a general rule that any time there is *only one* pattern (i.e. not a switch), it should not have a failure behavior other than throwing (or the explicit ejector offered by def).


Another possibility is if we could have some kind of general syntax for all patterns which expressed "unexpected" (throw) vs. "expected" (match fail) mismatches. That is, being able to write (deliberately horrible syntax for example):

for <<EXPECTED>> [name :String, <<UNEXPECTED>> ==false] in pairs {...}

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