Fork me on GitHub
#cursive
<
2019-03-31
>
mbjarland20:03:29

Is there a way to get cursive to grok custom macros or is this just a known limitation?

potetm20:03:18

see: “Customising symbol resolution”

potetm20:03:38

But I’m going to also take a second and encourage you to consider the worth of that macro as well 🙂

potetm20:03:25

If I understand correctly, the following is equivalent:

(str/join "\n"
          (for [w ["alice" "writing" "desk"]
                fmt ["%20s" "%-20s"]]
            (format fmt w)))

potetm20:03:12

As a reader, I would honestly prefer to just see that^ in the code. Offhand, it seems like a pretty unique case.

potetm20:03:09

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"])

mbjarland20:03:56

@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.

potetm20:03:02

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))

mbjarland20:03:31

the example use above was contrived and does not reflect the complexity of the actual for comprehensions

potetm20:03:43

@mbjarland Yeah. Simplistic examples lead to simpleton reasoning 🙂

potetm20:03:39

Anyways, back to your original question: Feel free to holler if you have trouble getting resolution working.

mbjarland20:03:54

A more realistic example

potetm20:03:20

Yeah okay — that makes a lot more sense 🙂

potetm20:03:54

Definitely preferable to use a macro like that^ instead of creating your own mini formatting lang.

mbjarland20:03:27

so in a case like the above you think it would be warranted to go the macro way?

potetm20:03:21

definitely

mbjarland20:03:17

ok - sanity restored, thanks for the feedback…will take a look at the cursive macro support