In KC3, a named block is a macro that allows you to do debranching
returns. First you create a block using block :name do ... end
,
then using either return
, or return_from :name
you can return
an abitrary value from the named block. Expressions after return
are not evaluated.
In the case where two blocks have the same name, the most inner block
is selected for return
.
All KC3 functions have their algorithm evaluated inside an implicit named block which has the name of the function (the first symbol the function was bound to)
On our way to inverted code golf, all forms of return x
are
completely equivalent to return_from void x
.
ikc3> block :abc do
ikc3> return 1
ikc3> 123
ikc3> end
1
ikc3> block :abc do
ikc3> return_from :abc 1 + 1
ikc3> 123
ikc3> end
2
ikc3> abc = fn () {
ikc3> return 1
ikc3> 123
ikc3> }
fn () {
return 1
123
}
ikc3> abc()
1
ikc3> abc = fn () {
ikc3> return_from :abc 2 + 2
ikc3> 123
ikc3> }
fn () {
return_from :abc 2 + 2
123
}
ikc3> abc()
4
Top : KC3 documentation
Previous : 1.25 Facts
Next : 2 HTTPd