3 ms·
This is Polish notation [1], which puts a symbol for the function at the front of a term and the arguments of that function after it. So (* 2 3) is what you'd u
by rachofsunshine 3y ago
This is Polish notation [1], which puts a symbol for the function at the front of a term and the arguments of that function after it. So (* 2 3) is what you'd usually write as 2*3.
So you can read this code:
(define (expt n p)
(if (equals? p 1)
n
(* n (expt n (- p 1)))
As this more typical psuedocode
function expt(n,p):
if p = 1:
return n
return n * exp(n, p-1)
Or the more mathematical framing:
n^p = n * n^(p-1)
[1] https://en.wikipedia.org/wiki/Polish_notation https://en.wikipedia.org/wiki/Polish_notation