# Correct terminology for a function that yields

**URL:** <https://www.ruby-forum.com/t/correct-terminology-for-a-function-that-yields/54214>\
**Category:** Ruby\
**Created:** [December 23, 2005, 1:00am UTC](https://www.ruby-forum.com/t/correct-terminology-for-a-function-that-yields/54214 "2005-12-23T01:00:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [December 23, 2005, 1:00am UTC](https://www.ruby-forum.com/t/correct-terminology-for-a-function-that-yields/54214/1 "2005-12-23T01:00:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [December 23, 2005, 1:19am UTC](https://www.ruby-forum.com/t/correct-terminology-for-a-function-that-yields/54214/2 "2005-12-23T01:19:09Z")

</div>

On 12/22/05, Edward F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [December 23, 2005, 9:39am UTC](https://www.ruby-forum.com/t/correct-terminology-for-a-function-that-yields/54214/3 "2005-12-23T09:39:14Z")

</div>

Joe Van D. 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
```

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [December 23, 2005, 1:07am UTC](https://www.ruby-forum.com/t/correct-terminology-for-a-function-that-yields/54214/4 "2005-12-23T01:07:01Z")

</div>

On Fri, Dec 23, 2005 at 09:00:31AM +0900, Joe Van D. 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
