On further digging, it seems like the exception raised when you return from a block (/Proc/lambda) is MacRuby specific. Seems like this should have been fixed a while ago:
def trigger_action(sender)
a_proc = Proc.new { |var|
puts "hello in proc"
return 1
}
a_proc.call('test')
puts "hello after proc"
end
That code runs without triggering an exception, and prints only "hello in proc" as expected. However, this variation on the code behaves differently:
def trigger_action(sender)
a_proc = Proc.new { |var|
puts "hello in proc"
return 1
}
a_lam = lambda { |var|
puts "hello in lambda"
return 1
}
a_lam.call('test')
puts "hello after lambda"
a_proc.call('test')
puts "hello after proc"
end
Now the code outputs the following:
hello in lambda
hello after lambda
hello in proc
uncaught Objective-C/C++ exception...
terminate called after throwing an instance of 'RoxorReturnFromBlockException*'
Program received signal: “SIGABRT”.
sharedlibrary apply-load-rules all
I can't quite understand why.
Anybody?
-Gabriel
That's not strictly true, you can if the Proc.new { } object was initialized within a method (like it is here).
On 30 Mar 2011, at 18:23, Gabriel Gilder wrote:
> I think you want "break" instead of "return". You can't return from a block (Proc).
>
> -Gabriel
However calling return explicitly will not return control to the caller.
Perhaps you could try a lambda, which behaves like a method when you use return explicitly (returns control to the caller), or
use break as Gabriel suggested.
- Rob
_______________________________________________
MacRuby-devel mailing list
MacRuby-devel@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel