Created
August 28, 2015 16:55
-
-
Save jjatria/cb03a2afe1691145dc01 to your computer and use it in GitHub Desktop.
Factorial procedure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Calculate the factorial of a number using | |
# a recursive procedure. | |
# A demonstration of the limitations of Praat | |
# procedures (and of possible workarounds). | |
# | |
# Author: José Joaquín Atria | |
procedure factorial: .n | |
# Cannot use an inline if here | |
if !variableExists("factorial.level") | |
.level = 1 | |
else | |
.level += 1 | |
endif | |
.n[.level] = .n | |
if !.n | |
.a[.level] = 1 | |
else | |
@factorial: .n-1 | |
.a[.level] = .n[.level] * factorial.a[.level+1] | |
endif | |
.level -= 1 | |
endproc | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment