Got stuck

Hi,

may be my Enigma hacking has encyphered my brain also...but...

What is wrong with this code:

etwdata=[[1,2],[3,4],[5,6]] # only example data

etwdata.each{ |rot|
rot.each{ |val|
   print (val + ?A).chr," " # here ruby fails...error message below...
}
print "\n"

Ruby's error message:

basicenigma4.rb:175: warning: don't put space before argument parentheses

Sorry... but _I_ dont see anything wrong here...

Ruby.use!
Meino

Meino Christian Cramer wrote:

Hi,

may be my Enigma hacking has encyphered my brain also...but...

What is wrong with this code:

etwdata=[[1,2],[3,4],[5,6]] # only example data

etwdata.each{ |rot|
rot.each{ |val|
  print (val + ?A).chr," " # here ruby fails...error message below...
}
print "\n"

Ruby's error message:

basicenigma4.rb:175: warning: don't put space before argument parentheses

Sorry... but _I_ dont see anything wrong here...

didn't read it all, but imho ruby wants to read:

print(val + ?A).chr," "

but you want to write:

print((val + ?A).chr," ")

or sth like that. put explicit brackets in that case.

emmanuel

Meino Christian Cramer wrote:

Hi,

may be my Enigma hacking has encyphered my brain also...but...

What is wrong with this code:

etwdata=[[1,2],[3,4],[5,6]] # only example data

etwdata.each{ |rot|
rot.each{ |val|

You wrote:

   print (val + ?A).chr," " #...

Try this:

     print( (val + ?A).chr, " " )

}
print "\n"

And adding a 2nd '}' might help, too. :wink:

Ruby's error message:

basicenigma4.rb:175: warning: don't put space before argument parentheses

The script didn't fail, it only gave you a warning.
For non-tivial combinations of method calls adding parentheseses is recommended, because otherwise it may be unclear what the result should be.

Sorry... but _I_ dont see anything wrong here...

....because there *is* nothing wrong, just sub-optimal. :wink:

Happy rubying

Stephan

···

--
Stephan Kämper/IT-Beratung http://www.stephankaemper.de
Qualitätssicherung / Softwaretest / Datenanalyse

I think you need to be a wee bit more explicit about what you want to print.
What about something like this?

etwdata.each{ |rot|
    rot.each{ |val|
        print("%s\n" % [(val + ?A).chr])
    }
}

···

----- Original Message -----
From: "Meino Christian Cramer" <Meino.Cramer@gmx.de>
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Sent: Friday, August 20, 2004 10:18 AM
Subject: Got stuck...

Hi,

may be my Enigma hacking has encyphered my brain also...but...

What is wrong with this code:

etwdata=[[1,2],[3,4],[5,6]] # only example data

etwdata.each{ |rot|
rot.each{ |val|
   print (val + ?A).chr," " # here ruby fails...error message

below...

}
print "\n"

Ruby's error message:

basicenigma4.rb:175: warning: don't put space before argument parentheses

Sorry... but _I_ dont see anything wrong here...

Ruby.use!
Meino

Other people have pointed the error out, but it's worth noting that
print is actually a method of Kernel, not a keyword, hence the need for
parens surrounding the entire argument.

martin

···

Meino Christian Cramer <Meino.Cramer@gmx.de> wrote:

   print (val + ?A).chr," " # here ruby fails...error message below...

basicenigma4.rb:175: warning: don't put space before argument parentheses

Meino Christian Cramer wrote:

print (val + ?A).chr," " # here ruby fails...error message below...

print(val + ?A).chr," "

moulon% ruby -e 'val = 32; print (val + ?A).chr," "'
a moulon%

Guy Decoux

Other people have pointed the error out, but it's worth noting that
print is actually a method of Kernel, not a keyword, hence the need for
parens surrounding the entire argument.

What error ?

svg% ruby -ve 'val = 32; print (val + ?A).chr," "'
ruby 1.8.2 (2004-07-29) [i686-linux]
-e:1: warning: (...) interpreted as grouped expression
a svg%

Guy Decoux

Well, the reason ruby was issuing a warning, at any rate :slight_smile:

martin

···

ts <decoux@moulon.inra.fr> wrote:

> Other people have pointed the error out, but it's worth noting that
> print is actually a method of Kernel, not a keyword, hence the need for
> parens surrounding the entire argument.

What error ?

Well, the reason ruby was issuing a warning, at any rate :slight_smile:

and you find this normal ?

vg% ruby -vce 'print (a + b)'
ruby 1.8.2 (2004-07-29) [i686-linux]
-e:1: warning: (...) interpreted as grouped expression
Syntax OK
svg%

svg% ruby -vce 'a { print (a + b) }'
ruby 1.8.2 (2004-07-29) [i686-linux]
-e:1: warning: don't put space before argument parentheses
Syntax OK
svg%

What is the next step ?

ruby will use a random generator to know if it must give the warning

     "warning: (...) interpreted as grouped expression"

or

     "warning: don't put space before argument parentheses"

:-)))

Guy Decoux

vg% ruby -vce 'print (a + b)'
ruby 1.8.2 (2004-07-29) [i686-linux]
-e:1: warning: (...) interpreted as grouped expression
Syntax OK
svg%

svg% ruby -vce 'a { print (a + b) }'
ruby 1.8.2 (2004-07-29) [i686-linux]
-e:1: warning: don't put space before argument parentheses
Syntax OK
svg%

Wow - wasn't aware of that. What's the difference due to?

What is the next step ?

ruby will use a random generator to know if it must give the warning

     "warning: (...) interpreted as grouped expression"

or

     "warning: don't put space before argument parentheses"

But will it be a reentrant random number generator? (:

martin

···

ts <decoux@moulon.inra.fr> wrote: