Hash :
878abc6d
Author :
Thomas de Grivel
Date :
2025-07-25T12:54:10
typo in doc
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
return or return_from :name you can return an abitrary value from
the block, expressions after return are not executed.
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)
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
# 1.26 Named block
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
`return` or `return_from :name` you can return an abitrary value from
the block, expressions after return are not executed.
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)
## 1.26.1 Examples
```elixir
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](/doc/)
Previous : [1.25 Facts](1.25_Facts)
Next : [2 HTTPd](../2_HTTPd)