letfn is not working at all

17 views
Skip to first unread message

Antony Lee

unread,
Nov 14, 2012, 6:03:46 AM11/14/12
to clojure-py-dev

I was trying to understand how the whole business of closures/aliases was resolved in compileFN when I noticed something wrong: the alias-resolving algorithm only ever goes forward, i.e. a new code object can only resolve aliases that had been defined before.  So the following (valid) code fails:

(letfn [(f [] (g)) (g [] nil)])

And of course it's not just an ordering problem -- you have to be able to define mutually recursive functions as well.

(letfn [(f [n] (if (zero? n) true (g (- n 1)))), (g [n] (if (zero? n) false (f (- n 1))))])

It seems like this will require quite some work at the level of compileFN.  A quick check tells me that clojure-jvm falls back on a letfn* special form that is implemented in java.  Urgh.

Any thoughts?

Antony
Reply all
Reply to author
Forward
0 new messages