Chapter 1. About the Y-Combinator
The Y-Combinator is for recursive functions when the function cannot be named.
The mathematical definition for the Y-combinator is:
Where (\lambda x.x\ x) is the U-Combinator (Function self-caller), and (\lambda x.f(\lambda y.x\ x\ y)) is the combinator function. The \lambda y. x\ x\ y wrap is the “Evaluation delay”.
The argument for a Y-Combinator looks similar to this:
Where f is the recursive function, and x is the argument.
And, the Snap! 12.0.6 definition for the Y-Combinator block looks like the photo in Figure 1-1:
Make sure you build this for the next chapter for writing a class block.
The example is included in our other project “Y-Combinator Revised”, but for this topic, we will borrow the script from that project as an example.
Figure 1-2 is an alternative ring block for calculating factorials using a Y-Combinator.
This block can be evaluated by using the “call” block once again.
If you drag the “call” block into the first input slot, right-click the block, click “unringify,” and then expand the parameter slot, this block becomes able to evaluate.
Additionally, using the list function, you can define custom blocks with more than one parameter without a name, even if there is only one parameter, as if there were more than one.
In Figure 1-3, if you try the same method as above, that block becomes able to evaluate again. If you put a list block into the first parameter input slot, that block works.
Chapter 2. Writing a class block using the Y-Combinator in Snap! 12.0.6
To write a class block with calling a method of itself inside a method, without any this script block, you must need a Y-Combinator block.
First, create a new block. You can name the block to anything you want. In this topic, we will create the new counter block. Its definition looks like the photo in Figure 2-1 if you read the manual and try to code:
There are missing input slots labeled ???. So this is the reason why you should use a Y-Combinator to write a class block with calling a method of itself inside a method.
We can use the Y-Combinator to write a class block with the function that we mentioned. For many arguments in the ring, we can use the first-class lists. Now we can code using the similar thing for a Y-combinator to create it. The full definition now looks like the photo in Figure 2-2:
Press OK, and run the following code, and check the output in Figure 2-3:
If it works properly, You have mastered the Snap! OOP with Y-Combinators.
Chapter 3. Off-topics
Chapter 3-1. Off-topic 1
You can get the name of the language translator by building like the photo shown in Figure 3-1-1:
Then, right-click the block in the second block and select the “rename…” option from the menu. When you open the variable name menu, “language_translator” appears as the person who translated the project editor content, as shown in Figure 3-1-2.
Note that the variable name shown in the photo below, with its translated content, is not my name.







