From: Brian Candler Date: 2007-04-24T04:31:05+09:00 Subject: Re: Arrow operator with dash instead of equals (->) On Tue, Apr 24, 2007 at 02:25:33AM +0900, Andrew Green wrote: > (x -> last_names).to_s + ", " + (x -> first_names).to_s > > Using a dot instead of an arrow here is not an option for various > reasons. > > Any ideas as to how to hack around this limitation in Ruby, then? As you say, you could use >>, although it has a fairly low operator precedence, so x >> last_names + x >> first_names would be parsed, I think, as x >> (last_names + x) >> first_names If you're going to run through a preprocessor to substitute ->, then "." may be a better substitution. > Our interpreter eventually gets the code blocks as strings, so I could > just substitute the -> for >> behind the user's back, but that would be > messy, because it would substitute all occurrences of ->, even if > they're in quotes or interpretable by Ruby in some other, unforseen way. > Or is there some clean way of doing this? With ri or something similar, > maybe? The cleanest way I suspect would be to define a grammar for your own language, and write a parser for it. I believe there's a Ruby parser generator out there. Then you are not bound by the rules of Ruby syntax at all. Regards, Brian.