Skip to content

Instantly share code, notes, and snippets.

@jjatria
Created August 28, 2015 16:55
Show Gist options
  • Save jjatria/cb03a2afe1691145dc01 to your computer and use it in GitHub Desktop.
Save jjatria/cb03a2afe1691145dc01 to your computer and use it in GitHub Desktop.
Factorial procedure
# 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