Jump to content

Nested function: Difference between revisions

Added R. Rather short.
m (→‎{{header|Phix}}: corrected version and grammar)
(Added R. Rather short.)
Line 1,190:
 
print(makeList(". "))</lang>
=={{header|R}}==
 
This also shows that cat's sep argument is not the same as MakeList's.
<lang r>MakeList <- function(sep)
{
counter <- 0
MakeItem <- function() paste0(counter <<- counter + 1, sep, c("first", "second", "third")[counter])
cat(replicate(3, MakeItem()), sep = "\n")
}
MakeList(". ")</lang>
{{out}}
<pre>1. first
2. second
3. third</pre>
=={{header|Racket}}==
See also [[#Scheme]]; this demonstrates <code>map</code> a higher order function and <code>begin0</code> a form which saves us having to explicitly remember the result.
331

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.