Forum: Ruby correct terminology for a function that yields

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 Joe Van Dyk (Guest)
on 2005-12-23 01:00
(Received via mailing list)
def foo
  yield
end

foo do
  puts "hey"
end


What's the correct description of what is going on there?  I've got a
function foo.  No arguments, right?  Does it "take a block"?  I know
it gives control to the block, but I'm not sure of the correct
terminology to use.

Joe
036a1b88dafaab8ffd73a8b0a74b5b38?d=identicon&s=25 Edward Faulkner (Guest)
on 2005-12-23 01:07
(Received via mailing list)
On Fri, Dec 23, 2005 at 09:00:31AM +0900, Joe Van Dyk wrote:
> function foo.  No arguments, right?  Does it "take a block"?  I know
> it gives control to the block, but I'm not sure of the correct
> terminology to use.

It does indeed "take a block".  The block argument is implicit.  You
could make it explicit if you wanted to:

def foo(&blk)
    blk.call
end

In more general terms, any function that takes another function as an
argument (or returns one as a result) is known as a higher-order
function.

regards,
Ed
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 Joe Van Dyk (Guest)
on 2005-12-23 01:19
(Received via mailing list)
On 12/22/05, Edward Faulkner <ef@alum.mit.edu> wrote:
> > What's the correct description of what is going on there?  I've got a
>
> In more general terms, any function that takes another function as an
> argument (or returns one as a result) is known as a higher-order
> function.

Ok, thanks.  I'm writing documentation for a domain-specific language
(in Ruby) that I created.  People who use it are probably programmers,
but may not be experienced with Ruby, so I wanted to explain a little
bit about what's going on behind the scenes.
5befe95e6648daec3dd5728cd36602d0?d=identicon&s=25 Robert Klemme (Guest)
on 2005-12-23 09:39
(Received via mailing list)
Joe Van Dyk wrote:
>>>
>> end
Note, that this has some performance implications though.

>> In more general terms, any function that takes another function as an
>> argument (or returns one as a result) is known as a higher-order
>> function.
>
> Ok, thanks.  I'm writing documentation for a domain-specific language
> (in Ruby) that I created.  People who use it are probably programmers,
> but may not be experienced with Ruby, so I wanted to explain a little
> bit about what's going on behind the scenes.

You can as well call the block "anonymous function" or "anonymous
callback" IMHO.  What I like about the "callback" variant is that it
precisely describes what's happening here: the caller provides a
function
as hook that is called by the method.

Kind regards

    robert
This topic is locked and can not be replied to.