Raku / old-design-docs

Raku language design documents
https://design.raku.org/
Artistic License 2.0
124 stars 36 forks source link

Need clarification/confirmation of Nil handling in ?-quantifiers #35

Closed pmichaud closed 10 years ago

pmichaud commented 11 years ago

Just wanting to make sure we cover the bases on ?-quantifiers...

Consider an expression like:

'1a2b345e' ~~ / [ (\d) (<[a..z]>)? ]+ /

Clearly $0 and $1 will both be lists of Match objects because of the indirect + quantifier, and $0 will have five elements.

Will $1 end up with three elements (the Match objects for 'a', 'b', and 'e'), five elements (Match for 'a', Match for 'b', Nil, Nil, and Match for 'e'), or some other result?

Pm

TimToady commented 11 years ago

Match, Match, Nil, Nil, Match is the best, seems to me. Also note that Nil is not supposed to turn into () in list context anymore, so @$0 Z @$1 should stay in sync.

FROGGS commented 11 years ago

If you have something like:

'1a-2b-3-4-5e' ~~ / [ (\d) (<[a..z]>)? ]+ % '-' /

It would be hard to loop over $0 and $1 at the same time if $1 had not the same number of elements...

So, +1 for Nil