Fork me on GitHub
#clojure
<
2023-07-02
>
didibus03:07:27

Selmer users: In a custom tag, any way that I can resolve variables?

(html/add-tag!
 :ifendswith
 (fn [args _context-map content]
   (if (str/ends-with? (first args) (second args))
     (-> content :ifendswith :content)
     (-> content :else :content)))
 :else :endifendswith)
Template:
{% ifendswith {{game.push.img}} "cover_large.jpg" %}
   <img src="{{game.igdb.img}}" alt="Cover of {{game.title}}">
{% else %}
   <img src="{{game.push.img}}" alt="Cover of {{game.title}}">
{% endifendswith %}
The custome tag gets "{{game.push.img}}" as the arg, but I would want this resolved and get the value it refers too instead.

seancorfield06:07:02

IIRC, my solution to this was to have my tags support @dotted.var.name and if the first char of the arg was @, to split the rest and use it to get-in the context map...

didibus06:07:33

I see, I was worried I'd have to do some parsing of my own. But if there's no built in way, I guess I'll do it.

didibus07:07:16

Hum, that function seems to already exists in Selmer here: https://github.com/yogthos/Selmer/blob/51ce02b1f736486b7733a39c3805e9cc5f969e7d/src/selmer/filter_parser.clj#L75C1-L84C13 It takes a context map, and returns a fn that given a @dotted.var.name resolves the value from the context map.

seancorfield17:07:26

Ah, so maybe my suggested syntax "just works" without additional parsing now?

seancorfield17:07:49

I'll have a look when I'm back at work tomorrow...

seancorfield17:07:25

That's specifically for arguments to filters: foo|date:@format:

user=> (html/render "{{when|date:@format}}" {:when #inst "2023" :format "shortDate"})
"12/31/22"
user=> (html/render "{{when|date:@format}}" {:when #inst "2023" :format "longDate"})
"December 31, 2022"
user=>

didibus19:07:21

Oh interesting. Well it would be a nice feature if that syntax also worked standard for arguments to tags.

didibus19:07:07

But I ended up finding I can reuse a few functions from the parser and get it to fully resolve variables, but even apply filters, inner tags and all that. https://github.com/yogthos/Selmer/issues/303

seancorfield19:07:41

Yup. Saw that. I'm subscribed to all issues on Selmer (and have contributed).

nice 2
hifumi12308:07:06

Trying to use thread from core.async in a REPL, but it’s failing with this exception.

Syntax error macroexpanding go at (*cider-repl Clojure/scratch:localhost:62417(clj)*:29:16).
Attempting to call unbound fn: #'clojure.core.async.impl.ioc-macros/state-machine
Here’s the code I am trying to run.
(defn fake-fetch []
  (thread 
    (Thread/sleep 5000) 
    "Ready!"))

(let [c (fake-fetch)]
  (go (println (<! c))))
A quick Google search suggests this is related to AOT compilation, but I don’t have any AOT settings configured in my project.clj file. Any idea what’s going on?

p-himik09:07:12

fake-fetch must also be called from within a go block.

hifumi12310:07:22

ah, so contrary to examples I’ve seen online, thread has to be within a go block?

p-himik10:07:12

Which examples were those?

p-himik10:07:18

Hmm, I'm probably wrong with my first statement.

p-himik10:07:10

Yeah, definitely wrong. Also, I now realize that the error in the OP is about the go macro, so seems like it should error out on your side even with (go (println (<! (to-chan! [1])))).

hifumi12311:07:52

Regarding examples: I referenced clojuredoc and the thread section in https://www.braveclojure.com/core-async/

p-himik11:07:13

Yeah, those work for me just fine without go. Not sure why state-machine is unbound in your case.

p-himik11:07:14

There was someone else seeing a similar behavior but without core.async: https://clojurians.slack.com/archives/C03S1L9DN/p1687801725042649?thread_ts=1687459697.547859&amp;cid=C03S1L9DN Ended up being some dependency somehow messing things up.

p-himik11:07:52

Is there a chance you depend on some library that's not a jar but an uberjar?

hifumi12311:07:59

Don't think so. I'm using the latest version of core.async together with a bunch of pedestal packages

hifumi12311:07:17

I'll try to narrow down what's causing the issue

Alex Miller (Clojure team)14:07:31

you might want to roll back one version of core.async

4
💯 2
Alex Miller (Clojure team)14:07:20

that is, if you're on latest (1.6.673) try 1.5.648 and see if you're still seeing it

Alex Miller (Clojure team)14:07:35

the latest version dynamically loads the ioc-macros only during compilation (not needed at runtime), but you might be seeing some "interesting" load order here, hard to really diagnose without a lot more info

phill15:07:20

Hopefully the optimization will get rolled back or someone will fork core.async to make it optional.

phill16:07:57

"Which server-side languages are we using with ClojureScript?" was asked on the State of Clojure 2023 survey. I see the bars, but only half of the labels! Clojure, , Python, , Java, , Go... I am curious what's in 2nd, 4th, and 6th place. The results I refer to are linked to from here: https://clojure.org/news/2023/06/30/state-of-clojure-2023. On my mobile phone, most of the bar graphs are similarly label-sparse, but, back on the desktop, I tried resizing the page and shrinking the print but I still did not see the elided labels.

Alex Miller (Clojure team)16:07:29

This was discussed on the other thread and I dropped the full image there. I have a support case open with surveymonkey on this