Semantics of Multiple Values

  • Thread starter Kristof Bastiaensen
  • Start date
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top