There is a lot of confusion because there are terms with several definitions and several different things that come together simply because they usually occur together.
Firstly, we have a “block”. This is just a lexical piece of code that makes one - the body of the loop, for example. If the language actually has a block area, then variables can be defined that exist only within this code fragment.
Secondly, we call the code as a value type. In functional languages, these are function values, sometimes called "funs", "anonymous functions" (because the function is found in the value, and not in the name to which it is assigned, you do not need a name to call them), or "lambda" (from the operator used to create them in the calculus of the Lambda Church). They can be called “closures,” but they are not automatically true closures; in order to qualify, they must encapsulate (“close”) the lexical area surrounding their creation, that is, variables defined outside the scope of the function itself, but within its definition are still available when the function is called, even if the calling point is after how the reference variable would otherwise go out of scope and be reprocessed.
However, you may have callable code values that are not entire functions. Smalltalk calls these "block locks," and Ruby calls them "procs." But most rubists simply call them "blocks" because they are an updated version of what is created with the { ... } or do ... end syntax. What sets them apart from lambdas (or "closing functions") is that they do not introduce a new level of routine. If the code in the block closure cube calls return , it returns from the external function / method the closure of the block inside, and not just the block itself.
This behavior is critical to maintaining what RD Tenent called the "correspondence principle", which states that you should be able to replace any code with a built-in function that contains this code in the body and call it right away. For example, in Javascript you can replace this:
x = 2;
with this:
(function(){x = 2;})();
My example is not very interesting, but the ability to perform such a conversion, without affecting the behavior of the program, plays a key role in functional refactoring. The problem is that once you have built in the return , the principle no longer holds.
That's why Ruby has both procs and lambdas - a constant source of confusion for beginners. Both procs and lambdas are objects of the Proc class, but they behave differently, as described above: a return simply returns from the body of the lambda, but returns from the method surrounding proc. (Also, not related to the demarcation that I draw here, lambdas checks arity and complains if called with the wrong number of arguments. You can indicate what type you have by calling .lambda? On the object.)
Javascript currently only has function closures, although there is a suggestion in the table to introduce block locks for the language.