It seems like DMD doesn't optimize tail recursion very well

sailormoontw sailormoontw_member at pathlink.com
Fri Jun 9 08:44:09 PDT 2006


It takes twice the time for D to do the same job...
but at least it's better than Ruby, Common Lisp, and Haskell
these 3 all failed...either stack overflow or halted.

Ruby:

def Ack(a,b)
return b + 1 if a == 0
return Ack(a-1, 1) if b == 0
Ack(a-1, Ack(a, b-1))
end 

Common Lisp:

(defun ack (a b)
(cond 
((equal a 0) (1+ b))
((equal b 0) (ack (1- a) 1))
(t (ack (1- a) (ack a (1- b))))))

Haskell:

ack :: Int -> Int -> Int
ack 0 b = b+1
ack a 0 = ack (a-1) 1
ack a b = ack (a-1) (ack a (b-1))





More information about the Digitalmars-d mailing list