[MacRuby] #381: Losing track of a defined constant - possibly related to Module.autoload
#381: Losing track of a defined constant - possibly related to Module.autoload -----------------------------------+---------------------------------------- Reporter: kamal.fariz@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: MacRuby 0.5 Component: MacRuby | Keywords: autoload require constants -----------------------------------+---------------------------------------- There seems to be a bug in the interaction of autoload and requires. I tried hard to reduce this with no success. However, here is the smallest snippet that will illustrate this bug: {{{ $ macruby -rubygems -rrack -r"rack/builder" -e "Rack::Builder" core:in `require:': uninitialized constant Rack::Builder (NameError) }}} If you remove the require to "rack/builder", MacRuby will autoload Rack::Builder normally and no exception will be raised. {{{ $ macruby -rubygems -rrack -e "Rack::Builder" }}} in rack.rb, it defines {{{ autoload :Builder, "rack/builder" }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/381> MacRuby <http://macruby.org/>
#381: Losing track of a defined constant - possibly related to Module.autoload -----------------------------------+---------------------------------------- Reporter: kamal.fariz@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: MacRuby 0.5 Component: MacRuby | Keywords: autoload require constants -----------------------------------+---------------------------------------- Comment(by lsansonetti@…): Actually, #autoload has not been implemented yet. -- Ticket URL: <http://www.macruby.org/trac/ticket/381#comment:1> MacRuby <http://macruby.org/>
#381: Losing track of a defined constant - possibly related to Module.autoload ----------------------------------------+----------------------------------- Reporter: kamal.fariz@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: minor | Milestone: MacRuby 0.5 Component: MacRuby | Resolution: fixed Keywords: autoload require constants | ----------------------------------------+----------------------------------- Changes (by lsansonetti@…): * status: new => closed * resolution: => fixed Comment: Should be fixed in r2792. {{{ $ macruby -rubygems -rrack -r"rack/builder" -e "Rack::Builder; p 42" 42 }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/381#comment:2> MacRuby <http://macruby.org/>
Hi all! Using Cocoa in MacRuby is sometimes a hard job, because all documentation, examples and sample code is Obj-C. For example, I found this piece of code '[NSNumber numberWithBool:NO]' and asked myself how to write that in Macruby. I opened macirb and typed:
NSNumber.numberWithBool 0 => false
First I had to laugh and then I thought: Hey implementors of macruby, you really did a great job! What do you think about a table on http://www.macruby.org/ which lists all such short (and astonishing) examples. Or even better, why not create a command in the services menu which translates a Obj-C sequence (by regexp). BTW, the second example I tried is:
NSDictionary.dictionaryWithObjectsAndKeys "a", "b", nil
but instead of {"b"=>"a"} I got a seg fault! (ticket is filed) Greets, Bernd
Hi Bernd, YES and NO in ObjC are translated to true and false in MacRuby. so you were probably after: NSNumber.numberWithBool(false) (I am curious as to how often that is useful actually) I will leave the table idea for others to comment - I actually think in the end there are only a few rules to learn and then you will find yourself translating easily (not that those rules should not go in a cheat sheet somewhere - that's probably a good idea). With: NSDictionary.dictionaryWithObjectsAndKeys "a", "b", nil I assume that in the original ObjC method is actually passing an array which (it seems) must be terminated by a nil (in objC). I actually ran across this in another context - passing objects in this way - again I will leave others to comment on it, perhaps it is an issue. However why can't you use : dict = {"b"=>"a"} => {"b"=>"a"} #check class of created dictionary dict.class => NSMutableDictionary Why use the long winded ObjC form? If you need a immutable NSDictionary for some reason: dict = NSDictionary.alloc.initWithDictionary({"a"=>"b", "c" => "d"}) #or if you like typing dict = NSDictionary.dictionaryWithObjects(["b","d"], forKeys: ["a","c"],count:1) (and many other similar methods, I am sure) works fine. Cheers, John On Oct 14, 2009, at 10:03 , B. Ohr wrote:
Hi all!
Using Cocoa in MacRuby is sometimes a hard job, because all documentation, examples and sample code is Obj-C. For example, I found this piece of code '[NSNumber numberWithBool:NO]' and asked myself how to write that in Macruby.
I opened macirb and typed:
NSNumber.numberWithBool 0 => false
First I had to laugh and then I thought: Hey implementors of macruby, you really did a great job!
What do you think about a table on http://www.macruby.org/ which lists all such short (and astonishing) examples. Or even better, why not create a command in the services menu which translates a Obj-C sequence (by regexp).
BTW, the second example I tried is:
NSDictionary.dictionaryWithObjectsAndKeys "a", "b", nil
but instead of {"b"=>"a"} I got a seg fault! (ticket is filed)
Greets, Bernd
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Hi John, Am 14.10.2009 um 10:34 schrieb John Shea:
Hi Bernd,
YES and NO in ObjC are translated to true and false in MacRuby.
so you were probably after:
NSNumber.numberWithBool(false)
(I am curious as to how often that is useful actually)
I will leave the table idea for others to comment - I actually think in the end there are only a few rules to learn and then you will find yourself translating easily (not that those rules should not go in a cheat sheet somewhere - that's probably a good idea).
Shure, there are only few rules, but: 1. there are newbies outside (most of the Obj-C programmers) 2. why should I manually correct those Obj-C things like [aObj: foo] a thousand times when it can easily be done by a regexp? I don't want a real translator, I am wanting just a simple []-remover!
With: NSDictionary.dictionaryWithObjectsAndKeys "a", "b", nil
I assume that in the original ObjC method is actually passing an array which (it seems) must be terminated by a nil (in objC). I actually ran across this in another context - passing objects in this way - again I will leave others to comment on it, perhaps it is an issue.
However why can't you use :
dict = {"b"=>"a"} => {"b"=>"a"}
#check class of created dictionary dict.class => NSMutableDictionary
Why use the long winded ObjC form?
Perhaps you misunderstood me. I know this already and I don't want to use the long form, I just typed that in macirb to use the RESULT (in this case {"b"=>"a"}). Perhaps this is the way a Obj-C programmer is trying out MacRuby because of lacking of documentation. Bernd
Hi, On Oct 14, 2009, at 1:03 AM, B. Ohr wrote:
Hi all!
Using Cocoa in MacRuby is sometimes a hard job, because all documentation, examples and sample code is Obj-C. For example, I found this piece of code '[NSNumber numberWithBool:NO]' and asked myself how to write that in Macruby.
You can simply pass true or false and MacRuby will do the conversion for you.
I opened macirb and typed:
NSNumber.numberWithBool 0 => false
First I had to laugh and then I thought: Hey implementors of macruby, you really did a great job!
And NSNumbers are converted to Ruby types as you just experienced :)
What do you think about a table on http://www.macruby.org/ which lists all such short (and astonishing) examples. Or even better, why not create a command in the services menu which translates a Obj-C sequence (by regexp).
I think a short tutorial/page on the website would be great, indeed. I don't believe it is easily possible to write an Objective-C -> MacRuby convertor that works most/all the time (because of the C nature of ObjC).
BTW, the second example I tried is:
NSDictionary.dictionaryWithObjectsAndKeys "a", "b", nil
but instead of {"b"=>"a"} I got a seg fault! (ticket is filed)
I replied to the ticket, it seems you forgot to do `framework 'Foundation'' first. Laurent
Hi, Am 14.10.2009 um 11:04 schrieb Laurent Sansonetti:
Hi,
On Oct 14, 2009, at 1:03 AM, B. Ohr wrote:
Hi all!
Using Cocoa in MacRuby is sometimes a hard job, because all documentation, examples and sample code is Obj-C. For example, I found this piece of code '[NSNumber numberWithBool:NO]' and asked myself how to write that in Macruby.
You can simply pass true or false and MacRuby will do the conversion for you.
Oh yes, in my example project , I automatically used true and it worked. But then I began asking myself, how can I be shure that this is the correct way and what would an absolute beginner do and then i opened macirb... ;-)
I opened macirb and typed:
NSNumber.numberWithBool 0 => false
First I had to laugh and then I thought: Hey implementors of macruby, you really did a great job!
And NSNumbers are converted to Ruby types as you just experienced :)
In the docs + (NSNumber *)numberWithBool:(BOOL)value gives a NSNumber and not a TrueClass or FalseClass as in Macruby. I only wanted to say how impressed I am!
What do you think about a table on http://www.macruby.org/ which lists all such short (and astonishing) examples. Or even better, why not create a command in the services menu which translates a Obj-C sequence (by regexp).
I think a short tutorial/page on the website would be great, indeed. I don't believe it is easily possible to write an Objective-C -> MacRuby convertor that works most/all the time (because of the C nature of ObjC).
Such a cheat sheet can easily show the beauty of MacRuby and the "noisiness" of Obj-C! ;-) I agree that a real translator is impossible. What I want is a simple text processing which removes all the [foo: bar baz] and replaces it with foo.bar(baz).
BTW, the second example I tried is:
NSDictionary.dictionaryWithObjectsAndKeys "a", "b", nil
but instead of {"b"=>"a"} I got a seg fault! (ticket is filed)
I replied to the ticket, it seems you forgot to do `framework 'Foundation'' first.
Oh, my fault! But wouldn't it be better NOT to respond with a segment fault (this irritated me) and instead throw an normal ruby exception? (But perhaps that is impossible.) Bernd
Hi, On Oct 14, 2009, at 2:34 AM, B. Ohr wrote:
Hi,
Am 14.10.2009 um 11:04 schrieb Laurent Sansonetti:
Hi,
On Oct 14, 2009, at 1:03 AM, B. Ohr wrote:
Hi all!
Using Cocoa in MacRuby is sometimes a hard job, because all documentation, examples and sample code is Obj-C. For example, I found this piece of code '[NSNumber numberWithBool:NO]' and asked myself how to write that in Macruby.
You can simply pass true or false and MacRuby will do the conversion for you.
Oh yes, in my example project , I automatically used true and it worked. But then I began asking myself, how can I be shure that this is the correct way and what would an absolute beginner do and then i opened macirb... ;-)
I opened macirb and typed:
NSNumber.numberWithBool 0 => false
First I had to laugh and then I thought: Hey implementors of macruby, you really did a great job!
And NSNumbers are converted to Ruby types as you just experienced :)
In the docs
+ (NSNumber *)numberWithBool:(BOOL)value
gives a NSNumber and not a TrueClass or FalseClass as in Macruby. I only wanted to say how impressed I am!
Hehe, thank you :)
What do you think about a table on http://www.macruby.org/ which lists all such short (and astonishing) examples. Or even better, why not create a command in the services menu which translates a Obj-C sequence (by regexp).
I think a short tutorial/page on the website would be great, indeed. I don't believe it is easily possible to write an Objective- C -> MacRuby convertor that works most/all the time (because of the C nature of ObjC).
Such a cheat sheet can easily show the beauty of MacRuby and the "noisiness" of Obj-C! ;-)
If you or anyone are willing to work on this, feel free and we can integrate it later on the website.
I agree that a real translator is impossible. What I want is a simple text processing which removes all the [foo: bar baz] and replaces it with foo.bar(baz).
I see. That should be easy then :)
BTW, the second example I tried is:
NSDictionary.dictionaryWithObjectsAndKeys "a", "b", nil
but instead of {"b"=>"a"} I got a seg fault! (ticket is filed)
I replied to the ticket, it seems you forgot to do `framework 'Foundation'' first.
Oh, my fault! But wouldn't it be better NOT to respond with a segment fault (this irritated me) and instead throw an normal ruby exception? (But perhaps that is impossible.)
It's unfortunately not possible, we crash when calling the method because we don't use the right ABI conventions (since the method is variadic) and there is no way we can determine that at runtime. This is why we need to load the framework metadata (BridgeSupport file) in order to handle these methods. Laurent
participants (4)
-
B. Ohr
-
John Shea
-
Laurent Sansonetti
-
MacRuby