[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Eval Weird Behavior

Ricardo Sisnett

3/19/2009 5:43:00 AM

Hi all... I'm doing some Genetic Programming for my AI class, and I ran
into a weird "bug" or behavior with the "eval()" function.

Mainly what I do is build a three of evaluable nodes, and then pour the
structure into a string, which I escape in order to make it "evaluable".

So after a run, a possible program would look like:

"whileInCorridorRange(\"do2(\\\"turnRight()\\\",\\\"turnRight()\\\")\")"

- whileInCorridorRange will check for a ceratain condition, and while
it is true it will call eval for the rest of the string "do2..." same
would be for do2 which would call turnRight() and then turnRight()..
turnRight() itself is a terminal so it won't call anyone else.

This works pretty good and causes no problem... but if I go deeper into
nesting:
"whileInCorridorRange(\"ifConvexCorner(\\\"turnRight()\\\",
\\\"do2(\\\\\"whileTooFarFromWall(\\\\\\\"turnRight()\\\\\\\")\\\\\",\\\\\"whileInCorridorRange(\\\\\\\"turnLeft()\\\\\\\")\\\\\")\\\")\")"

I will get:

SyntaxError: (eval):1:in `do': compile error
(eval):1: syntax error, unexpected tIDENTIFIER, expecting ')'
whileInCorridorRange("ifConvexCorner(\"turnRight()\",
\"do2(\\"whileTooFarFromWall(\\\"turnRight()\\\")\\",\\"whileInCorridorRange(\\\"turnLeft()\\\")\\")\")")
^
(eval):1: syntax error, unexpected ',', expecting $end
whileInCorridorRange("ifConvexCorner(\"turnRight()\",
\"do2(\\"whileTooFarFromWall(\\\"turnRight()\\\")\\",\\"whileInCorridorRange(\\\"turnLeft()\\\")\\")\")")
^
from ./robot.rb:107:in `do'
from ./geneticProgram.rb:128:in `eval'
from ./robot.rb:107:in `do'
from ./geneticProgram.rb:128:in `evaluate'
from (irb):34


It looks like, using five slashes \\\\\" to escape the quotes cause the
eval function to break.

I'm not sure if this is a bug or has some "meant to be" explanation, but
I'd really appreciate any pointers.

Thanks.
--
Posted via http://www.ruby-....

8 Answers

The Mighty T.B.

3/17/2009 9:51:00 PM

0

andyk122@gmail.com wrote:

> And 64 percent of Iraqis say democracy is the way to go in Iraq.
> Guess the Iraq war might pay off after all.

Gee, I wonder if they polled the 1.3 MILLION Iraqis that have been
killed as a result of the US invasion of Iraq?
I wonder if they feel that the war is "working"?
I wonder how many civilians have do die in order for the war to "pay
off"?
I wonder if 4,200 (and counting) dead American soldiers is enough of a
price to pay for good poll numbers?
How far up your own ass do you have to be to actually think this war
is "working"?

Woulda been kind of nice if more Iraqis got off their lazy asses a lot
sooner instead of relying on the Coalition to do all the heavy lifting the
past 6 years. There's a reason why some shlub like Saddam Hussein was able
to keep that country under his thumb and it wasn't due to any "resistance
fighters." Now that there's some "progress," it's all "get out of our
country!"

Guaranteed within 5 years of the US pulling out, the Taliban will be running
that country.

T.B.

Evolution

3/18/2009 4:23:00 PM

0

The Mighty T.B. wrote:
> andyk122@gmail.com wrote:
>
>> And 64 percent of Iraqis say democracy is the way to go in Iraq.
>> Guess the Iraq war might pay off after all.
>
> Gee, I wonder if they polled the 1.3 MILLION Iraqis that have been
> killed as a result of the US invasion of Iraq?
> I wonder if they feel that the war is "working"?
> I wonder how many civilians have do die in order for the war to "pay
> off"?
> I wonder if 4,200 (and counting) dead American soldiers is enough of a
> price to pay for good poll numbers?
> How far up your own ass do you have to be to actually think this war
> is "working"?
>
> Woulda been kind of nice if more Iraqis got off their lazy asses a lot
> sooner instead of relying on the Coalition to do all the heavy lifting
> the past 6 years. There's a reason why some shlub like Saddam Hussein
> was able to keep that country under his thumb and it wasn't due to any
> "resistance fighters." Now that there's some "progress," it's all "get
> out of our country!"

They certainly aren't lazy. The reason the Iraqi puppet government
couldn't raise an army the last 6 years is because no Iraqis would be
caught dead helping the US puppet government. In fact, they would join,
then bugger off with the equipment and training they received to work
for a militia. Why on earth would you expect them to support our
occupation puppet government.

>
> Guaranteed within 5 years of the US pulling out, the Taliban will be
> running that country.

You're confused. There are no Taliban in Iraq. However, within a year
of the US pulling out, you can bet another strongman, likely al Sadr,
will take over. And unlike Saddam Hussein, al Sadr is a religious
radical, and the Iraqis will be far worse off than had we left Saddam in
place.

The only reason the "surge" is working is because at the same time we
added more troops, we began paying al Sadr to stop fighting. He's just
biding his time, building up his resources and weaponry with US money,
for when we leave. Hopefully, the coup won't be too bloody.

>
> T.B.


--
Laurie

http://lauriehester.blo...

David

3/18/2009 5:19:00 PM

0

On Tue, 17 Mar 2009 14:51:27 -0700, "The Mighty T.B."
<TB@someunknownaddress.com> wrote:

>Guaranteed within 5 years of the US pulling out, the Taliban will be running
>that country.
>
>T.B.

So in your opinion should we stay there permanently, or should Bush
never have invaded.
--
Reply to david at habermehl dot com

The Mighty T.B.

3/18/2009 11:35:00 PM

0

"David" wrote:

>>Guaranteed within 5 years of the US pulling out, the Taliban will be
>>running
>>that country.
>>
>>T.B.
>
> So in your opinion should we stay there permanently, or should Bush
> never have invaded.

The US should have never invaded.

T.B.

Ricardo Sisnett

3/19/2009 6:48:00 AM

0

Ok I'm answering my own question, just in case anyone stumbles across
this issue and ends in my post:

I thought you had to add a pair of slashes (\\) to escape the quotes(")
but it seems that you have to add twice the last number of slashes plus
one...

So if you had something like this:

class Test
def a(arg)
eval(arg)
end
def b
puts "b"
end
end

In order to recursively call function a and pass "b" to the las call in
order to get a printed b... you'd have to:

1 Call:
eval("a(\"b\")")
=>b
--One Slash
2 Calls:
eval("a(\"a(\\\"b\\\")\")")
--Three Slashes ( 1 * 2 + 1)

3 Calls:
eval("a(\"a(\\\"a(\\\\\\\"b\\\\\\\")\\\")\")")
--Seven Slashes ( 3 * 2 + 1)

4 Calls:
--Fifteen Slashes (7*2 +1 )



I'm not sure if this is useful for anyone besides me and my pretty
small-scoped project, but who would know?


Thanks again
--
Posted via http://www.ruby-....

Evolution

3/19/2009 11:51:00 AM

0

The Mighty T.B. wrote:
> "David" wrote:
>
>>> Guaranteed within 5 years of the US pulling out, the Taliban will be
>>> running
>>> that country.
>>>
>>> T.B.
>>
>> So in your opinion should we stay there permanently, or should Bush
>> never have invaded.
>
> The US should have never invaded.
>
> T.B.

The Iraqis agree... according to the ABC poll Patrick quoted:

"Most, 56 percent, say it was wrong for the United States and its
coalition allies to invade six years ago this week. Never in these polls
has a majority of Iraqis supported the U.S.-led war.

"Other views of the U.S. presence remain weak as well. Just 27 percent
are confident in U.S. forces (albeit nearly double its low). Just 30
percent say U.S. and coalition forces have done a good job carrying out
their responsibilities in Iraq. Still fewer, 18 percent, have a positive
opinion of the United States overall. Barely over a third think the
election of Barack Obama will help their country. "

--
Laurie

http://lauriehester.blo...

The Mighty T.B.

3/19/2009 4:05:00 PM

0

"Evolution" wrote:

>>> So in your opinion should we stay there permanently, or should Bush
>>> never have invaded.
>>
>> The US should have never invaded.
>>
>> T.B.
>
> The Iraqis agree... according to the ABC poll Patrick quoted:
>
> "Most, 56 percent, say it was wrong for the United States and its
> coalition allies to invade six years ago this week. Never in these polls
> has a majority of Iraqis supported the U.S.-led war.
>
> "Other views of the U.S. presence remain weak as well. Just 27 percent are
> confident in U.S. forces (albeit nearly double its low). Just 30 percent
> say U.S. and coalition forces have done a good job carrying out their
> responsibilities in Iraq. Still fewer, 18 percent, have a positive opinion
> of the United States overall. Barely over a third think the election of
> Barack Obama will help their country. "

Well, with any luck in the next few years when the Iraqi people are once
again under the thumb of an oppressive regime, maybe France can save their
asses or even more unlikely, they can finally grow a pair and do it
themselves.

T.B.

Evolution

3/20/2009 12:11:00 AM

0

The Mighty T.B. wrote:
> "Evolution" wrote:
>
>>>> So in your opinion should we stay there permanently, or should Bush
>>>> never have invaded.
>>>
>>> The US should have never invaded.
>>>
>>> T.B.
>>
>> The Iraqis agree... according to the ABC poll Patrick quoted:
>>
>> "Most, 56 percent, say it was wrong for the United States and its
>> coalition allies to invade six years ago this week. Never in these
>> polls has a majority of Iraqis supported the U.S.-led war.
>>
>> "Other views of the U.S. presence remain weak as well. Just 27 percent
>> are confident in U.S. forces (albeit nearly double its low). Just 30
>> percent say U.S. and coalition forces have done a good job carrying
>> out their responsibilities in Iraq. Still fewer, 18 percent, have a
>> positive opinion of the United States overall. Barely over a third
>> think the election of Barack Obama will help their country. "
>
> Well, with any luck in the next few years when the Iraqi people are once
> again under the thumb of an oppressive regime, maybe France can save
> their asses or even more unlikely, they can finally grow a pair and do
> it themselves.
>
> T.B.

If they want democracy, they'll fight for it. You can't force democracy
at the point of a gun. The Iraqis didn't even ask us for help. On a
conceptual level, most people prefer having a vote, but not all are
willing to fight for it. They were better off under Saddam, and that's
the question this poll refuses to ask.

Funny how some people are more fond of jobs and water and electricity
than of having democracy...

--
Laurie

http://lauriehester.blo...