Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Named anonymous functions are there to allow you to call the function recursively while inside it.

i.e.

    (= ((fn factorial [x] 
          (if (<= x 1) 
              1 
              (* x (factorial (dec x))))) 5)
     120)
Note, this isn't run under TCO (see loop/recur).


Also, in your example, the recursive call is not in tail position. You would first need to rewrite it to use an acumulator parameter.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: