i am new to ruby i am trieng to get some skils but i have a problem when
i use a fixnum :
years = ask("")
days = years * 365
puts days
my answer is
222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
but i should be 730
i have an screenshot as an attachment plz help me
Please paste your ask() Method. That appears to be where the problem is.
···
=======================================================================
This email, including any attachments, is only for the intended
addressee. It is subject to copyright, is confidential and may be
the subject of legal or other privilege, none of which is waived or
lost by reason of this transmission.
If the receiver is not the intended addressee, please accept our
apologies, notify us by return, delete all copies and perform no
other act on the email.
Unfortunately, we cannot warrant that the email has not been
altered or corrupted during transmission.
This is because for all we know, ask("") is returning "2" and 365
times "2" is a string containing 365 2s. At least in such a inferior
language as Ruby.
In more strongly typed programming languages such as Common Lisp,
you'd get an error:
Ask is returning the string "2" instead of the number 2.
When you use the multiplication operator on a string, it creates a longer
string with that many copies of the string concatenated back to back, so
instead of multiplying the number 2 by 365 to give 730, you got a string
containing exactly 365 twos.
years=ask("").to_i
--Ken
···
On Tue, 03 Mar 2009 16:28:48 -0500, Guy Dols wrote:
--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/
This is because for all we know, ask("") is returning "2" and 365
times "2" is a string containing 365 2s. At least in such a inferior
language as Ruby.
Unsuccessful troll is unsuccessful.
···
In more strongly typed programming languages such as Common Lisp,
you'd get an error:
C/USER[929]> (* "2" 365)
*** - *: "2" is not a number
i have an screenshot as an attachment plz help me
Good for you!
=======================================================================
This email, including any attachments, is only for the intended
addressee. It is subject to copyright, is confidential and may be
the subject of legal or other privilege, none of which is waived or
lost by reason of this transmission.
If the receiver is not the intended addressee, please accept our
apologies, notify us by return, delete all copies and perform no
other act on the email.
Unfortunately, we cannot warrant that the email has not been
altered or corrupted during transmission.
This is because for all we know, ask("") is returning "2" and 365
times "2" is a string containing 365 2s. At least in such a inferior
language as Ruby.
In more strongly typed programming languages such as Common Lisp,
you'd get an error:
C/USER[929]> (* "2" 365)
*** - *: "2" is not a number
i have an screenshot as an attachment plz help me
Good for you!
And for the benefits, such as they are, of strong typing, we get to a whole other level of detail to attend to. No thanks. Did that for a time with Pascal. I prefer the mindless grace of waterfowl.
t.
···
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website) << sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is because for all we know, ask("") is returning "2" and 365
times "2" is a string containing 365 2s. At least in such a inferior
language as Ruby.
In more strongly typed programming languages such as Common Lisp,
What?? There are other languages than CL??? You must be kidding? I
warn you I might report you to the CL-ML.
Some things are just too serious to joke with!!
And BTW, seems you posted this by error to ruby talk, well I'm sure
that was just a stupid mistake you will take of correcting very soon.
Thank you in advance.
Cheers
Robert
···
On Tue, Mar 3, 2009 at 10:43 PM, Pascal J. Bourguignon <pjb@informatimago.com> wrote:
language as Ruby.
In more strongly typed programming languages such as Common Lisp,
This is because for all we know, ask("") is returning "2" and 365
times "2" is a string containing 365 2s. At least in such a inferior
language as Ruby.
In more strongly typed programming languages such as Common Lisp,