[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Tricky: converting path into a Hash

M. Edward (Ed) Borasky

1/22/2007 2:00:00 AM

Robert MannI wrote:
> Hello!
>
>
> I am wondering if the mighty ruby crowd has a brilliant idea for a tricky
> problem I am solving.
>
> I need to store a path as a tree in a hash.
>
> Given:
> a/b/c
>
> I want the Hash:
> { 'a' => { 'b' => { 'c' => { } } } }
> or written differently
> hsh['a']['b']['c'] = {}
>
> Is there an elegant solution to this, without maybe looping or
> eval'ing too
> much?
>
>
>
> Muchas Gracias Senoritas,
> Robert Mannl
>
There's a "natural" (tail) recursive solution to this if you've learned
Lisp or Scheme, and an easy translation to a "while" loop should
recursion be inefficient on your platform. I don't know of any "natural"
way to do it without recursion or iteration/looping, nor do I see any
need to introduce "eval" at all.

I would say the most "elegant" solution would be the obvious iterative
"while" loop translated into Ruby's iterators, since Ruby does not to my
knowledge support efficient tail recursion. But I'm not going to code it
for you. :)

--
M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)
http://borasky-research.blo...

If God had meant for carrots to be eaten cooked, He would have given rabbits fire.


85 Answers

Logan Capaldo

1/22/2007 2:23:00 AM

0

On Mon, Jan 22, 2007 at 10:59:44AM +0900, M. Edward (Ed) Borasky wrote:
> Robert MannI wrote:
> >Hello!
> >
> >
> >I am wondering if the mighty ruby crowd has a brilliant idea for a tricky
> >problem I am solving.
> >
> >I need to store a path as a tree in a hash.
> >
> >Given:
> >a/b/c
> >
> >I want the Hash:
> >{ 'a' => { 'b' => { 'c' => { } } } }
> >or written differently
> >hsh['a']['b']['c'] = {}
> >
> >Is there an elegant solution to this, without maybe looping or
> >eval'ing too
> >much?
> >
> >
> >
> >Muchas Gracias Senoritas,
> >Robert Mannl
> >
> There's a "natural" (tail) recursive solution to this if you've learned
> Lisp or Scheme, and an easy translation to a "while" loop should
> recursion be inefficient on your platform. I don't know of any "natural"
> way to do it without recursion or iteration/looping, nor do I see any
> need to introduce "eval" at all.
>
> I would say the most "elegant" solution would be the obvious iterative
> "while" loop translated into Ruby's iterators, since Ruby does not to my
> knowledge support efficient tail recursion. But I'm not going to code it
> for you. :)
>
I was trying to think of fold-ish solution to it, you've stimulated my
brain enough to do it:

# I wish we had a foldr to go with our foldl
p "a/b/c".split("/").reverse.inject({}) { |h, v| {v => h} }
{"a"=>{"b"=>{"c"=>{}}}}
> --
> M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)
> http://borasky-research.blo...
>
> If God had meant for carrots to be eaten cooked, He would have given
> rabbits fire.
>

deep

7/7/2013 6:30:00 PM

0

On Sun, 07 Jul 2013 12:33:40 -0500, Spender <Spender@Mars.org> wrote:

>On Sun, 07 Jul 2013 01:12:17 GMT, benj <benj@iwaynet.net> wrote:
>
>>Lessee. I wonder. Is it OK for me as a "non-deputized citizen" to
>>"follow" strangers in my neighborhood especially if they are acting
>>suspiciously? That's a tough one. Of course it is true that police have
>>no duty to protect anyone, especially me. And if that stranger should
>>suddenly assault me, punch me in the face, knock me down, sit on me and
>>pound my head into the pavement because I'm "creepy". Shouldn't I be
>>prohibited from shooting him with a legally carried firearm? I AM
>>"creepy" after all and the attacker DOES get to "stand his ground"!
>>
>>All I can say is the jury really faces a moral dilemma here.
>>
>>What do you guys think?
>
>There is a moral dilemma, but it's not illustrated very plainly by the
>terms you are using.
>
>Let's try again without the rhetoric. Martin may have been behaving
>suspiciously from Zimmerman's point of view, and Zimmerman may have been
>behaving suspiciously from Martin's point of view.
>
>That's the potential for trouble right there. Which one has the inherent
>right to follow and observe the other? Both of them do. Which one has an
>obligation to flee? Neither one does.

Which one was just minding their own business and doing nothing wrong?

Martin.

Which one had a history of violence and mental health issues and was
out wandering the streets at night with a gun looking for trouble and
has lied about everything regarding the incident in question?

Zimmerman.

And the jury is damned well going to figure it out.

Wayne

7/7/2013 6:36:00 PM

0



"deep" wrote in message news:4ncjt8ps0epqob9tc582pf57vo2e913tfm@4ax.com...

On Sun, 07 Jul 2013 12:33:40 -0500, Spender <Spender@Mars.org> wrote:

>On Sun, 07 Jul 2013 01:12:17 GMT, benj <benj@iwaynet.net> wrote:
>
>>Lessee. I wonder. Is it OK for me as a "non-deputized citizen" to
>>"follow" strangers in my neighborhood especially if they are acting
>>suspiciously? That's a tough one. Of course it is true that police have
>>no duty to protect anyone, especially me. And if that stranger should
>>suddenly assault me, punch me in the face, knock me down, sit on me and
>>pound my head into the pavement because I'm "creepy". Shouldn't I be
>>prohibited from shooting him with a legally carried firearm? I AM
>>"creepy" after all and the attacker DOES get to "stand his ground"!
>>
>>All I can say is the jury really faces a moral dilemma here.
>>
>>What do you guys think?
>
>There is a moral dilemma, but it's not illustrated very plainly by the
>terms you are using.
>
>Let's try again without the rhetoric. Martin may have been behaving
>suspiciously from Zimmerman's point of view, and Zimmerman may have been
>behaving suspiciously from Martin's point of view.
>
>That's the potential for trouble right there. Which one has the inherent
>right to follow and observe the other? Both of them do. Which one has an
>obligation to flee? Neither one does.

# Which one was just minding their own business and doing nothing wrong?

# Martin.

How does that justify attempted murder on someone following Martin?

deep

7/7/2013 6:38:00 PM

0

On Sun, 07 Jul 2013 11:25:58 -0700, Oren <Oren@127.0.0.1> wrote:

>On Sun, 07 Jul 2013 12:33:40 -0500, Spender <Spender@Mars.org> wrote:
>
>>Let's try again without the rhetoric. Martin may have been behaving
>>suspiciously from Zimmerman's point of view, and Zimmerman may have been
>>behaving suspiciously from Martin's point of view.
>>
>>That's the potential for trouble right there. Which one has the inherent
>>right to follow and observe the other? Both of them do. Which one has an
>>obligation to flee? Neither one does.
>
>Who brought a fist to a gun fight?

Why was there a gun fight? If Florida had sensible gun carry laws
this never would have happened.

deep

7/7/2013 6:44:00 PM

0

On Sun, 7 Jul 2013 11:36:29 -0700, "Wayne" <mygarbagecan@verizon.net>
wrote:

>
>
>"deep" wrote in message news:4ncjt8ps0epqob9tc582pf57vo2e913tfm@4ax.com...
>
>On Sun, 07 Jul 2013 12:33:40 -0500, Spender <Spender@Mars.org> wrote:
>
>>On Sun, 07 Jul 2013 01:12:17 GMT, benj <benj@iwaynet.net> wrote:
>>
>>>Lessee. I wonder. Is it OK for me as a "non-deputized citizen" to
>>>"follow" strangers in my neighborhood especially if they are acting
>>>suspiciously? That's a tough one. Of course it is true that police have
>>>no duty to protect anyone, especially me. And if that stranger should
>>>suddenly assault me, punch me in the face, knock me down, sit on me and
>>>pound my head into the pavement because I'm "creepy". Shouldn't I be
>>>prohibited from shooting him with a legally carried firearm? I AM
>>>"creepy" after all and the attacker DOES get to "stand his ground"!
>>>
>>>All I can say is the jury really faces a moral dilemma here.
>>>
>>>What do you guys think?
>>
>>There is a moral dilemma, but it's not illustrated very plainly by the
>>terms you are using.
>>
>>Let's try again without the rhetoric. Martin may have been behaving
>>suspiciously from Zimmerman's point of view, and Zimmerman may have been
>>behaving suspiciously from Martin's point of view.
>>
>>That's the potential for trouble right there. Which one has the inherent
>>right to follow and observe the other? Both of them do. Which one has an
>>obligation to flee? Neither one does.
>
># Which one was just minding their own business and doing nothing wrong?
>
># Martin.
>
>How does that justify attempted murder on someone following Martin?

What attempted murder? There was no attempted murder. The MEs
testified Zimmerman's injuries were "very insignificant", even most
likely self inflicted.

Oren

7/7/2013 7:01:00 PM

0

On Sun, 07 Jul 2013 12:38:14 -0600, deep wrote:

>On Sun, 07 Jul 2013 11:25:58 -0700, Oren <Oren@127.0.0.1> wrote:
>
>>On Sun, 07 Jul 2013 12:33:40 -0500, Spender <Spender@Mars.org> wrote:
>>
>>>Let's try again without the rhetoric. Martin may have been behaving
>>>suspiciously from Zimmerman's point of view, and Zimmerman may have been
>>>behaving suspiciously from Martin's point of view.
>>>
>>>That's the potential for trouble right there. Which one has the inherent
>>>right to follow and observe the other? Both of them do. Which one has an
>>>obligation to flee? Neither one does.
>>
>>Who brought a fist to a gun fight?
>
>Why was there a gun fight? If Florida had sensible gun carry laws
>this never would have happened.

It took Florida ~ 60 years to get "sensible" gun laws.

They have the best Castle Doctrine law in the nation.

....sometimes people call it a liberal law <smack!>

Oren

7/7/2013 7:07:00 PM

0

On Sun, 07 Jul 2013 12:44:04 -0600, deep wrote:

>>How does that justify attempted murder on someone following Martin?
>
>What attempted murder? There was no attempted murder. The MEs
>testified Zimmerman's injuries were "very insignificant", even most
>likely self inflicted.

Martin attempted to murder Zimmerman.

The ME that stated that is a political operative.

The biatch did not EXAMINE GZ. WTF is she?

Flint

7/7/2013 7:50:00 PM

0

On 7/7/2013 2:38 PM, deep wrote:
> On Sun, 07 Jul 2013 11:25:58 -0700, Oren <Oren@127.0.0.1> wrote:
>
>> On Sun, 07 Jul 2013 12:33:40 -0500, Spender <Spender@Mars.org> wrote:
>>
>>> Let's try again without the rhetoric. Martin may have been behaving
>>> suspiciously from Zimmerman's point of view, and Zimmerman may have been
>>> behaving suspiciously from Martin's point of view.
>>>
>>> That's the potential for trouble right there. Which one has the inherent
>>> right to follow and observe the other? Both of them do. Which one has an
>>> obligation to flee? Neither one does.
>>
>> Who brought a fist to a gun fight?
>
> Why was there a gun fight? If Florida had sensible gun carry laws
> this never would have happened.
>

Erroneous premise. There was no 'gun fight'. The use of a gun ENDED
the fight that was already in progress. Skittles and tea are not very
effective weapons to be used in a 'gun fight', or any fight for that
matter.

Boy are you stooooooopid...

--
MFB

Flint

7/7/2013 8:03:00 PM

0

On 7/7/2013 2:30 PM, deep wrote:
> On Sun, 07 Jul 2013 12:33:40 -0500, Spender <Spender@Mars.org> wrote:
>
>> On Sun, 07 Jul 2013 01:12:17 GMT, benj <benj@iwaynet.net> wrote:
>>
>>> Lessee. I wonder. Is it OK for me as a "non-deputized citizen" to
>>> "follow" strangers in my neighborhood especially if they are acting
>>> suspiciously? That's a tough one. Of course it is true that police have
>>> no duty to protect anyone, especially me. And if that stranger should
>>> suddenly assault me, punch me in the face, knock me down, sit on me and
>>> pound my head into the pavement because I'm "creepy". Shouldn't I be
>>> prohibited from shooting him with a legally carried firearm? I AM
>>> "creepy" after all and the attacker DOES get to "stand his ground"!
>>>
>>> All I can say is the jury really faces a moral dilemma here.
>>>
>>> What do you guys think?
>>
>> There is a moral dilemma, but it's not illustrated very plainly by the
>> terms you are using.
>>
>> Let's try again without the rhetoric. Martin may have been behaving
>> suspiciously from Zimmerman's point of view, and Zimmerman may have been
>> behaving suspiciously from Martin's point of view.
>>
>> That's the potential for trouble right there. Which one has the inherent
>> right to follow and observe the other? Both of them do. Which one has an
>> obligation to flee? Neither one does.
>
> Which one was just minding their own business and doing nothing wrong?

Turning back on someone one suspects is following them, while not
necessarily 'wrong' was incredibly stupid, and is definitely not
simply 'minding one's own business'... ... unless one's business is to
seek a confrontation. By not going straight home, Martin actually
pursued/stalked Zimmerman, not the other way around. If Martin felt
threatened by Zimmerman's entirely lawful activity, that was his
mistake, not Zimmerman's. By confronting Zimmerman, Martin failed in
his duty to retreat, and hence was the actual aggressor...

....and he paid the ultimate price. Since he can't be tried for
stupidity, the best justice he deserves is a posthumously Darwin award
for attempting to bring skittles and tea
to a confrontation with an armed person.

Unlike you, deep birddropping, this isn't about race, black vs white,
what have you. It's about the stupid vs the well prepared.

Be stupid and buy into the false media racial narrative if you like,
but be prepared to have vent your spleen when Zimmerman walks. Life's
a bitch, eh, pooh pooh?


>
> Martin.
>
> Which one had a history of violence and mental health issues and was
> out wandering the streets at night with a gun looking for trouble and
> has lied about everything regarding the incident in question?
>
> Zimmerman.
>
> And the jury is damned well going to figure it out.
>


--
MFB

Frank

7/7/2013 8:07:00 PM

0

On 7/7/2013 2:44 PM, deep wrote:
> On Sun, 7 Jul 2013 11:36:29 -0700, "Wayne" <mygarbagecan@verizon.net>
> wrote:
>
>>
>>
>> "deep" wrote in message news:4ncjt8ps0epqob9tc582pf57vo2e913tfm@4ax.com...
>>
>> On Sun, 07 Jul 2013 12:33:40 -0500, Spender <Spender@Mars.org> wrote:
>>
>>> On Sun, 07 Jul 2013 01:12:17 GMT, benj <benj@iwaynet.net> wrote:
>>>
>>>> Lessee. I wonder. Is it OK for me as a "non-deputized citizen" to
>>>> "follow" strangers in my neighborhood especially if they are acting
>>>> suspiciously? That's a tough one. Of course it is true that police have
>>>> no duty to protect anyone, especially me. And if that stranger should
>>>> suddenly assault me, punch me in the face, knock me down, sit on me and
>>>> pound my head into the pavement because I'm "creepy". Shouldn't I be
>>>> prohibited from shooting him with a legally carried firearm? I AM
>>>> "creepy" after all and the attacker DOES get to "stand his ground"!
>>>>
>>>> All I can say is the jury really faces a moral dilemma here.
>>>>
>>>> What do you guys think?
>>>
>>> There is a moral dilemma, but it's not illustrated very plainly by the
>>> terms you are using.
>>>
>>> Let's try again without the rhetoric. Martin may have been behaving
>>> suspiciously from Zimmerman's point of view, and Zimmerman may have been
>>> behaving suspiciously from Martin's point of view.
>>>
>>> That's the potential for trouble right there. Which one has the inherent
>>> right to follow and observe the other? Both of them do. Which one has an
>>> obligation to flee? Neither one does.
>>
>> # Which one was just minding their own business and doing nothing wrong?
>>
>> # Martin.
>>
>> How does that justify attempted murder on someone following Martin?
>
> What attempted murder? There was no attempted murder. The MEs
> testified Zimmerman's injuries were "very insignificant", even most
> likely self inflicted.
>

What part of the ME's not even seeing him don't you understand?