Jump to content

Mutual recursion: Difference between revisions

smalltalk
(smalltalk)
Line 170:
 
In python there is no need to pre-declare ''M'' for it to be used in the definition of ''F''. (However ''M'' must be defined before ''F'' calls it).
 
=={{header|Smalltalk}}==
 
Using block closure.
 
<lang smalltalk>|F M ra rb|
 
F := [ :n |
(n == 0)
ifTrue: [ 1 ]
ifFalse: [ n - (M value: (F value: (n-1))) ]
].
 
M := [ :n |
(n == 0)
ifTrue: [ 0 ]
ifFalse: [ n - (F value: (M value: (n-1))) ]
].
 
ra := OrderedCollection new.
rb := OrderedCollection new.
0 to: 19 do: [ :i |
ra add: (F value: i).
rb add: (M value: i)
].
 
ra displayNl.
rb displayNl.</lang>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.