Arc Forumnew | comments | leaders | submitlogin
3 points by almkglor 5949 days ago | link | parent

Use:

  (range 0 i)
instead of:

  (indices (+ i 1))
If you're willing to wait for your code to compile, you can even use Anarki, (require "ssyntaxes.arc"), and use:

  0..i
instead of:

  (indices (+ i 1))
Edit: Also, factorial is pure anyway, so you might have some performance improvement by using defmemo instead of plain def.

Edit2: It's also better to use true tail recursion:

  (def factorial (n)
    ((afn (acc n)
      (if (< n 2)
          acc
          (self (* acc n) (- n 1))))
      1 n))