Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Ruby doesn't implement x++ for Fixnum's because ???
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 101 - 125 of 157 - Collapse all  -  Translate all to Translated (View all originals) < Older  Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Tony Arcieri  
View profile  
 More options Nov 8, 3:26 pm
Newsgroups: comp.lang.ruby
From: Tony Arcieri <t...@medioh.com>
Date: Sun, 8 Nov 2009 15:26:14 -0500
Local: Sun, Nov 8 2009 3:26 pm
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???
[Note:  parts of this message were removed to make it a legal post.]

On Sun, Nov 8, 2009 at 1:15 PM, Walton Hoops <wal...@vyper.hopto.org> wrote:
> Incorrect. In fact the very first message in this thread provided an
> example of redifining Fixnum in such a way that it was mutable.

No it didn't, that post created a new class called "FixNum"

And again, that's beside the point, which is to allow the expected "++"
semantics for immutable Numerics while also allowing in-place incrementation
for other classes which may store a mutable value, such as counters (whose
backing store may be a database, memcache, etc)

That would provide a truly Ruby-like ++ experience, aside from the fact you
can't redefine #++ for a Numeric, which probably isn't a good idea anyway.

--
Tony Arcieri
Medioh/Nagravision


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Walton Hoops  
View profile  
 More options Nov 8, 3:54 pm
Newsgroups: comp.lang.ruby
From: Walton Hoops <wal...@vyper.hopto.org>
Date: Sun, 8 Nov 2009 15:54:40 -0500
Local: Sun, Nov 8 2009 3:54 pm
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???

> -----Original Message-----
> From: basc...@gmail.com [mailto:basc...@gmail.com] On Behalf Of Tony
> No it didn't, that post created a new class called "FixNum"

I apologize, you are correct that post defined a new class, due to a
capitalization error, which was corrected a few posts down.

The point is, yes indeed, numerics can be mutable.  I could if I were
so inclined write a String backed subclass of Numeric which represtend
integers as Roman Numerals and was mutable, (or Fixnum backed if we're
 feeling boring).

> And again, that's beside the point, which is to allow the expected "++"
> semantics for immutable Numerics while also allowing in-place
> incrementation
> for other classes which may store a mutable value, such as counters
> (whosebacking store may be a database, memcache, etc)

But your missing the point that ++ is NOT expected. Not in Ruby. Ruby
simply doesn't work that way.  You talked about "operator rebinding",
but you ignored the fact that ++ is nothing like those examples.

a+=<expression> expands to a=a+<expression>.  It's a simple syntaxtic
sugar. a++ expands to... what? Nothing.  There is no way you could
expand puts foo(a++,b) and get the desired behavior.

This discussion has gone on and on, and it's really quite pointless.
There is no good reason to include ++ in Ruby, and every reason not to.
No one can even agree on what they would expect a ++ operator to do when
used "The Ruby Way", with C programmers expecting it to work like C, and
the Rubyists expecting it to follow the Ruby way, with every operator
being a method call on that object (NOT variable).

So why introduce this operator into the language that would cause all
this confusion, when all it will do is save a few C programmers a SINGLE
line of code. 95% of the time it won't even do that, if they would
learn and do things the Ruby way, rather than trying to write C code in
Ruby.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Florian Aßmann  
View profile  
 More options Nov 8, 4:30 pm
Newsgroups: comp.lang.ruby
From: Florian Aßmann <florian.assm...@email.de>
Date: Sun, 8 Nov 2009 16:30:53 -0500
Local: Sun, Nov 8 2009 4:30 pm
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???
Gaah, close this thread! ;)

Cheers
Florian

Am 08.11.2009 um 21:26 schrieb Tony Arcieri:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marnen Laibow-Koser  
View profile  
 More options Nov 8, 4:40 pm
Newsgroups: comp.lang.ruby
From: Marnen Laibow-Koser <mar...@marnen.org>
Date: Sun, 8 Nov 2009 16:40:35 -0500
Local: Sun, Nov 8 2009 4:40 pm
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???

Florian Aßmann wrote:
> Gaah, close this thread! ;)

I don't think there's a mechanism for doing that, since this is an
unmoderated list.  You don't have to follow it if you don't want to. :)

> Cheers
> Florian

> Am 08.11.2009 um 21:26 schrieb Tony Arcieri:

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
--
Posted via http://www.ruby-forum.com/.

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tony Arcieri  
View profile  
 More options Nov 8, 5:44 pm
Newsgroups: comp.lang.ruby
From: Tony Arcieri <t...@medioh.com>
Date: Sun, 8 Nov 2009 17:44:37 -0500
Local: Sun, Nov 8 2009 5:44 pm
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???
On Sun, Nov 8, 2009 at 2:30 PM, Florian Aßmann <florian.assm...@email.de>wrote:

> Gaah, close this thread! ;)

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.

--
Tony Arcieri
Medioh/Nagravision


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marnen Laibow-Koser  
View profile  
 More options Nov 8, 5:49 pm
Newsgroups: comp.lang.ruby
From: Marnen Laibow-Koser <mar...@marnen.org>
Date: Sun, 8 Nov 2009 17:49:39 -0500
Local: Sun, Nov 8 2009 5:49 pm
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???

And as others have made clear, you are incorrect.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
--
Posted via http://www.ruby-forum.com/.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tony Arcieri  
View profile  
 More options Nov 8, 6:01 pm
Newsgroups: comp.lang.ruby
From: Tony Arcieri <t...@medioh.com>
Date: Sun, 8 Nov 2009 18:01:43 -0500
Local: Sun, Nov 8 2009 6:01 pm
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???
[Note:  parts of this message were removed to make it a legal post.]

On Sun, Nov 8, 2009 at 3:49 PM, Marnen Laibow-Koser <mar...@marnen.org>wrote:

> And as others have made clear, you are incorrect.

What exactly is it you think I'm "incorrect" about?

--
Tony Arcieri
Medioh/Nagravision


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joshua Ballanco  
View profile  
 More options Nov 8, 6:51 pm
Newsgroups: comp.lang.ruby
From: Joshua Ballanco <jball...@gmail.com>
Date: Sun, 8 Nov 2009 18:51:00 -0500
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???
On Nov 8, 2009, at 3:01 PM, Tony Arcieri wrote:

> On Sun, Nov 8, 2009 at 3:49 PM, Marnen Laibow-Koser <mar...@marnen.org>wrote:

>> And as others have made clear, you are incorrect.

> 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


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marnen Laibow-Koser  
View profile  
 More options Nov 8, 7:02 pm
Newsgroups: comp.lang.ruby
From: Marnen Laibow-Koser <mar...@marnen.org>
Date: Sun, 8 Nov 2009 19:02:45 -0500
Local: Sun, Nov 8 2009 7:02 pm
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???

Tony Arcieri wrote:
> On Sun, Nov 8, 2009 at 3:49 PM, Marnen Laibow-Koser
> <mar...@marnen.org>wrote:

>> And as others have made clear, you are incorrect.

> 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.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org

--
Posted via http://www.ruby-forum.com/.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tony Arcieri  
View profile  
 More options Nov 8, 9:40 pm
Newsgroups: comp.lang.ruby
From: Tony Arcieri <t...@medioh.com>
Date: Sun, 8 Nov 2009 21:40:15 -0500
Local: Sun, Nov 8 2009 9:40 pm
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???
[Note:  parts of this message were removed to make it a legal post.]

On Sun, Nov 8, 2009 at 5:02 PM, Marnen Laibow-Koser <mar...@marnen.org>wrote:

> The last assertion you made about the ++ operator.  Read the recent
> posts from Seebs and others.  Make sure you understand them.

I read and responded to them.  Was there something about my responses you
didn't like, aside from my initial confusion with a dangling method from a
previously defined class? :)

--
Tony Arcieri
Medioh/Nagravision


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tony Arcieri  
View profile  
 More options Nov 8, 10:11 pm
Newsgroups: comp.lang.ruby
From: Tony Arcieri <t...@medioh.com>
Date: Sun, 8 Nov 2009 22:11:12 -0500
Local: Sun, Nov 8 2009 10:11 pm
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???
[Note:  parts of this message were removed to make it a legal post.]

On Sun, Nov 8, 2009 at 4:51 PM, Joshua Ballanco <jball...@gmail.com> wrote:
> I apologize, but I feel the need to interject:

> http://xkcd.com/386/

I still find this most appropriate:

http://bit.ly/w8WZA

--
Tony Arcieri
Medioh/Nagravision


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Phrogz  
View profile  
 More options Nov 8, 10:37 pm
Newsgroups: comp.lang.ruby
From: Phrogz <phr...@mac.com>
Date: Sun, 8 Nov 2009 19:37:00 -0800 (PST)
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???
On Nov 8, 12:37 pm, Tony Arcieri <t...@medioh.com> wrote:

> On Sun, Nov 8, 2009 at 12:32 PM, Tony Arcieri <t...@medioh.com> wrote:
> > I cannot begin to answer this question because Ruby is doing strange and
> > unexpected things here, at least from my perspective...

> Never mind, bar= was still defined because I was reopening the class.

Dude, you just about gave me a heart attack. Phewsh - sanity is
restored.

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gavin Sinclair  
View profile  
 More options Nov 8, 10:48 pm
Newsgroups: comp.lang.ruby
From: Gavin Sinclair <gsincl...@gmail.com>
Date: Sun, 8 Nov 2009 19:48:25 -0800 (PST)
Local: Sun, Nov 8 2009 10:48 pm
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???
On Nov 9, 9:44 am, Tony Arcieri <t...@medioh.com> wrote:

> 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.

If implementing ++ requires changes to the parser, that seems like a
pretty technical limitation to me! :)

Matter of interpretation?

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.

--
Gavin Sinclair


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tony Arcieri  
View profile  
 More options Nov 8, 10:51 pm
Newsgroups: comp.lang.ruby
From: Tony Arcieri <t...@medioh.com>
Date: Sun, 8 Nov 2009 22:51:50 -0500
Local: Sun, Nov 8 2009 10:51 pm
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???
[Note:  parts of this message were removed to make it a legal post.]

On Sun, Nov 8, 2009 at 8:40 PM, Phrogz <phr...@mac.com> wrote:
> Dude, you just about gave me a heart attack. Phewsh - sanity is
> restored.

My bad, it will serve as a reminder to double check my work before posting
:)

--
Tony Arcieri
Medioh/Nagravision


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tony Arcieri  
View profile  
 More options Nov 8, 11:00 pm
Newsgroups: comp.lang.ruby
From: Tony Arcieri <t...@medioh.com>
Date: Sun, 8 Nov 2009 23:00:31 -0500
Local: Sun, Nov 8 2009 11:00 pm
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???
[Note:  parts of this message were removed to make it a legal post.]

On Sun, Nov 8, 2009 at 8:50 PM, Gavin Sinclair <gsincl...@gmail.com> wrote:
> If implementing ++ requires changes to the parser, that seems like a
> pretty technical limitation to me! :)

Assuredly it would require changes to the parser, as "++" presently
lexes/parses as "plus (unary+ value)", and that's not to mention how it
parses in method definitions.  The resulting operation is equivalent to
binary +, unless you're using something like
Methodphitamine<http://jicksta.com/posts/the-methodphitamine>

> 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.

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?

--
Tony Arcieri
Medioh/Nagravision


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joel VanderWerf  
View profile  
 More options Nov 8, 11:54 pm
Newsgroups: comp.lang.ruby
From: Joel VanderWerf <vj...@path.berkeley.edu>
Date: Sun, 8 Nov 2009 23:54:25 -0500
Local: Sun, Nov 8 2009 11:54 pm
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???

Tony Arcieri wrote:
>> 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.

> 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? 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?

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.

--
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tony Arcieri  
View profile  
 More options Nov 9, 12:15 am
Newsgroups: comp.lang.ruby
From: Tony Arcieri <t...@medioh.com>
Date: Mon, 9 Nov 2009 00:15:33 -0500
Local: Mon, Nov 9 2009 12:15 am
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???
[Note:  parts of this message were removed to make it a legal post.]

On Sun, Nov 8, 2009 at 9:54 PM, Joel VanderWerf <vj...@path.berkeley.edu>wrote:

> The only sane answer is to do what C does, as far as parsing.

You will find the answer to these edge cases varies.  Fortunately they are
edge cases...

> 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,

As someone intimately familiar with the expression/statement barrier, I
really don't see the issue...

> so we can define natural boundaries for pre and post in terms of
> expressions. In ruby we have mostly expressions.

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.

> So the hard questions are "before what?" and "after what?"

> Does

>  foo {x++}

> yield the incremented x to foo, or the original x?

Well, to be pedantic, foo is yielding.  The return value of the block in
this case is original x.

> What if foo yields several times? Increment once, or once per iteration?

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.

Funny, earlier you implied there were things that aren't expressions 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.

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"...

--
Tony Arcieri
Medioh/Nagravision


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ralph Shnelvar  
View profile  
 More options Nov 9, 1:39 am
Newsgroups: comp.lang.ruby
From: Ralph Shnelvar <ral...@dos32.com>
Date: Mon, 9 Nov 2009 01:39:13 -0500
Local: Mon, Nov 9 2009 1:39 am
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???

> Never mind, bar= was still defined because I was reopening the class.

Noob question: What does that mean?

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tony Arcieri  
View profile  
 More options Nov 9, 1:44 am
Newsgroups: comp.lang.ruby
From: Tony Arcieri <t...@medioh.com>
Date: Mon, 9 Nov 2009 01:44:05 -0500
Local: Mon, Nov 9 2009 1:44 am
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???
[Note:  parts of this message were removed to make it a legal post.]

On Sun, Nov 8, 2009 at 11:39 PM, Ralph Shnelvar <ral...@dos32.com> wrote:
> > Never mind, bar= was still defined because I was reopening the class.

> Noob question: What does that mean?

Before defining either of the classes I described, I did this:

class Foo
  attr_accessor :bar

  ...
end

This meant Foo#bar= was defined already.  I forgot I did that, and thus my
results were, well, unexpected...

--
Tony Arcieri
Medioh/Nagravision


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marnen Laibow-Koser  
View profile  
 More options Nov 9, 6:36 am
Newsgroups: comp.lang.ruby
From: Marnen Laibow-Koser <mar...@marnen.org>
Date: Mon, 9 Nov 2009 06:36:47 -0500
Local: Mon, Nov 9 2009 6:36 am
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???
Tony Arcieri wrote:

[...]

>> But the deeper problem in ruby is what do pre- and post- really mean?

> Really?

Well, that's certainly one of the issues.

[...]

>> It's not an answer to say

>>  'x++' should have the same effect as 'x+=1'

>> because that's not even true in C.

> 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,

The "step through subscripts" use of ++ and -- is not useful in Ruby
because of the use of iterators.  The pre-/postincrement distinction is
not that useful because of the nature of the language.  So...why have ++
and -- at all if its two main advantages are not useful in Ruby?
Where's the benefit?  What is some actual Ruby code that would be
improved by these constructs?

> which is why I've advocated picking the canonical one

There is no one canonical one.  Pre and post are both canonical, and
that's the problem.

> and going
> with that, even though preincrementation has semantics which would make
> more
> sense in Ruby.

Um, what?

> I'm trying to be pragmatic...

What's pragmatic about grafting onto Ruby a feature which is useful in C
but not in Ruby?

Again, if you can think of an actual context where this would be useful
in Ruby, please provide actual code.

> and yet being dismissed out of hand.

You're not being dismissed out of hand.  You've been given numerous
reasons why this is not a great idea, which it seems that you keep on
ignoring.

> Because
> it is not Ruby-like!  According to certain people's definitions of
> "Ruby-like"...

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,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
--
Posted via http://www.ruby-forum.com/.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Seebs  
View profile  
 More options Nov 9, 8:15 am
Newsgroups: comp.lang.ruby
From: Seebs <usenet-nos...@seebs.net>
Date: 09 Nov 2009 13:15:19 GMT
Local: Mon, Nov 9 2009 8:15 am
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???
On 2009-11-09, Tony Arcieri <t...@medioh.com> wrote:

> 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?

Maximal munch.  Those are, in order:
        a++ + b
        a++ ++b (a syntax error)
        a++ ++ +b (also a syntax error)

But I think the more difficult issue is the semantics.

-s
--
Copyright 2009, all wrongs reversed.  Peter Seebach / usenet-nos...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Seebs  
View profile  
 More options Nov 9, 8:21 am
Newsgroups: comp.lang.ruby
From: Seebs <usenet-nos...@seebs.net>
Date: 09 Nov 2009 13:21:58 GMT
Local: Mon, Nov 9 2009 8:21 am
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???
On 2009-11-09, Joel VanderWerf <vj...@path.berkeley.edu> wrote:

> 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?

Postincrement should always produce the original value.

> What about

>    x = 0
>    y = case; when true; x++; end

> Is y 0 or 1?

0, of course.  postincrement gives the original value.  I would say that,
by the end of the assignment to y, x has taken the value 1, but what's yielded
by a postincrement is not the value of x, but a separate value which happens
to be the same as the value x used to have.

> It's not an answer to say

>    'x++' should have the same effect as 'x+=1'

> because that's not even true in C.

Right.  But that is (nearly always) what "++x" should mean.

Hmm.

Let us imagine that we were to make ++ a rebinding operator, like +=.  Not
just for Numerics, but always -- otherwise we lose the expected semantics.
Hmm.  This leads to an interesting point:

Since you can't modify the underlying object when it's immutable, it violates
POLS for ++ to ever modify the underlying object.  It would ALWAYS be a
rebinding to a new value.

The semantics of "++x" would indeed be exactly equivalent to "x += 1".  The
semantics of "x++" would be equivalent to
        magic_temporary_value = x
        x += 1
        magic_temporary_value

The question is...

Would this be useful enough to justify the hassle?  I'm not sold on it.
The postincrement form is really primarily useful for idioms that don't
make any sense in Ruby.  The preincrement form is actually sorta nice,
because it really is easier for me to read (I don't have to actually
think about whether the amount incremented by is really 1 or not).  I'm
not sure it's nice enough to justify the effort.

-s
--
Copyright 2009, all wrongs reversed.  Peter Seebach / usenet-nos...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aldric Giacomoni  
View profile  
 More options Nov 9, 8:30 am
Newsgroups: comp.lang.ruby
From: Aldric Giacomoni <ald...@trevoke.net>
Date: Mon, 9 Nov 2009 08:30:52 -0500
Local: Mon, Nov 9 2009 8:30 am
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???

Marnen Laibow-Koser wrote:
> Tony Arcieri wrote:

>> Because
>> it is not Ruby-like!  According to certain people's definitions of
>> "Ruby-like"...

> 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,
> --
> Marnen Laibow-Koser

I really do hesitate to speak, here, as I am not nearly as skilled in
Ruby, or C / C++, as the rest of you, but it seems to me that Matz
expressed his opinion on the matter already... :)

Also, in more productive terms:
"a += 1".size => 6
"a+=1".size => 4
"a++".size => 3
RubyForum::Thread.self.count_keystrokes => zomg !

On the other hand, it's also plain impossible to implement, for various
reasons listed numerous times prior to this humble message.

It seems to me that at this point, the next and only logical step is to
take the Ruby source code and go implement whatever you want to
implement.. Then come back with your own language, which may well be
called Lapis-Lazuli, and will allow the ++.
--
Posted via http://www.ruby-forum.com/.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Seebs  
View profile  
 More options Nov 9, 8:32 am
Newsgroups: comp.lang.ruby
From: Seebs <usenet-nos...@seebs.net>
Date: 09 Nov 2009 13:32:19 GMT
Local: Mon, Nov 9 2009 8:32 am
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???
On 2009-11-09, Tony Arcieri <t...@medioh.com> wrote:

> [Note:  parts of this message were removed to make it a legal post.]
> On Sun, Nov 8, 2009 at 9:54 PM, Joel VanderWerf <vj...@path.berkeley.edu>wrote:
>> The only sane answer is to do what C does, as far as parsing.
> You will find the answer to these edge cases varies.

No, you won't.  The parsing is 100% consistent and has been, so far as I
know, in every compiler released since the mid-70s.

> 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.

But "expressions" can be extremely large.

In C, "x++" yields the current value of x, and at some point between the
prior sequence point and the next sequence point, x gets incremented.
The reason that "i + i++" is *undefined behavior*, not just an unspecified
value, is that Deep Magic may occur to implement or support the
increment operators.  There's no particular guarantee -- none at all --
that such code even runs, let alone does anything specific.

That's fine.  C has "sequence points", and because expressions in C are
pretty simple and limited, you always have plenty.  Consider:

        for (i = 0; i < 10; ++i) {
                printf("%d\n", i);
        }

The evaluation of each of the control expressions in the for loop is
separated from everything else by sequence points.  There's a sequence point
between the evaluation of i for the printf and the actual execution of
printf, and another when printf is done, and so on.

Let's look at a while loop to simplify a bit:
        i = 0;
        while (i++ < 10) {
                printf("%d\n", i);
        }
In C, that should consistently yield the numbers 1 through 10.  (When i
is 0, i++ is < 10, but increments i, so printf sees 1.  When i is 9, i++
is 9, thus still < 10, but increments i, so printf sees 10.)

In Ruby, if you did something similar to this, you might write:
        i = 0
        while i++ < 10
                puts i
        end

When, exactly, do we expect that the increment happens?  This whole thing
is an expression.  I'm not aware of anything particularly equivalent to
sequence points.  Do we ensure that i is incremented before puts is called?
Consider that this whole block (while ... end) could be a single argument
to a function, because it's just an expression.

In short, the fact that control statements in Ruby are also expressions
makes it harder to run with the simple "by the end of the expression"
heuristic most people use.

Think about:

        puts i++ || i

In C, you'd have a nice solid guarantee that the increment happens before
the || (because &&/|| are sequence points).  Would you in Ruby?  I have no
clue.

> 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.

There's nothing particularly more canonical about postincrement.  It is
the one that's harder to replace by just writing something else.  I would
rather see both, personally.  In particular, it looks very much as though
postincrement would be expensive, so I'd want preincrement available so
I could actually use it.  :)

-s
--
Copyright 2009, all wrongs reversed.  Peter Seebach / usenet-nos...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Seebs  
View profile  
 More options Nov 9, 8:33 am
Newsgroups: comp.lang.ruby
From: Seebs <usenet-nos...@seebs.net>
Date: 09 Nov 2009 13:33:37 GMT
Local: Mon, Nov 9 2009 8:33 am
Subject: Re: Ruby doesn't implement x++ for Fixnum's because ???
On 2009-11-09, Marnen Laibow-Koser <mar...@marnen.org> wrote:

> Where's the benefit?  What is some actual Ruby code that would be
> improved by these constructs?

        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.

-s
--
Copyright 2009, all wrongs reversed.  Peter Seebach / usenet-nos...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 101 - 125 of 157 < Older  Newer >
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google