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.
Tom C. (Guest)
on 2009-05-13 03: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 C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom C. (Guest)
on 2009-05-13 03:44
(Received via mailing list)
Tom C. wrote:
>
Sorry - inadequate details: running ruby 1.8.7 (2008-08-11 patchlevel
72) [i486-linux]

 t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ben B. (Guest)
on 2009-05-13 03:45
(Received via mailing list)
On Tue, May 12, 2009 at 4:39 PM, Tom C. <removed_email_address@domain.invalid> 
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
Bill K. (Guest)
on 2009-05-13 03:49
(Received via mailing list)
From: "Tom C." <removed_email_address@domain.invalid>
>
> 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
Kirk H. (Guest)
on 2009-05-13 03:54
(Received via mailing list)
On Tue, May 12, 2009 at 5:39 PM, Tom C. <removed_email_address@domain.invalid> 
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 H.
Tom C. (Guest)
on 2009-05-13 03:58
(Received via mailing list)
Ben B. 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 C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom C. (Guest)
on 2009-05-13 04:05
(Received via mailing list)
Kirk H. wrote:
>>
>
> Kirk H.
>
>
>
Thanks, Kirk. That's the best answer yet. Very helpful.

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Robert D. (Guest)
on 2009-05-13 05:15
(Received via mailing list)
On Wed, May 13, 2009 at 1:57 AM, Tom C. <removed_email_address@domain.invalid> 
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
Tom C. (Guest)
on 2009-05-13 05:35
(Received via mailing list)
Robert D. 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 C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Todd B. (Guest)
on 2009-05-13 06:03
(Received via mailing list)
On Tue, May 12, 2009 at 8:34 PM, Tom C. <removed_email_address@domain.invalid> 
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
Robert D. (Guest)
on 2009-05-13 12:51
(Received via mailing list)
On Wed, May 13, 2009 at 4:02 AM, Todd B. <removed_email_address@domain.invalid>
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.
Chad P. (Guest)
on 2009-05-13 19:38
(Received via mailing list)
On Wed, May 13, 2009 at 11:02:45AM +0900, Todd B. 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".
Adam G. (Guest)
on 2009-05-13 20:44
Chad P. wrote:
> On Wed, May 13, 2009 at 11:02:45AM +0900, Todd B. 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!
Tom C. (Guest)
on 2009-05-14 03:25
(Received via mailing list)
Adam G. 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 C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Brian C. (Guest)
on 2009-05-14 14:34
Todd B. 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.
Jeff M. (Guest)
on 2009-05-14 22:05
Brian C. wrote:
> Todd B. 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
Jeremy H. (Guest)
on 2009-05-15 15:26
(Received via mailing list)
On 2009-05-14, Jeff M. <removed_email_address@domain.invalid> 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 H.
Rick D. (Guest)
on 2009-05-15 16:52
(Received via mailing list)
On Fri, May 15, 2009 at 7:25 AM, Jeremy H. 
<removed_email_address@domain.invalid>
wrote:
> On 2009-05-14, Jeff M. <removed_email_address@domain.invalid> 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
Robert D. (Guest)
on 2009-05-15 17:29
(Received via mailing list)
On Fri, May 15, 2009 at 2:51 PM, Rick DeNatale 
<removed_email_address@domain.invalid>
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.
Jeff S. (Guest)
on 2009-05-15 17:30
(Received via mailing list)
Rick DeNatale wrote:
> On Fri, May 15, 2009 at 7:25 AM, Jeremy H. <removed_email_address@domain.invalid> wrote:
>> On 2009-05-14, Jeff M. <removed_email_address@domain.invalid> 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.
Rick D. (Guest)
on 2009-05-15 18:11
(Received via mailing list)
On Fri, May 15, 2009 at 9:30 AM, Jeff S. <removed_email_address@domain.invalid>
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
Jeff M. (Guest)
on 2009-05-15 19:03
Jeremy H. wrote:
> On 2009-05-14, Jeff M. <removed_email_address@domain.invalid> 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 H.

The RI entry has no preference or deprecation statement.

Regards,

jcm
Jeff S. (Guest)
on 2009-05-15 19: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.
Chad P. (Guest)
on 2009-05-15 19:38
(Received via mailing list)
On Sat, May 16, 2009 at 12:20:03AM +0900, Jeff S. 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?
Rick D. (Guest)
on 2009-05-15 21:04
(Received via mailing list)
On Fri, May 15, 2009 at 11:37 AM, Chad P. <removed_email_address@domain.invalid>
wrote:
> On Sat, May 16, 2009 at 12:20:03AM +0900, Jeff S. 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
Jeff S. (Guest)
on 2009-05-15 21:56
(Received via mailing list)
Rick DeNatale wrote:
> On Fri, May 15, 2009 at 11:37 AM, Chad P. <removed_email_address@domain.invalid> wrote:
>> On Sat, May 16, 2009 at 12:20:03AM +0900, Jeff S. 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.