In ruby 1.8.7 and 1.9.2 this
return 0.0but on maglev-head on OSX snow leopard I get a
ArgumentError: invalid value for Float(): "0.0"
from (irb):2:in `__compileEval'
ruby -v: maglev 1.0.0 (ruby 1.8.7) (2011-10-31 rev 1.0.0-27184)[Darwin x86_64]
uname -a: 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64
machine: macbook pro intel
I'm running same version of Snow Leopard and MagLev, but works for me. Did you install with RVM or from github?
One thing you can try:
1. export MAGLEV_OPTS="-d"
2. Run the code again.
When it gets the error, it should leave you at the topaz prompt. Type "where", and let us see the stack trace.
installed via rvm, stacktrace and pre-prompt is at https://gist.github.com/1330812 (github would not let me post it as a comment)
it appears to me that this could be a locale issue (I assume my machine has "italian" in some system variable), as Float('0,1') appears to work and I can see this happening:
$ ruby -e 'p 1/2.to_f'
so, I omitted: it is not zero related as I expected at first, but float related (Float("0,0") also returns a zero float).
this seems to affect string representation and the #Float method, while at the repl it seems stuff after the dot is silently dropped:
maglev-head :001 > a= 0.1
maglev-head :002 > b=0
maglev-head :003 > a == b
maglev-head :004 > c= 0,1
=> [0, 1]
maglev-head :005 > d= Float('0,1')
Thanks for the followup, I think I have enough to start working on it.
no problem, I can also confirm you that changing locale fixes the issue:
mecbucpro:~ riffraff$ LANG="en_US.UTF-8" ruby -e 'p Float("0.0")'
And for US English users, we can reproduce with:
```$ LANG="it_IT.UTF-8" maglev-ruby -e 'p Float("0.0")'
ERROR 2702 , invalid value for Float(): "0.0" (ArgumentError)
topaz 1> exitifnoerror
End of initialization files
The problem is that Smalltalk is locale aware, but Ruby isn't. Some operations (i.e., string to float conversion) are done in Smalltalk in a locale aware manner, but other operations are done in Ruby, which is ignorant of locale.
A quick workaround is to add export LANG=C to the beginning of bin/maglev-ruby. That will erase locale for sub-processes, but should "fix" the current problem, and provide consistent behavior for any other locale aware operations provided by Smalltalk.
Using LANG=C in front of any MagLev related command (e.g. LANG=C $MAGLEV_HOME/bin/bundle install) works for me..
LANG=C $MAGLEV_HOME/bin/bundle install
@pbm export LANG=C might be a problem when running "system" from within maglev and expecting it to pick up the surrounding locale. but maybe this is just nitpicking. I'd say go for it :)
Workaround issues with Locale aware Smalltalk methods.
Set LANG=C in maglev-ruby script. This essentially turns off locale aware
processing in Smalltalk. The down-side is that processes forked from
maglev-ruby will also have LANG=C.