Nested function: Difference between revisions

J draft
(Wrote a proper task description)
(J draft)
Line 50:
 
Console.WriteLine(MakeList(". "));</lang>
 
=={{header|J}}==
 
J does not have nested scopes, so they must be emulated. (The design philosophy here is that nesting tends to become difficult to understand when taken too far, so the coder and designer should be mildly penalized with extra work for choosing nesting as opposed to some other problem solving approach.)
 
That said, emulating a single level of nesting is relatively trivial and does not reflect the complexities necessary for more elaborate (and more difficult to understand) cases:
 
<lang J>MakeList=: dyad define
sep_MakeList_=: x
cnt_MakeList_=: 0
;MakeItem each y
)
 
MakeItem=: verb define
cnt_MakeList_=: cnt_MakeList_+1
(":cnt_MakeList_),sep_MakeList_,y,LF
)</lang>
 
Example use:
 
<lang J> '. ' MakeList 'first';'second';'third'
1. first
2. second
3. third
</lang>
 
=={{header|JavaScript}}==
6,962

edits