# Fixnum problem plz help

**URL:** <https://www.ruby-forum.com/t/fixnum-problem-plz-help/161925>\
**Category:** Ruby\
**Created:** [March 3, 2009, 10:30pm UTC](https://www.ruby-forum.com/t/fixnum-problem-plz-help/161925 "2009-03-03T22:30:06Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![guydols](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a6a055/32.png) [@guydols](https://www.ruby-forum.com/u/guydols)\
**Post date:** [March 3, 2009, 10:30pm UTC](https://www.ruby-forum.com/t/fixnum-problem-plz-help/161925/1 "2009-03-03T22:30:06Z")

</div>

hy

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

---

<div class="post-metadata">

**Author:** ![guydols](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a6a055/32.png) [@guydols](https://www.ruby-forum.com/u/guydols)\
**Post date:** [March 3, 2009, 10:34pm UTC](https://www.ruby-forum.com/t/fixnum-problem-plz-help/161925/2 "2009-03-03T22:34:26Z")

</div>

On [Wed, 04.03.2009 06:28], Guy D. wrote:

> my answer is  
> 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
> 
> but i should be 730
> 
> i have an screenshot as an attachment plz help me  
> Thats the character “2” (not the number) repeated 365 times. you  
> probably want years = ask(“”).to\_i

---

<div class="post-metadata">

**Author:** ![guydols](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a6a055/32.png) [@guydols](https://www.ruby-forum.com/u/guydols)\
**Post date:** [March 3, 2009, 10:36pm UTC](https://www.ruby-forum.com/t/fixnum-problem-plz-help/161925/3 "2009-03-03T22:36:47Z")

</div>

Guy D. wrote:

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

---

<div class="post-metadata">

**Author:** ![guydols](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a6a055/32.png) [@guydols](https://www.ruby-forum.com/u/guydols)\
**Post date:** [March 3, 2009, 10:45pm UTC](https://www.ruby-forum.com/t/fixnum-problem-plz-help/161925/4 "2009-03-03T22:45:34Z")

</div>

Guy D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> my answer is  
> 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
> 
> but i should be 730

I think you are lying. Twice.

First, the answer is probably not what you’re telling but rather:

22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222

Then it should NOT be 730, but what you get.

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!

---

<div class="post-metadata">

**Author:** ![guydols](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a6a055/32.png) [@guydols](https://www.ruby-forum.com/u/guydols)\
**Post date:** [March 3, 2009, 10:52pm UTC](https://www.ruby-forum.com/t/fixnum-problem-plz-help/161925/5 "2009-03-03T22:52:03Z")

</div>

Pascal J. Bourguignon wrote:

> > puts days

Unsuccessful troll is unsuccessful.

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

---

<div class="post-metadata">

**Author:** ![guydols](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a6a055/32.png) [@guydols](https://www.ruby-forum.com/u/guydols)\
**Post date:** [March 4, 2009, 12:14am UTC](https://www.ruby-forum.com/t/fixnum-problem-plz-help/161925/6 "2009-03-04T00:14:10Z")

</div>

On Tue, 03 Mar 2009 16:28:48 -0500, Guy D. wrote:

> my answer is

222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222

> but i should be 730
> 
> i have an screenshot as an attachment plz help me

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

---

<div class="post-metadata">

**Author:** ![guydols](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a6a055/32.png) [@guydols](https://www.ruby-forum.com/u/guydols)\
**Post date:** [March 4, 2009, 1:21am UTC](https://www.ruby-forum.com/t/fixnum-problem-plz-help/161925/7 "2009-03-04T01:21:24Z")

</div>

Pascal J. Bourguignon wrote:

> > puts days
> 
> > 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.

–

```auto
Tom C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)

```

---

<div class="post-metadata">

**Author:** ![guydols](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a6a055/32.png) [@guydols](https://www.ruby-forum.com/u/guydols)\
**Post date:** [March 4, 2009, 9:05am UTC](https://www.ruby-forum.com/t/fixnum-problem-plz-help/161925/8 "2009-03-04T09:05:55Z")

</div>

Pascal J. Bourguignon wrote:

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

Typo. Should be Commune Lisp.

> you’d get an error:
> 
> C/USER[929]\> (\* “2” 365)
> 
> \*\*\* - \*: “2” is not a number

Commune Lisp:  
(\* “2” 9)  
\*\*\* ERROR!!! \*\*\*

Awk:  
“2” \* 9  
18

Ruby:  
“2” \* 9  
“222222222”

Now, which is the lowest-level language?

---

<div class="post-metadata">

**Author:** ![guydols](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a6a055/32.png) [@guydols](https://www.ruby-forum.com/u/guydols)\
**Post date:** [March 4, 2009, 10:00am UTC](https://www.ruby-forum.com/t/fixnum-problem-plz-help/161925/9 "2009-03-04T10:00:27Z")

</div>

Pascal J. Bourguignon wrote:

> 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

This is nothing to do with “strongly typed”. Ruby’s concept of the  
difference between a string and an integer is just as strict as LISP’s.

Rather, Ruby provides semantics to the ‘\*’ operator/function for strings  
which LISP doesn’t.

You can get exactly the behaviour you desire by _removing_ some Ruby  
functionality.

irb(main):001:0\> String.class\_eval { undef\_method(:_) }  
=\> String  
irb(main):002:0\> “2” \* 365  
NoMethodError: undefined method `_’ for “2”:String  
from (irb):2  
from :0

---

<div class="post-metadata">

**Author:** ![guydols](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a6a055/32.png) [@guydols](https://www.ruby-forum.com/u/guydols)\
**Post date:** [March 4, 2009, 10:50am UTC](https://www.ruby-forum.com/t/fixnum-problem-plz-help/161925/10 "2009-03-04T10:50:34Z")

</div>

Brian C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> from (irb):2  
> from :0

Right, it is too much overloading, not weak typing. Sorry for the  
confusion.

---

<div class="post-metadata">

**Author:** ![guydols](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a6a055/32.png) [@guydols](https://www.ruby-forum.com/u/guydols)\
**Post date:** [March 4, 2009, 2:07pm UTC](https://www.ruby-forum.com/t/fixnum-problem-plz-help/161925/11 "2009-03-04T14:07:34Z")

</div>

2009/3/4 William J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Typo. Should be Commune Lisp.
> 
> Awk:  
> “2” \* 9  
> 18
> 
> Ruby:  
> “2” \* 9  
> “222222222”

C:  
printf(“%d\n”,‘2’\*9);  
450

---

<div class="post-metadata">

**Author:** ![guydols](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a6a055/32.png) [@guydols](https://www.ruby-forum.com/u/guydols)\
**Post date:** [March 4, 2009, 6:53pm UTC](https://www.ruby-forum.com/t/fixnum-problem-plz-help/161925/12 "2009-03-04T18:53:01Z")

</div>

On Mar 3, 3:49 pm, Michael M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Unsuccessful troll is unsuccessful.

I had to re-read the post to be sure it actually came from Pascal.  
After all, there were no nested parens in the entire thing.

---

<div class="post-metadata">

**Author:** ![guydols](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a6a055/32.png) [@guydols](https://www.ruby-forum.com/u/guydols)\
**Post date:** [March 5, 2009, 10:24pm UTC](https://www.ruby-forum.com/t/fixnum-problem-plz-help/161925/13 "2009-03-05T22:24:30Z")

</div>

On Tue, Mar 3, 2009 at 10:43 PM, Pascal J. Bourguignon  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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

---

<div class="post-metadata">

**Author:** ![guydols](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a6a055/32.png) [@guydols](https://www.ruby-forum.com/u/guydols)\
**Post date:** [March 5, 2009, 10:26pm UTC](https://www.ruby-forum.com/t/fixnum-problem-plz-help/161925/14 "2009-03-05T22:26:53Z")

</div>

On Wed, Mar 4, 2009 at 6:51 PM, Yossef M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> On Mar 3, 3:49 pm, Michael M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Unsuccessful troll is unsuccessful.
> 
> I had to re-read the post to be sure it actually came from Pascal.  
> After all, there were no nested parens in the entire thing.

But the nested parens occur in Lisp, right, Pascal is the thing with  
“:=” or am I confused here? (Maybe I should go to Delphi to seek some  
guidance)

R.
