This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-03-31
Channels
- # announcements (16)
- # beginners (52)
- # calva (44)
- # cider (82)
- # clojure (21)
- # clojure-greece (1)
- # clojure-losangeles (1)
- # clojure-spec (8)
- # clojure-uk (3)
- # clojurescript (55)
- # community-development (26)
- # cursive (18)
- # datomic (7)
- # editors (6)
- # events (1)
- # fulcro (19)
- # kaocha (1)
- # klipse (1)
- # off-topic (13)
- # re-frame (1)
- # ring-swagger (2)
- # spacemacs (2)
- # vim (15)
Is there a way to get cursive to grok custom macros or is this just a known limitation?
@mbjarland The answer to your question is, “yes”: https://cursive-ide.com/userguide/macros.html
But I’m going to also take a second and encourage you to consider the worth of that macro as well 🙂
If I understand correctly, the following is equivalent:
(str/join "\n"
(for [w ["alice" "writing" "desk"]
fmt ["%20s" "%-20s"]]
(format fmt w)))
As a reader, I would honestly prefer to just see that^ in the code. Offhand, it seems like a pretty unique case.
But if it’s a pattern that keeps arising, I would suggest making a regular fn:
(defn format-each-and-join [inputs formats]
(str/join "\n"
(for [w inputs
fmt formats]
(format fmt w))))
(format-each-and-join ["alice" "writing" "desk"]
["%20s" "%-20s"])
@potetm thank you, point taken, an yes, I would much prefer a function as well. This is however a recurring pattern in the code I’m in and the for comprehensions are somewhat complex…need to mull on whether I can get away with a function.
However, if you do in fact require permutations of inputs and complex formatting, then this seems reasonable. E.g.:
(sfor [a ["alice" "writing" "desk"]
b ["bob" "flying" "plane"]]
(format "%20s %20s" a b)
(format "%-20s" b))
the example use above was contrived and does not reflect the complexity of the actual for comprehensions
@mbjarland Yeah. Simplistic examples lead to simpleton reasoning 🙂
Anyways, back to your original question: Feel free to holler if you have trouble getting resolution working.