[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Got some syntax error I can't spot. Can you (I hope)?

RichardOnRails

4/4/2009 6:04:00 AM

Hi all,

I pulled my problem code from my app into a test on http://www.pastie.....

Lines 13-19 are the problem code in my app.

Lines preceding them I set up needed definitions and test individual
components of the problematic code.

The final lines display the error lines 13-19 produce. Can you see
what the problem is?

Thanks in Advance,
Richard
7 Answers

Bill Kelly

4/4/2009 6:21:00 AM

0


From: "RichardOnRails" <RichardDummyMailbox58407@USComputerGurus.com>
>
> I pulled my problem code from my app into a test on http://www.pastie.....
>
> Lines 13-19 are the problem code in my app.
>
> Lines preceding them I set up needed definitions and test individual
> components of the problematic code.
>
> The final lines display the error lines 13-19 produce. Can you see
> what the problem is?

Precedence problem with + and % apparently. This works:

puts(("Considering saving the trade-group" +
"\tfor symbol \"%s\", "+
"\tgroup size: %d, " +
"\tand # groups saved thus far: " +
"open(%d), " +
"completed(%d)") %
[savedSymbol, tradeGroup.size, openTrades.size, completedTrades.size])


Regards,

Bill



Martin DeMello

4/4/2009 6:22:00 AM

0

On Sat, Apr 4, 2009 at 11:34 AM, RichardOnRails
<RichardDummyMailbox58407@uscomputergurus.com> wrote:
> Hi all,
>
> I pulled my problem code from my app into a test on http://www.p...
/436616.
>
> Lines 13-19 are the problem code in my app.
>
> Lines preceding them I set up needed definitions and test individual
> components of the problematic code.
>
> The final lines display the error lines 13-19 produce. =A0Can you see
> what the problem is?

It's a precedence thing - % has higher precedence than +. Try this:

# before
puts "Considering saving the trade-group" +
"\tfor symbol \"%s\", "+
"\tgroup size: %d, " +
"\tand # groups saved thus far: " +
"open(%d), " +
"completed(%d)" %
[savedSymbol, tradeGroup.size, openTrades.size, completedTrades.size]

# after

puts ("Considering saving the trade-group" +
"\tfor symbol \"%s\", "+
"\tgroup size: %d, " +
"\tand # groups saved thus far: " +
"open(%d), " +
"completed(%d)") %
[savedSymbol, tradeGroup.size, openTrades.size, completedTrades.size]

martin



>
> Thanks in Advance,
> Richard
>
>

RichardOnRails

4/4/2009 6:56:00 AM

0

On Apr 4, 2:04 am, RichardOnRails
<RichardDummyMailbox58...@USComputerGurus.com> wrote:
> Hi all,
>
> I pulled my problem code from my app into a test onhttp://www.pastie.....
>
> Lines 13-19 are the problem code in my app.
>
> Lines preceding them I set up needed definitions and test individual
> components of the problematic code.
>
> The final lines display the error lines 13-19 produce.  Can you see
> what the problem is?
>
> Thanks in Advance,
> Richard

My brain finally thawed. I a movie decades ago, a Dustin Hoffman
character was told the "plastic" was the key to success. For my
current problem, the key was "parentheses"! I appended the
correction to the Pastie post.
My apology for wasting your time with my stupidity.

Best wishes,
Richard

RichardOnRails

4/4/2009 3:23:00 PM

0

On Apr 4, 2:20 am, Bill Kelly <bi...@cts.com> wrote:
> From: "RichardOnRails" <RichardDummyMailbox58...@USComputerGurus.com>
>
>
>
> > I pulled my problem code from my app into a test onhttp://www.pastie.....
>
> > Lines 13-19 are the problem code in my app.
>
> > Lines preceding them I set up needed definitions and test individual
> > components of the problematic code.
>
> > The final lines display the error lines 13-19 produce.  Can you see
> > what the problem is?
>
> Precedence problem with + and % apparently.  This works:
>
> puts(("Considering saving the trade-group"   +
>   "\tfor symbol \"%s\", "+
>   "\tgroup size: %d, " +
>   "\tand # groups saved thus far: " +
>       "open(%d), " +
>       "completed(%d)") %
>       [savedSymbol, tradeGroup.size, openTrades.size, completedTrades.size])
>
> Regards,
>
> Bill

Hi Bill,

Many thanks for your solution. It looks like you posted your response
about 15 minutes after I posted my question.

I posted my Eureka moment about an hour after I posted my question,
though it seemed to me to have been much sooner than that, so I never
checked to see whether anyone had posted a response.

So I don't know which to be happier about. That my brain began
functioning again, of that this newsgroup is attended by such
wonderful people like you and Martin.

Again, thank you and
Best wishes,

Richard

RichardOnRails

4/4/2009 3:25:00 PM

0

On Apr 4, 2:21 am, Martin DeMello <martindeme...@gmail.com> wrote:
> On Sat, Apr 4, 2009 at 11:34 AM, RichardOnRails
>
> <RichardDummyMailbox58...@uscomputergurus.com> wrote:
> > Hi all,
>
> > I pulled my problem code from my app into a test onhttp://www.pastie.....
>
> > Lines 13-19 are the problem code in my app.
>
> > Lines preceding them I set up needed definitions and test individual
> > components of the problematic code.
>
> > The final lines display the error lines 13-19 produce.  Can you see
> > what the problem is?
>
> It's a precedence thing - % has higher precedence than +. Try this:
>
> # before
> puts "Considering saving the trade-group"     +
>   "\tfor symbol \"%s\", "+
>   "\tgroup size: %d, " +
>   "\tand # groups saved thus far: " +
>       "open(%d), " +
>       "completed(%d)" %
>       [savedSymbol, tradeGroup.size, openTrades.size, completedTrades.size]
>
> # after
>
> puts ("Considering saving the trade-group"    +
>   "\tfor symbol \"%s\", "+
>   "\tgroup size: %d, " +
>   "\tand # groups saved thus far: " +
>       "open(%d), " +
>       "completed(%d)") %
>       [savedSymbol, tradeGroup.size, openTrades.size, completedTrades.size]
>
> martin
>
>
>
> > Thanks in Advance,
> > Richard
>
>

Hi Martin,

I posted an equivalent of the following post to Bill Kelly:

Many thanks for your solution. It looks like you posted your response
about 20 minutes after I posted my question.

I posted my Eureka moment about an hour after I posted my question,
though it seemed to me to have been much sooner than that, so I never
checked to see whether anyone had posted a response.

So I don't know which to be happier about. That my brain began
functioning again, of that this newsgroup is attended by such
wonderful people like you and Bill.

Again, thank you and
Best wishes,

Richard

-lim-

4/4/2009 4:35:00 PM

0

> I pulled my problem code from my app into a test onhttp://www.pastie.....

You might want to take a look at ruby's heredoc syntax:

Instead of

a = ("foo" + "(%d)" + " bar") % 123

you could also use:

a = <<TEXT % 123
foo(%d) bar
TEXT


RichardOnRails

4/5/2009 4:30:00 AM

0

On Apr 4, 12:34 pm, Leo <minil...@gmail.com> wrote:
> > I pulled my problem code from my app into a test onhttp://www.pastie.....
>
> You might want to take a look at ruby's heredoc syntax:
>
> Instead of
>
>     a = ("foo" + "(%d)" + " bar") % 123
>
> you could also use:
>
>     a = <<TEXT % 123
>     foo(%d) bar
>     TEXT

Hi Leo,

Nice idea! Saves typing (and mistyping!) all those quotes, pluses, \n
and \t. Works great!

Many thanks and
Best wishes,
Richard