ztellman/proteus — pull request #5 by trptcolin (2014-06-20 03:36:23+00:00)
Title: Bump to latest riddley (0.1.7)

letfn isn't having its locals registered as part of the letfn* transformation, so its bindings weren't visible to the analyzer inside nested let expressions. So swallowing analysis errors as riddley 0.1.7 gets this use case working, but the right fix is probably to register locals for letfn.

In digging into a potential locals-registering solution, my quicky & easy (but dirty, poking at internals) idea:
```diff
diff --git a/src/proteus.clj b/src/proteus.clj
index 7eadb2e..d73b710 100644
--- a/src/proteus.clj
+++ b/src/proteus.clj
@@ -50,7 +50,9 @@
vs' (map #(gensym (name %)) vs)]
`(let [~@(interleave vs' vs)
~@(interleave vs (map read-form vs))]
- (~'letfn* ~bindings
+ (~'letfn* ~((.get #'riddley.walk/let-bindings)
+ transform-let-mutable-form
+ bindings)
(let [~@(interleave vs vs')]
~(transform-let-mutable-form `(do ~@body))))))
```
didn't work, got a `java.lang.UnsupportedOperationException: Can't type hint a primitive local`.

Surprisingly (to me), inlining the implementation of `let-bindings` seemed to do the trick:

```diff
diff --git a/src/proteus.clj b/src/proteus.clj
index 7eadb2e..39b1c98 100644
--- a/src/proteus.clj
+++ b/src/proteus.clj
@@ -50,7 +50,14 @@
vs' (map #(gensym (name %)) vs)]
`(let [~@(interleave vs' vs)
~@(interleave vs (map read-form vs))]
- (~'letfn* ~bindings
+ (~'letfn* ~(->> bindings
+ (partition-all 2)
+ (mapcat
+ (fn [[k v]]
+ (let [[k v] [k (transform-let-mutable-form v)]]
+ (riddley.compiler/register-local k v))
+ [k v]))
+ vec)
(let [~@(interleave vs vs')]
~(transform-let-mutable-form `(do ~@body))))))
```

But that seemed pretty awful, and might not even be necessary - I don't have a full mental model of the consequences of analysis errors in this context.