J
Joshua Ballanco
=20
=20
What exactly is it you think I'm "incorrect" about?
I apologize, but I feel the need to interject:
http://xkcd.com/386/
...that is all.
- Josh=
=20
=20
What exactly is it you think I'm "incorrect" about?
I apologize, but I feel the need to interject:
http://xkcd.com/386/
...that is all.
- Josh=
Tony said:What exactly is it you think I'm "incorrect" about?
The last assertion you made about the ++ operator. Read the recent
posts from Seebs and others. Make sure you understand them.
Never mind, bar= was still defined because I was reopening the class.
I suppose the whole discussion is moot as Ruby will likely never see a ++
operator.
I was just trying to make clear the limitation wasn't a technical one, and
further show how a ++ operator could be "Ruby-like" while still retaining
C/C++/Java-like semantics.
Dude, you just about gave me a heart attack. Phewsh - sanity is
restored.
If implementing ++ requires changes to the parser, that seems like a
pretty technical limitation to me!
BTW in all your posts on the topic, you don't seem to address pre-
increment vs post-incrememt. (Forgive me if I'm wrong.) If Ruby
implemented ++ and didn't address that, it wouldn't be C or C++
semantics at all.
Tony said:That's a can of worms I've been trying to avoid, as there are lexing/parsing
ambiguities surrounding the combination of both. How do you parse a+++b vs
a++++b vs a+++++b?
The only sane answer is to do what C does, as far as parsing.
But the deeper problem in ruby is what do pre- and post- really mean?
Really?
In C there are expressions and there are other constructs,
so we can define natural boundaries for pre and post in terms of
expressions. In ruby we have mostly expressions.
So the hard questions are "before what?" and "after what?"
Does
foo {x++}
yield the incremented x to foo, or the original x?
What if foo yields several times? Increment once, or once per iteration?
What about
x = 0
y = case; when true; x++; end
Is y 0 or 1?
0
It's kind of an ink-blot test for what you think "expression" means, but of
course everything is an expression in ruby.
It's not an answer to say
'x++' should have the same effect as 'x+=1'
because that's not even true in C.
Noob question: What does that mean?
Really?
Correct, it's ++x that would have the same effect as x += 1, not that I
find
the preincrementation vs postincrementation distinction particularly
useful
in Ruby,
which is why I've advocated picking the canonical one
and going
with that, even though preincrementation has semantics which would make
more
sense in Ruby.
I'm trying to be pragmatic...
and yet being dismissed out of hand.
Because
it is not Ruby-like! According to certain people's definitions of
"Ruby-like"...
That's a can of worms I've been trying to avoid, as there are lexing/parsing
ambiguities surrounding the combination of both. How do you parse a+++b vs
a++++b vs a+++++b?
Does
foo {x++}
yield the incremented x to foo, or the original x? What if foo yields
several times? Increment once, or once per iteration?
What about
x = 0
y = case; when true; x++; end
Is y 0 or 1?
It's not an answer to say
'x++' should have the same effect as 'x+=1'
because that's not even true in C.
Marnen said:The fact that it would require major parser and language changes is a
pretty good indication that it is not in keeping with the nature of the
language...
Best,
[Note: parts of this message were removed to make it a legal post.]
The only sane answer is to do what C does, as far as parsing.
You will find the answer to these edge cases varies.
Ruby is a pure expression-based language (and I see you acknowledge that
later in this message). There are no statements which don't return a value.
Correct, it's ++x that would have the same effect as x += 1, not that I find
the preincrementation vs postincrementation distinction particularly useful
in Ruby, which is why I've advocated picking the canonical one and going
with that, even though preincrementation has semantics which would make more
sense in Ruby.
Where's the benefit? What is some actual Ruby code that would be
improved by these constructs?
Seebs said:blahblahblah.each do |args|
lots of stuff lots of stuff
if condition
count += 1
end
end
I'd rather see "++count". It's easier for me to read.
Would you? Or would you rather see
count = blahblahblah.count do |args|
lots_of_stuff
condition
end
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.