Fork me on GitHub
#clojurescript
<
2021-12-21
>
lilactown07:12:34

(letfn [(create [k depth]
          (if (zero? depth)
            (k {:id depth})
            #(create
              (fn [c]
                (k {:id depth :child c}))
              (dec depth))))]
  (trampoline create identity 5000)
  nil)
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."

lilactown07:12:55

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

lilactown07:12:20

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

lilactown08:12:55

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

lilactown08:12:19

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

lilactown08:12:04

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})
            #(create
              (fn [c]
                (fn [] (k {:id depth :child c})))
              (dec depth))))]
  (dissoc (trampoline create identity 50000) :child))
;; => {:id 50000}

lilactown08:12:21

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 😆

Derek15:12:39

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

borkdude16:12:07

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

1
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: https://orgpad.com/img/DpuNESB2FJbLm0P-eeYifP/download?token=AU25m6asVA56Cw6cceBK5Y 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: https://orgpad.com/img/CwvFl3QIpCHL6IvsTpa3FJ/download?token=CsmOIOJNFKQ5t1VW8k7fFX

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.

p-himik22:12:47

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.

p-himik23:12:17

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.

p-himik23:12:50

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.