J
Jean-Hugues ROBERT
il Wed, 28 Apr 2004 13:35:09 +0900, Jean-Hugues ROBERT
oh, please no more obscure operators.
I think little people here would like this route when in the future we
found ourself using perl6-ish stuff like "@a >>=:=<< @b"
Well... once you have =~= you can get rid of both = and ==, =~= does
both (under certain circumstances). So I guess I am actually proposing
to have less operators ! kidding.
I agree with you. If something related to Unification is to be introduced,
say the pattern matching, I would rather have a "match()" builtin than
a rather contrived =~= binary operator.
Example: somewhere in a parser.
# Get next token. If expecting a specific one, please specify it.
# Returns next token or nil if it is not the expected one.
def next_tok( tok = free )
tok if match tok, $lex.next_tok()
end
def next_tok( tok = nil )
ntok = $lex.next_tok()
ntok unless tok and ntok != tok
end
x = next_tok()
...
syntax_err( "expected 'end'") unless next_tok( Tk::End)
Both methods serve the same purpose, but the first one's body is
50% slimmer. It should be faster too.
I believe this is a significant increase in the expressiveness
of Ruby, for a rather low cost.
I will provide a user level prototypal implementation in Ruby soon.
Yours,
Jean-Hugues