Arc Forumnew | comments | leaders | submitlogin
6 points by rincewind 6064 days ago | link | parent

these are tail-recursive:

  (def fac (n (o m 1)) 
    (if (> n 0) 
      (fac (- n 1) (* m n))
      m))

  (def sfac (n (o m 1)) 
    (if (> n 0) 
      (sfac (- n 1) (* m (fac n))) 
      m))
  
these use higher-order-functions:

  (def fac (n) (apply * (range 1 n)))

  (def sfac (n) (apply * (map fac (range 1 n))))