STR-667: ?Foo(...) : support efficient, concise matching of constructors with variable number of arguments
?“Foo”#(_) is a rather verbose and inefficient way of matching Foo with any number of arguments. Two things could be improved:
a) support a more intuitive syntax, for example ?Foo(…) (which is the syntax of parse-unit)
Submitted on 24 November 2006 at 14:19
b) make specific forms of ?p#(p) more efficient (i.e. not explode to a tuple). in particular, matching a constant constructor with a variable number of arguments can be implemented much more efficiently.
Issue Log
STR-667, martin:
Tom supports this as Foo[]. In Stratego, I would prefer the Foo(…) syntax.
STR-667, pierron:
and why not handle those in the same way ??Foo(…) -> “Foo”#(id)
?Foo(x, …) -> “Foo”#([?x | id])
?Foo(…, x, …) -> “Foo”#(at-suffix([?x | id]))
?Foo(…, x) -> “Foo”#(at-last([?x]))
?Foo(a, …, b, …, c, …, d) -> “Foo”#([?a | at-suffix([?b | at-suffix([?c | at-last([?d]) ]) ]) ])
STR-667, martin:
Hm, list matching, interesting :)Indeed, it would be good if ?Foo(…) is just sugar for the # operator, where the implementation of the # operator should be optimized.
The list matching would be great to have, though we should probably consider to do this completely right (as opposed to supporting some specific forms, e.g. should list matching be greedy? What if a match fails because it was too greedy? How to deal with multiple possible matches?)
STR-667, pierron:
This problem should be solved to remove an asymmetric behavior of star-variables:a := 1
; b* := [2, 3]
; c := 4
; ![a, b*, c]
; ?[1, 2, 3, 4]
; ?[a, b*, c] // fail
Log in to post comments