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

**URL:** <https://www.ruby-forum.com/t/got-some-syntax-error-i-cant-spot-can-you-i-hope/164698>\
**Category:** Ruby\
**Created:** [April 4, 2009, 8:05am UTC](https://www.ruby-forum.com/t/got-some-syntax-error-i-cant-spot-can-you-i-hope/164698 "2009-04-04T08:05:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [April 4, 2009, 8:05am UTC](https://www.ruby-forum.com/t/got-some-syntax-error-i-cant-spot-can-you-i-hope/164698/1 "2009-04-04T08:05:41Z")

</div>

Hi all,

I pulled my problem code from my app into a test on  
[http://www.pastie.org/436616](http://www.pastie.org/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. Can you see  
what the problem is?

Thanks in Advance,  
Richard

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [April 4, 2009, 8:22am UTC](https://www.ruby-forum.com/t/got-some-syntax-error-i-cant-spot-can-you-i-hope/164698/2 "2009-04-04T08:22:02Z")

</div>

From: “RichardOnRails” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> I pulled my problem code from my app into a test on [http://www.pastie.org/436616](http://www.pastie.org/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. 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

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [April 4, 2009, 8:23am UTC](https://www.ruby-forum.com/t/got-some-syntax-error-i-cant-spot-can-you-i-hope/164698/3 "2009-04-04T08:23:12Z")

</div>

On Sat, Apr 4, 2009 at 11:34 AM, RichardOnRails  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [April 4, 2009, 9:00am UTC](https://www.ruby-forum.com/t/got-some-syntax-error-i-cant-spot-can-you-i-hope/164698/4 "2009-04-04T09:00:39Z")

</div>

On Apr 4, 2:04 am, RichardOnRails  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [April 4, 2009, 5:26pm UTC](https://www.ruby-forum.com/t/got-some-syntax-error-i-cant-spot-can-you-i-hope/164698/5 "2009-04-04T17:26:03Z")

</div>

On Apr 4, 2:20 am, Bill K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> "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

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [April 4, 2009, 5:30pm UTC](https://www.ruby-forum.com/t/got-some-syntax-error-i-cant-spot-can-you-i-hope/164698/6 "2009-04-04T17:30:44Z")

</div>

On Apr 4, 2:21 am, Martin DeMello [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > components of the problematic code.  
> > "\tand # groups saved thus far: " +  
> > "open(%d), " +

Hi Martin,

I posted an equivalent of the following post to Bill K.:

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

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [April 5, 2009, 6:32am UTC](https://www.ruby-forum.com/t/got-some-syntax-error-i-cant-spot-can-you-i-hope/164698/7 "2009-04-05T06:32:44Z")

</div>

On Apr 4, 12:34 pm, Leo [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> 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

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [April 4, 2009, 6:39pm UTC](https://www.ruby-forum.com/t/got-some-syntax-error-i-cant-spot-can-you-i-hope/164698/8 "2009-04-04T18:39:52Z")

</div>

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

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
```
