Nested function: Difference between revisions

Content added Content deleted
(Added Kotlin)
Line 847: Line 847:


print(makeList(". "))</lang>
print(makeList(". "))</lang>

=={{header|Tcl}}==
The code below satisfies the specification (inspired by the Swift example). The inner function is defined, called, and then discarded by renaming to {}.
<lang Tcl>
#!/usr/bin/env tclsh

proc MakeList separator {
set counter 1
proc MakeItem string {
upvar 1 separator separator counter counter
set res $counter$separator$string\n
incr counter
return $res
}
set res [MakeItem first][MakeItem second][MakeItem third]
rename MakeItem {}
return $res
}
puts [MakeList ". "]
</lang>


=={{header|zkl}}==
=={{header|zkl}}==