print with no arguments?

O

Oliver Cromm

I feel that the Ruby interpreter is poking fun at me with this error:

findcols.rb:84:in `print': wrong number of arguments(1 for 0)
(ArgumentError)

The script does indeed run without errors as soon as I remove the
argument from print, but what sense should that make? The culprit line
with a little context:

(0..@peak).each do |n|
([email protected]).each {|i| print "*" if @cumul > n}
puts
end
 
A

Ara.T.Howard

I feel that the Ruby interpreter is poking fun at me with this error:

findcols.rb:84:in `print': wrong number of arguments(1 for 0)
(ArgumentError)

The script does indeed run without errors as soon as I remove the
argument from print, but what sense should that make? The culprit line
with a little context:

(0..@peak).each do |n|
([email protected]).each {|i| print "*" if @cumul > n}
puts
end


perhaps you have another 'def print...' in scope somewhere which does NOT take
an argument? are you sure that your entire source file (or something you've
required) has not defined a print?

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| URL :: http://www.ngdc.noaa.gov/stp/
| TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done
===============================================================================
 
N

Nathaniel Talbott

I feel that the Ruby interpreter is poking fun at me with this error:

findcols.rb:84:in `print': wrong number of arguments(1 for 0)
(ArgumentError)

The script does indeed run without errors as soon as I remove the
argument from print, but what sense should that make? The culprit line
with a little context:

(0..@peak).each do |n|
([email protected]).each {|i| print "*" if @cumul > n}
puts
end


Have you perhaps overridden print somewhere in your code?


Nathaniel

<:((><
 
O

Oliver Cromm

Ara.T.Howard said:
perhaps you have another 'def print...' in scope somewhere which
does NOT take an argument?

Indeed, that's it. So I was poking fun at me myself. I'll quickly
change the name of that "print" function!

Thanks!
 
A

Archit Baweja

Hey

Oliver Cromm said:
Indeed, that's it. So I was poking fun at me myself. I'll quickly
change the name of that "print" function!

even though you found an error it wouldn't hurt if you put it like so

print("*") if ...

so that the precedence is clear. The interpreter could have seen it as

print ("*" if ...)

which would be runtime problem.

Cheers!
Archit
 
O

Oliver Cromm

[print "*" if @cumul > n]
even though you found an error it wouldn't hurt if you put it like
so

print("*") if ...

so that the precedence is clear.

Indeed - that was my first suspicion as to the source of the error, so
I tried changing to

"*".print

Strange how unfamiliar the print() version looks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top