C
cnb
which is more idiomatic? amazing how similar ruby and python are.
and what does the guy mean with "pure" here:
http://www.linuxjournal.com/article/4834
that it is purely OO and consequent? Would Python be impure in his
meaning of pure?
def fib(n, a=0, b=1)
if n > 0
then fib(n-1, a+b, a)
else a
end
end
def fibo(n)
a, b = 0, 1
while n > 0
a, b, n = a+b, a, n-1
end
a
end
def fac(n, acc=1)
if n > 0
then fac(n-1, n*acc)
else acc
end
end
def fac2(n)
acc = 1
for x in 1...n+1
acc *= x
end
return acc
end
and what does the guy mean with "pure" here:
http://www.linuxjournal.com/article/4834
that it is purely OO and consequent? Would Python be impure in his
meaning of pure?
def fib(n, a=0, b=1)
if n > 0
then fib(n-1, a+b, a)
else a
end
end
def fibo(n)
a, b = 0, 1
while n > 0
a, b, n = a+b, a, n-1
end
a
end
def fac(n, acc=1)
if n > 0
then fac(n-1, n*acc)
else acc
end
end
def fac2(n)
acc = 1
for x in 1...n+1
acc *= x
end
return acc
end