For that conversion, #to_i could have been used as well, and then '09' would
be interpreted as decimal 9. Why should I expect my string to be passed
through Integer() before formatting? That is not documented.
Why would you pass a string to something that expects a number
anyway?
For that conversion, #to_i could have been used as well, and then '09' would
be interpreted as decimal 9. Why should I expect my string to be passed
through Integer() before formatting? That is not documented.
Why would you pass a string to something that expects a number
anyway?
Actually, let me say this, as it's more informative and
constructive.
If you need to convert your string to a number, it's best
to do so explicitly. (If you really want to pass a string
into sprintf, %s is the correct modifier.)
Also note that while Integer() doesn't convert the way
you want, to_i does:
Hal
all you are saying is true BUT
I do not think we should blame C for something which really is not nice.
I know not many share my opinion but the brave speaks out nevertheless
IMHO the interpreter should raise an expression when a String is passed to
%d (as you asked OP rightfully not to do so).
Early Failure, please, *early*.
BTW who is talking about sprintf I am talking about "%" a very rubish
construct.
Cheers
Robert
···
On 8/19/06, Hal Fulton <hal9000@hypermetrics.com> wrote:
Hal Fulton wrote:
> Carlos wrote:
>
>>
>> For that conversion, #to_i could have been used as well, and then '09'
>> would
>> be interpreted as decimal 9. Why should I expect my string to be passed
>> through Integer() before formatting? That is not documented.
>>
>
> Why would you pass a string to something that expects a number
> anyway?
Actually, let me say this, as it's more informative and
constructive.
If you need to convert your string to a number, it's best
to do so explicitly. (If you really want to pass a string
into sprintf, %s is the correct modifier.)
Also note that while Integer() doesn't convert the way
you want, to_i does:
Integer("09") # error
"09".to_i # 9
Cheers,
Hal
--
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.
Hal
all you are saying is true BUT
I do not think we should blame C for something which really is not nice.
I know not many share my opinion but the brave speaks out nevertheless
IMHO the interpreter should raise an expression when a String is passed to
%d (as you asked OP rightfully not to do so).
Early Failure, please, *early*.
I see your point. Truthfully, I think automatic conversion of a
string in this case is probably a bad idea. And that is a Ruby
issue, not a C one.
BTW who is talking about sprintf I am talking about "%" a very rubish
construct.
But format % array behaves the same as sprintf(format,*array)
The specifiers are the same (and the same as C, perhaps with a few
minor differences).
Robert Dober wrote:
>>
> Hal
> all you are saying is true BUT
> I do not think we should blame C for something which really is not nice.
> I know not many share my opinion but the brave speaks out nevertheless
>
> IMHO the interpreter should raise an expression when a String is passed
to
> %d (as you asked OP rightfully not to do so).
> Early Failure, please, *early*.
I see your point. Truthfully, I think automatic conversion of a
string in this case is probably a bad idea. And that is a Ruby
issue, not a C one.
> BTW who is talking about sprintf I am talking about "%" a very rubish
> construct.
But format % array behaves the same as sprintf(format,*array)
Yup, I failed to be clear about this sorry for wasting Austin's and your
time.
I should have said
even more so as we have the % operator which looking very rubish still
has these
C caveats.
Anyway I am more than happy that you share my POV
Cheers
Robert
The specifiers are the same (and the same as C, perhaps with a few
···
On 8/20/06, Hal Fulton <hal9000@hypermetrics.com> wrote: