[MacRuby-devel] [MacRuby] #712: Feature Request: Add Support for C-Level Blocks
MacRuby
ruby-noreply at macosforge.org
Thu May 13 11:14:17 PDT 2010
#712: Feature Request: Add Support for C-Level Blocks
-------------------------------+--------------------------------------------
Reporter: cwdinfo@… | Owner: lsansonetti@…
Type: enhancement | Status: new
Priority: blocker | Milestone: MacRuby 0.7
Component: MacRuby | Keywords: block
-------------------------------+--------------------------------------------
Comment(by cwdinfo@…):
Replying to [comment:1 martinlagardette@…]:
> I would say the 2nd and 3rd form wouldn't be good to implement.
>
> The 3rd one because, well, some parts are missing (the
`completionHandler:` part). The second one because this looks more like a
callback, rather than a Proc/lambda, and would have unexpected behavior
from a ruby point of view. In fact, Ruby-wise, it would be expected that
"handler" is called and its result is passed to completion handler.
>
> Otherwise, I agree 100% for the first form :-). I wanted to do it when
implementing the Proc as callback functions, but we had no C-block
supports at the time. I hope we can bring them to life (since a C-block is
not that far from a ruby-block, at least in principle).
I understand that the 2nd form appears more like a callback, but the
expectation of a functional programming language -- which Ruby debatably
is -- is that a Proc is a first-class citizen. Therefore, a method should
be usable where a Proc or a lambda is. Regarding the third, how about
syntax like:
{{{
open_panel.beginSheetModalForWindow(@main_window,
completionHandler:MACRUBY_BLOCK) do |arg|
puts "Hello, open file and user arg is #{arg}"
end
}}}
The benefit is that you don't wind up shoehorning all your code inside the
parentheses of a method call. Dangling close parens are syntax errors
waiting to happen.
--
Ticket URL: <http://www.macruby.org/trac/ticket/712#comment:2>
MacRuby <http://macruby.org/>
More information about the MacRuby-devel
mailing list