Clarifying the meaning of "block parameter"

The name “block parameter” means two things:

  • The ultimate parameter in a def or macro that accepts a block argument:
    def foo(&x) # `x` is a block parameter
    end
    
    def foo(**a, b) # Error: only block parameter is allowed after double splat
    end
    
  • A parameter of a block argument to a call:
    foo do |x| # `x` is a block parameter
    end
    
    foo do | | # Error: expecting block parameter name, not |
    end
    

Can we be more specific about these two concepts?

3 Likes

block parameter and block variable?

3 Likes

block parameter and block argument? block variable might be confused with a variable created inside a block

1 Like

oh, good call :+1:

1 Like
def bar(&blk : Int32 -> _)
  blk.call(100)
end

def foo(&blk : Int32 -> _)
  bar(&blk)  # <== this &blk is call block argument?
end

foo do |x|
  p x
end

I think the term there would be captured block.

1 Like

But &x does not necessarily imply capturing, first because it can go unused, and second because the same syntax is used for macro blocks:

macro foo(&x)
end

foo # okay, `x` is a `Nop`

The block is there regardless of whether & or &x is used, since the & alone already signifies the presence of a block parameter. The difference is whether that block is named or anonymous.

So my conclusion would be block name for the former and block parameter for the latter.