Is it "Ruby is bad for having this not working"? -- then go to
https://bugs.ruby-lang.org/ and write it there. And prepare to discuss your
position and prove it should work another way around.
It is this case.
Then you know what to do, OK?
Or is it just "You, Victor, is wrong, stop saying it is not a bug"? --
OK, I am giving up. Who am I to try explaining to people who don't want any
explanations?..
But also it is "You, Victor, stop saying ruby fails because omitting a
space is bad code. It is not bad code."
In fact, it is. It is clearly defined by Ruby grammar and consistently
implemented in all versions and variants of Ruby.
If ruby decides /(1.to_f * (100 / 100)) is a malformed regexp, I think it
should do decide it always, no matter what's on the left of that, being 2,
2.to_f or var_name. It is confusing. Anyways, yes, this may not be the
place to discuss that.
You think this, then try to persuade Ruby core team, not me, that they
should complicate parser even more for this, definitely very important,
frequent and critical case.
Just out of curiosity, is this also how things are here?:
puts defined?(hello).class;if false;hello=1;end;puts defined?(hello).class
Yes. It is called variable scoping.
if-expression, by definition, does not create a separate scope, so every
local variable defined inside expression, even in the unreachable branch,
becomes defined.
···
2018-03-15 16:34 GMT+02:00 Roberto Romero <sildurin@gmail.com>:
El 03/15/2018 a las 02:52 PM, Victor Shepelev escribió:
> It doesn't treat / as a start of Regexp when I use 2.to_f(). That is
inconsistent.
Try this:
2.to_f +1
2.to_f + 1
2.to_f() +1
This is not "inconsistent", but a conscious tradeoff of "forgiving"
grammar (e.g. one where you can use or omit parens, use or omit spaces and
so on). However smart parser is, sometimes you need just stop trying to
solve all the weird cases and go with the most reasonable guess.
And no, change in parsing because of parens is NOT inconsistency, it is a
feature allowing go with simplest possible code in simple cases and use
parens to clarify meaning in more complicated ones.
For example, this is also "inconsistent" speaking in your words:
p (1..3).map { |i| i.to_s }
# => ["1", "2", "3"]
p (1..3).map do |i| i.to_s end
# => #<Enumerator: 1..3:map>
p((1..3).map do |i| i.to_s end)
# => ["1", "2", "3"]
That's just how things are here.
And anyway, I don't understand what you are trying to prove.
Is it "Ruby is bad for having this not working"? -- then go to
https://bugs.ruby-lang.org/ and write it there. And prepare to discuss
your position and prove it should work another way around.
It is this case.
Or is it just "You, Victor, is wrong, stop saying it is not a bug"? --
OK, I am giving up. Who am I to try explaining to people who don't want any
explanations?..
But also it is "You, Victor, stop saying ruby fails because omitting a
space is bad code. It is not bad code." If ruby decides /(1.to_f * (100 /
100)) is a malformed regexp, I think it should do decide it always, no
matter what's on the left of that, being 2, 2.to_f or var_name. It is
confusing. Anyways, yes, this may not be the place to discuss that.
Just out of curiosity, is this also how things are here?:
puts defined?(hello).class;if false;hello=1;end;puts defined?(hello).class
--
Roberto Romero
Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>