4

I'm trying to write a macro that takes a vector of bindings and a function that can access these bindings. In the simplest form:

(defmacro f-with-binds [binds f]
  `(let [~@binds]
     ~f))

even though the above works:

(f-with-binds [n 123 m 456] (println n m)) ;; => 123 456

I am not happy with this because Cursive highlights n and m as undeclared variables which does not happen for macros like for and let . How can I improve my implementation?

ps.: the real macro returns a transducer - bindings are the transducer's state and function is the transducer's step function

Tomas Zaoral
  • 499
  • 2
  • 5
  • 11
  • 3
    Maybe `let` and `for` are handled as special cases in Cursive? It's hard to say since Cursive is closed source. – juan.facorro May 27 '16 at 10:58
  • 1
    by the way, you don't need to do `[~@binds]`. You can use `(let ~binds ~f)`. – leetwinski May 27 '16 at 11:27
  • @leetwinski lol, you're right, thanks – Tomas Zaoral May 27 '16 at 11:36
  • 2
    This is a known issue in Cursive that is currently being worked on (see, for example https://github.com/cursive-ide/cursive/issues/147). For now the only remedy seems to be in the beta version `1.3.0-eap1`, where you can instruct Cursive to resolve bindings in your macro as if it was a `let`: https://cursive-ide.com/userguide/macros.html Another solution would be to disable highlighting of unresolved symbols entirely (Settings → Languages & Frameworks → Clojure → Highlight Unresolved Symbols). – superkonduktr May 27 '16 at 11:45
  • @superkonduktr oh! Thank you sir. – Tomas Zaoral May 27 '16 at 11:54
  • @juan.facorro you were right after all ;) – Tomas Zaoral May 27 '16 at 11:54
  • `f` need not be a function; it can be any form that the bindings close. – Thumbnail May 28 '16 at 15:55

1 Answers1

2

taken from @superkonduktr comment:

This is a known issue in Cursive that is currently being worked on. For now the only remedy seems to be in the beta version 1.3.0-eap1, where you can instruct Cursive to resolve bindings in your macro as if it was a let. Another solution would be to disable highlighting of unresolved symbols entirely (Settings → Languages & Frameworks → Clojure → Highlight Unresolved Symbols).

Tomas Zaoral
  • 499
  • 2
  • 5
  • 11