Forum: Ruby Whaaaaat?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D15a45a973443d4562051eb675b60474?d=identicon&s=25 Tom Cloyd (Guest)
on 2009-05-13 01:39
(Received via mailing list)
p [0..5].include? 0
false
p [0..5].member? 0
false

This is nuts. The world is flat, evidently.

Can someone explain this nonsense?

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D15a45a973443d4562051eb675b60474?d=identicon&s=25 Tom Cloyd (Guest)
on 2009-05-13 01:44
(Received via mailing list)
Tom Cloyd wrote:
>
Sorry - inadequate details: running ruby 1.8.7 (2008-08-11 patchlevel
72) [i486-linux]

 t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
90a73d9875462aaa9fab2feffafbffe7?d=identicon&s=25 Ben Bleything (Guest)
on 2009-05-13 01:45
(Received via mailing list)
On Tue, May 12, 2009 at 4:39 PM, Tom Cloyd <tomcloyd@comcast.net> wrote:
> p [0..5].include? 0
> false
> p [0..5].member? 0
> false
>
> This is nuts. The world is flat, evidently.

Nope.

> Can someone explain this nonsense?

Yep.  You've got an array with a single member... the range 0..5.

I think what you meant is:

  (0..5).include? 0
  => true

:)

Ben
4feed660d3728526797edeb4f0467384?d=identicon&s=25 Bill Kelly (Guest)
on 2009-05-13 01:49
(Received via mailing list)
From: "Tom Cloyd" <tomcloyd@comcast.net>
>
> p [0..5].include? 0
> false
> p [0..5].member? 0
> false
>
> This is nuts. The world is flat, evidently.
>
> Can someone explain this nonsense?

Same reason as this:

>> ["hello world"].include? "hell"
=> false


We're asking whether the array contains a particular
object.


Regards,

bill
Ca8efd0ba834b02b9b7dd34b5c6c2721?d=identicon&s=25 Kirk Haines (Guest)
on 2009-05-13 01:54
(Received via mailing list)
On Tue, May 12, 2009 at 5:39 PM, Tom Cloyd <tomcloyd@comcast.net> wrote:
> p [0..5].include? 0
> false
> p [0..5].member? 0
> false
>
> This is nuts. The world is flat, evidently.
>
> Can someone explain this nonsense?

[0..5] is an array with a single element, a Range object representing
the range from 0 to 5.

(0..5).to_a gives you [0,1,2,3,4,5] which is probably what you assumed
you got with [0..5]

(0..5).include?(0) will work, as well, because ranges support the
include? method.


Kirk Haines
D15a45a973443d4562051eb675b60474?d=identicon&s=25 Tom Cloyd (Guest)
on 2009-05-13 01:58
(Received via mailing list)
Ben Bleything wrote:
> Nope.
>   => true
>
> :)
>
> Ben
>
>
>
Well, nuts.

This clarifies it a bit:

irb(main):009:0> (1..10).class
=> Range
irb(main):010:0> [1..10].class
=> Array
irb(main):011:0>

Why can't ruby just do what I mean, rather than what I say? Is that
asking too much? (heh heh)

Thanks for the clarifications. This list has not equal for speedy
answers (usually).

t.



--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D15a45a973443d4562051eb675b60474?d=identicon&s=25 Tom Cloyd (Guest)
on 2009-05-13 02:05
(Received via mailing list)
Kirk Haines wrote:
>>
>
> Kirk Haines
>
>
>
Thanks, Kirk. That's the best answer yet. Very helpful.

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
703fbc991fd63e0e1db54dca9ea31b53?d=identicon&s=25 Robert Dober (Guest)
on 2009-05-13 03:15
(Received via mailing list)
On Wed, May 13, 2009 at 1:57 AM, Tom Cloyd <tomcloyd@comcast.net> wrote:
> Why can't ruby just do what I mean, rather than what I say? Is that asking
> too much? (heh heh)
But it does, I am sure you just forgot the *, right?
[*0..5].include? 42
--> false
Cheers
Robert
D15a45a973443d4562051eb675b60474?d=identicon&s=25 Tom Cloyd (Guest)
on 2009-05-13 03:35
(Received via mailing list)
Robert Dober wrote:
>
>
>
Robert,

Interesting, but obscure. I just did a quick dig into Thomas (Pickaxe,
3rd ed.), to try to figure out what [*1..5] does, and I still don't get
it. Can you explain?

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
289cf19aa581c445915c072bf45c5e25?d=identicon&s=25 Todd Benson (Guest)
on 2009-05-13 04:03
(Received via mailing list)
On Tue, May 12, 2009 at 8:34 PM, Tom Cloyd <tomcloyd@comcast.net> wrote:
>> But it does, I am sure you just forgot the *, right?
> Interesting, but obscure. I just did a quick dig into Thomas (Pickaxe, 3rd
> ed.), to try to figure out what [*1..5] does, and I still don't get it. Can
> you explain?

The"pre-appending" (yes I'm aware that's not a word or proper
conjuction) _star_ flattens arrays/ranges.  Well, not exactly; it
allows you to use a "list" of things.  Some people avoid it because of
a supposed performance issue.  Pick your battle, I guess.

It happens to be useful to me.  I really hope they don't get rid of
that nomenclature (much like getting rid of #inject; if so, goodbye
Ruby for me).

Todd
703fbc991fd63e0e1db54dca9ea31b53?d=identicon&s=25 Robert Dober (Guest)
on 2009-05-13 10:51
(Received via mailing list)
On Wed, May 13, 2009 at 4:02 AM, Todd Benson <caduceass@gmail.com>
wrote:
>>>
>>
> that nomenclature (much like getting rid of #inject; if so, goodbye
> Ruby for me).
I do not believe I have ever heard of that intention, if they get rid
of *0..3 than there is nothing one can do, if they get rid of inject
we will just reimplement it ;)
Robert


--
Si tu veux construire un bateau ...
Ne rassemble pas des hommes pour aller chercher du bois, préparer des
outils, répartir les tâches, alléger le travail… mais enseigne aux
gens la nostalgie de l’infini de la mer.

If you want to build a ship, don’t herd people together to collect
wood and don’t assign them tasks and work, but rather teach them to
long for the endless immensity of the sea.
Fd22ee3cfc7dac283ce8e451af324f7d?d=identicon&s=25 Chad Perrin (Guest)
on 2009-05-13 17:38
(Received via mailing list)
On Wed, May 13, 2009 at 11:02:45AM +0900, Todd Benson wrote:
>
> The"pre-appending" (yes I'm aware that's not a word or proper
> conjuction) _star_ flattens arrays/ranges.  Well, not exactly; it

I'm pretty sure the word you want is either "prefixing" or, if you like
the hypercorrect neologism, "prepending".
Eacf5ed623e72db0b87707baabd6f21a?d=identicon&s=25 Adam Gardner (adamgardner)
on 2009-05-13 18:44
Chad Perrin wrote:
> On Wed, May 13, 2009 at 11:02:45AM +0900, Todd Benson wrote:
>>
>> The"pre-appending" (yes I'm aware that's not a word or proper
>> conjuction) _star_ flattens arrays/ranges.  Well, not exactly; it
>
> I'm pretty sure the word you want is either "prefixing" or, if you like
> the hypercorrect neologism, "prepending".

Hrm. I had always thought of 'prepend' as a commonplace, dictionary
word, and was about to point out that it was such, until I accidentally
looked it. Neologismtastic!
D15a45a973443d4562051eb675b60474?d=identicon&s=25 Tom Cloyd (Guest)
on 2009-05-14 01:25
(Received via mailing list)
Adam Gardner wrote:
>
> Hrm. I had always thought of 'prepend' as a commonplace, dictionary
> word, and was about to point out that it was such, until I accidentally
> looked it. Neologismtastic!
>
Actually, this is all unnecessary. In linguistics, for eons, we have
spoken of prefix and suffix usage, So, this is a prefix asterisk, as in
"...the meaning of this prefix asterisk is blah blah...". That says it
just fine, with no new language. Travel light.

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (candlerb)
on 2009-05-14 12:34
Todd Benson wrote:
> It happens to be useful to me.  I really hope they don't get rid of
> that nomenclature (much like getting rid of #inject; if so, goodbye
> Ruby for me).

I never heard any proposal to get rid of Enumberable#inject, and I don't
think it's something you need to worry about. Ruby 1.9 has been adding
hundreds of new methods, not taking them away.
C1b6b5557723c9db912b075e954166d3?d=identicon&s=25 Jeff Moore (djief)
on 2009-05-14 20:05
Brian Candler wrote:
> Todd Benson wrote:
>> It happens to be useful to me.  I really hope they don't get rid of
>> that nomenclature (much like getting rid of #inject; if so, goodbye
>> Ruby for me).
>
> I never heard any proposal to get rid of Enumberable#inject, and I don't
> think it's something you need to worry about. Ruby 1.9 has been adding
> hundreds of new methods, not taking them away.

1.9.1 adds Enumerable#reduce as synonym (which makes more sense to me)
and
still retains inject
15f985dc1d6a150767736a0c65e9ef35?d=identicon&s=25 Jeremy Henty (Guest)
on 2009-05-15 13:26
(Received via mailing list)
On 2009-05-14, Jeff Moore <jcmoore@pressenter.com> wrote:

> 1.9.1 adds  Enumerable#reduce as synonym (which makes  more sense to
> me) and still retains inject

Is one of #reduce or #inject deprecated in 1.9.1?

Regards,

Jeremy Henty
8f6f95c4bd64d5f10dfddfdcd03c19d6?d=identicon&s=25 Rick Denatale (rdenatale)
on 2009-05-15 14:52
(Received via mailing list)
On Fri, May 15, 2009 at 7:25 AM, Jeremy Henty <onepoint@starurchin.org>
wrote:
> On 2009-05-14, Jeff Moore <jcmoore@pressenter.com> wrote:
>
>> 1.9.1 adds  Enumerable#reduce as synonym (which makes  more sense to
>> me) and still retains inject
>
> Is one of #reduce or #inject deprecated in 1.9.1?

Don't think so.

Actually IMHO which makes more sense is situational. To me reduce
makes sense when the optional initial argument is not used, and inject
makes more sense when it is:

collection.reduce {|memo, element| ...}
vs
collection.inject(initial_value) {|memo, element| ...}

Several of the Enumerable method names were pretty obviously inspired
by the Smalltalk collection hierarcy, select, detect, reject, and
inject among them.  The Smalltalk method is inject:info: which makes
the meaning of inject a bit clearer, in Smalltalk you would write the
second example as:

  collection inject: initialValue into: [memo, element| ...]

You are injecting the initialValue into the sequence given to the block.

And there are other instances of long-standing aliases like find for
detect.

Personally I think it's good to have such synonyms, they make it
easier to be express subtleties just as they do for authors in natural
languages.

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
703fbc991fd63e0e1db54dca9ea31b53?d=identicon&s=25 Robert Dober (Guest)
on 2009-05-15 15:29
(Received via mailing list)
On Fri, May 15, 2009 at 2:51 PM, Rick DeNatale <rick.denatale@gmail.com>
wrote:
nt| ...}
> Personally I think it's good to have such synonyms, they make it
> easier to be express subtleties just as they do for authors in natural
> languages.
In my humble opinion I believe that having different words meaning the
same thing is not bad. It enables a certain ease to adapt our programs
slightly accordingly to slightly different cases. This is exactly what
they do for people expressing themselves in human idioms.

I guess that was what you meant, though I apologize for a certain lack
of subtlety.
;)
R.
149379873fe2cb70e550c6bff8fedd0c?d=identicon&s=25 Jeff Schwab (Guest)
on 2009-05-15 15:30
(Received via mailing list)
Rick DeNatale wrote:
> On Fri, May 15, 2009 at 7:25 AM, Jeremy Henty <onepoint@starurchin.org> wrote:
>> On 2009-05-14, Jeff Moore <jcmoore@pressenter.com> wrote:
>>
>>> 1.9.1 adds  Enumerable#reduce as synonym (which makes  more sense to
>>> me) and still retains inject
>> Is one of #reduce or #inject deprecated in 1.9.1?
>
> Don't think so.
>
> Actually IMHO which makes more sense is situational.

Really?  I never heard of "inject" in any other language.  It was always
"reduce" to me.  I got the impression that "inject" was just a cutesy
way of making the method name similar to detect, select, collect, and
reject.
8f6f95c4bd64d5f10dfddfdcd03c19d6?d=identicon&s=25 Rick Denatale (rdenatale)
on 2009-05-15 16:11
(Received via mailing list)
On Fri, May 15, 2009 at 9:30 AM, Jeff Schwab <jeff@schwabcenter.com>
wrote:
>>> Is one of #reduce or #inject deprecated in 1.9.1?
>>
>> Don't think so.
>>
>> Actually IMHO which makes more sense is situational.
>
> Really?  I never heard of "inject" in any other language.  It was always
> "reduce" to me.  I got the impression that "inject" was just a cutesy way of
> making the method name similar to detect, select, collect, and reject.

So did you stop reading my reply at that point?

And if you want to let languages vote on what the 'correct' name
should be maybe it should be fold:

http://en.wikipedia.org/wiki/Fold_(higher-order_fu...

Fold gets 8 'votes',
Reduce gets 7, but that's counting ruby's afterthought, and Python
twice since it changed slightly between Python 2.x and 3.x so maybe
that should only be 5 'votes'
Inject gets 'votes' from Smalltalk and Ruby

Either reduce or inject is probably the earliest though.  Probably
reduce since that's what Common Lisp uses, BUT CL is a tad newer than
Smalltalk, and I'm not sure where in Lisp's long evolution from Lisp
1.5 reduce came into common usage.  I'm a bit perturbed that I can't
seem to find my copy of the Lisp 1.5 Programmers Manual which is
probably buried somewhere in my attic.

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
C1b6b5557723c9db912b075e954166d3?d=identicon&s=25 Jeff Moore (djief)
on 2009-05-15 17:03
Jeremy Henty wrote:
> On 2009-05-14, Jeff Moore <jcmoore@pressenter.com> wrote:
>
>> 1.9.1 adds  Enumerable#reduce as synonym (which makes  more sense to
>> me) and still retains inject
>
> Is one of #reduce or #inject deprecated in 1.9.1?
>
> Regards,
>
> Jeremy Henty

The RI entry has no preference or deprecation statement.

Regards,

jcm
149379873fe2cb70e550c6bff8fedd0c?d=identicon&s=25 Jeff Schwab (Guest)
on 2009-05-15 17:20
(Received via mailing list)
Rick DeNatale wrote:
>>>
>>> Actually IMHO which makes more sense is situational.
>> Really?  I never heard of "inject" in any other language.  It was always
>> "reduce" to me.  I got the impression that "inject" was just a cutesy way of
>> making the method name similar to detect, select, collect, and reject.
>
> So did you stop reading my reply at that point?

No, but I did somehow have a brain fart.  Apologies.

> And if you want to let languages vote on what the 'correct' name
> should be

It's not a question of correctness.  Both inject and reduce are clearly
correct in their own context.  It's purely a matter of clarity.

> maybe it should be fold:

When I've seen "fold" it has meant something completely different,
despite what Wikipedia says.  I'm not claiming right or wrong here, just
relating my own experience.  There's no need for you to take offense,
nor to reply with such an arrogant and condescending tone.
Fd22ee3cfc7dac283ce8e451af324f7d?d=identicon&s=25 Chad Perrin (Guest)
on 2009-05-15 17:38
(Received via mailing list)
On Sat, May 16, 2009 at 12:20:03AM +0900, Jeff Schwab wrote:
> Rick DeNatale wrote:
>
> >maybe it should be fold:
>
> When I've seen "fold" it has meant something completely different,
> despite what Wikipedia says.  I'm not claiming right or wrong here, just
> relating my own experience.  There's no need for you to take offense,
> nor to reply with such an arrogant and condescending tone.

I didn't see any arrogance or condescension.  Where did you see it?
8f6f95c4bd64d5f10dfddfdcd03c19d6?d=identicon&s=25 Rick Denatale (rdenatale)
on 2009-05-15 19:04
(Received via mailing list)
On Fri, May 15, 2009 at 11:37 AM, Chad Perrin <perrin@apotheon.com>
wrote:
> On Sat, May 16, 2009 at 12:20:03AM +0900, Jeff Schwab wrote:
>> Rick DeNatale wrote:

  Something.

>> There's no need for you to take offense,
>> nor to reply with such an arrogant and condescending tone.
>
> I didn't see any arrogance or condescension.  Where did you see it?

Certainly, with all humility, none was intended.

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
149379873fe2cb70e550c6bff8fedd0c?d=identicon&s=25 Jeff Schwab (Guest)
on 2009-05-15 19:56
(Received via mailing list)
Rick DeNatale wrote:
> On Fri, May 15, 2009 at 11:37 AM, Chad Perrin <perrin@apotheon.com> wrote:
>> On Sat, May 16, 2009 at 12:20:03AM +0900, Jeff Schwab wrote:
>>> Rick DeNatale wrote:
>
>   Something.
>
>>> There's no need for you to take offense,
>>> nor to reply with such an arrogant and condescending tone.
>> I didn't see any arrogance or condescension.  Where did you see it?

I said, effectively, "that terminology is new to me."  The
interpretation was apparently "you're making that up," and the response
was "you're wrong, and I'll prove it."

> Certainly, with all humility, none was intended.

My mistake.
This topic is locked and can not be replied to.