Tony Garnock-Jones wrote:
Paolo Bonzini wrote:
I'm thinking of adding regex literals to GNU Smalltalk.

I'd be against this.

 'a.*b' asRegex

to me seems better, and doesn't require and lexer/parser changes.

It's also slower, which is why as of today 'a.*b' works even without sending #asRegex.

However, *always* treating string literals as regexes is going to give problems in the long term. In particular, it would break with another extension that I was thinking about:

    #(1 3 2 6 5 4) select: #odd => #(1 3 5)
    #(1 12 2) select: (1 to: 10) => #(1 12)
    #('foo' 'bar') select: ##/f./ => #('foo')

This would be quite easily implemented (#select: would send a new message to its argument, e.g. #~, instead of #value:). If regexes would be implemented simply as strings, however, there would be a conflict between the Collection example (second) and the regex example (third):

    'foo' select: 'aeiouy' => 'oo'
    #('foo') select: 'f.' => cannot make it return 'foo' as I'd like!

That's why in this case, simply using string literals as regexes wouldn't work. You would need to specify #asRegex to get the desired behavior.

As I said, I'm also thinking "no"/"not yet". It's not paramount: older code would be unaffected, and I could start implementing the above (which is not happening any time soon), and then see if it is a problem. Just, there *might* be one.

Paolo


_______________________________________________
help-smalltalk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to