Fork me on GitHub

(letfn [(create [k depth]
          (if (zero? depth)
            (k {:id depth})
              (fn [c]
                (k {:id depth :child c}))
              (dec depth))))]
  (trampoline create identity 5000)
in clojure this works, in fact I can increase the depth to 40,000 or so, but in clojurescript I get a "Maximum call stack size exceeded."


shouldn't trampoline and using CPS prevent this from growing the stack?


for clarity, an example of using a depth of 5:

{:id 5, :child {:id 4, :child {:id 3, :child {:id 2, :child {:id 1, :child {:id 0}}}}}}


in fact, the non-trampoline version can actually grow farther lol


(letfn [(create [depth]
          (if (zero? depth)
            {:id 0}
            {:id depth
             :child (create (dec depth))}))]
  (create 5000)
works on my machine. the trampoline version above w/ 5000 does not


the answer is that I had an error in my trampolined version. the inner fn that calls k needs to return a thunk

(letfn [(create [k depth]
          (if (zero? depth)
            (k {:id depth})
              (fn [c]
                (fn [] (k {:id depth :child c})))
              (dec depth))))]
  (dissoc (trampoline create identity 50000) :child))
;; => {:id 50000}


hmm but why is that necessary. k should return a thunk

Pepijn de Vos15:12:54

What do people generally use for templates? Just simple text substitution stuff, not the sexpy html stuff

Léo J16:12:10

I’ve only use (str so far 😆


or is this not what you were looking for

Pepijn de Vos15:12:58

Maybe? Kinda? Seems there is also Cljstache. I tend to like Mustache implementations because of their simplicity. Seems Selmer is more advanced with filters and stuff. My needs are mostly glorified printf

Pepijn de Vos15:12:52

I guess Selmer can also be used as glorified printf though, we'll see


@pepijndevos FWIW Selmer is also available in #babashka , but so is clojure.pprint/cl-format and format cl-format probably qualifies as a glorified version of format?

Richard Bowen22:12:34

Hey, how does one get the final rendered html for a page using reagent?

Pavel Klavík22:12:38

@rbowen It is possible to use reagent.dom.server/render-to-string

Richard Bowen22:12:15

Thanks @pavel.klavik, I'll give that a go.

Pavel Klavík22:12:57

I am trying to find a bizzare bug which only occurs in ClojureScript code compiled in advanced mode and only in Safari. After a fun evening of random debugging, I have found that it occurs in this function: The input a should be nil, but when passed into Lka, when printed there, it shows 0. When I copy this function on the side and add a log statement for the value of a, the issue disappears:

Pavel Klavík22:12:11

In Clojure, all three functions look like this:

Pavel Klavík22:12:36

All the inputs should be immutable Clojurescript values.


Other browsers - do they have nil there as expected? Have you tried creating a minimal reproducible example?

Pavel Klavík23:12:24

Haven’t checked but almost surely yes, the app works fine there and breaks after a few actions in Safari (both mac and ios)

Pavel Klavík23:12:23

Minimal reproducible example will be tricky.


The process of coming up with such an example can by itself shed quite a lot of light on the situation.

Pavel Klavík23:12:09

Surely. I will probably just hack the solution right now and will probably dig deeper if it resurfaces. I need to get working development on mac anyway if we want to support Safari better.


Just make sure to leave plenty of comments in whatever hack you'll come up with. :)

Pavel Klavík23:12:45

Ya :) browsers are overall a huge minefield everywhere, I have already discovered multiple Chromium specific bugs.