Fork me on GitHub

letfn is an IOC boundary as a whole, but it seems only bound functions should be, not the body. e.g (a/go (letfn [(f [x] (do-something-with x))] (f (a/<! port)))) looks perfectly legit to me, but fails because <! is outside of go boundaries. Is this intended, and why ?


letfn is a special from with special semantics (namely that you can use any of the fns that you define in its bindings in any order), which I think is the issue. it holds onto the body of the letfn until the very last minute, so the go block can't properly see the <! to transform it away.


I can't really explain it very well, but if you do something like (clojure.walk/macroexpand-all '(go (letfn [(f [x] (println x))] (f (<! port))))) vs (clojure.walk/macroexpand-all '(go (let [f (fn [x] (println x))] (f (<! port))))) then you can see that the (f (<! port)) still exists in the paren soup that gets spit out in the first case, but it works how you're expecting in the second case


so basically, the explanation is that letfn is weird


also, that might just be a bug?


looks like a bug to me


i'll take a look if you make a ticket to track this @leonoel


ha yeah, I typed all of that up and then thought about it one more time and realized it's probably just a bug


can't wait to hear about your strategy on this one @bronsa that sounds definitely fixable but all the solutions I can think of fight against the overall design


the fix is actually trivial AFAICT


@leonoel I've attached a patch, give it a spin

Alex Miller (Clojure team)14:10:54

that looks pretty simple. can someone add a test?


I'll turn the example in the ticket into one and update the patch


it works by coincidence, I fear


the even? function can't see odd? because it's not bound yet


it works because clojure.core has a function named odd?, but if you rename it then it won't compile


my example isn't that good 🙂


I see what's happening


it's collapsing the letfn into a regular let


it's binding the name of the fn after the fn has been defined, but that means that odd? doesn't exist when even? is defined


which happens to work when you use odd? and even? but if you change the names of the functions, it breaks

Erik Thorselius16:10:00

Hi! I'm having problem with integrant and channels in the repl. When I start the application all my channels works fine. Then when I stop and start again, it is like the new channels are closed. When I send a message on the channel it replies with false. On the halt-hook I'm closing the existing channels and when starting again I'm creating new ones. Should I try to keep them when restaring or is there anything else I'm doing wrong?


Are your functions referencing old channels somehow?


I do something very similar with integrant and works just fine


This is likely more relevant for #integrant channel

Erik Thorselius16:10:55

aaa sorry I'm new here. I will check in the integrant channel


No worries! 😄


heh, I hadn't connected my brain yet @leonoel, I'll make another patch handing this correctly


should still be relatively easy, just not that trivial :)

😎 4