Fork me on GitHub
Yehonathan Sharvit15:10:52

@jrheard I was off for the week end

Yehonathan Sharvit15:10:22

@jrheard your blog post is wonderful!

Yehonathan Sharvit15:10:38

It’s the first article featuring klipse that does graphics. Congrats

Yehonathan Sharvit15:10:18

regarding infinite loops

Yehonathan Sharvit15:10:46

the worker idea looks interesting but it makes the whole thing much more complicated and I’m not sure it worths it

Yehonathan Sharvit15:10:01

do you know how figwheel prevents infinite loops

Yehonathan Sharvit15:10:18

@bhauman how do you prevent infinite loops in figwheel repl?

Yehonathan Sharvit16:10:18

@jrheard thx for the :optimizations tip - I have deployed a smaller version of the plugin


glad you like the post! looking forward to publishing it 🙂


i agree with you that the worker idea is too complex for its own good


also glad that :simple worked


from what i can tell from using figwheel, i think that after 8 seconds, it returns control of the REPL to the user, but the function that timed out is still running


(when doing performance investigations / collecting simple benchmarks in intellij+cursive, i often send the figwheel repl functions that take 30 seconds or so to complete; after 8 seconds, the repl will say “evaluation timed out!” and allow me to run more commands, but 20 seconds later the results of my benchmarking function will appear in the repl’s output)

Yehonathan Sharvit16:10:11

I’m thinking of another hack to prevent infinite loops

Yehonathan Sharvit16:10:45 = function() { guard(); return, arguments)}

Yehonathan Sharvit16:10:52

Intercepting all js function calls

Yehonathan Sharvit16:10:06

by overrriding




i wonder what that would do to performance, hm


can’t know unless we try, i guess!


what would guard() do?

Yehonathan Sharvit16:10:56

guard = function(){
if (window.check) {
  var now = new Date();
  if ((now - start) > 1000) { window.check = false; throw("Infinite Loop")};}

Yehonathan Sharvit16:10:17

do u think it can work?


not sure! gonna poke around at something for a second, i wanna see if it would work on the specific infinite-loop i had, gonna see the generated js


so the main infinite-loop in my post’s code could be triggered if the user called drunkards-walk and asked for more empty cells to be carved out than actually exist on the grid, so eg (drunkards-walk 5 5 1000); i added a check to the start of the function to defend against this (sidenote: that check basically solves the problem for my purposes, so i’m less worried about the infinite loop issue than i was when i first asked about it) and so anyway i just looked at the generated js, and it looks basicaly like this:

var foo = 2, bar = 3, baz = 4;
while(true) {
  if(done(foo, bar, baz)) {
    return baz;
  } else {
  foo = foo+1;
  bar = bar+1;
  baz = baz+1;


and so it’s not a situation where it’s a recursive function that keeps calling itself, it’s just this single function call that has a while(true) loop that will never be broken out of


i’m not sure if it’s possible to solve this particular case


unless the loop/recur solution in cljs-soup you linked a few days ago would solve this

Yehonathan Sharvit16:10:19

there is this line

var direction = new cljs.core.Keyword(null,”north","north",(651323902));

Yehonathan Sharvit16:10:31

Maybe there is a way in js to hook new


ah, good point!


i don’t think we have to worry about new, i think that ends up being a function call that’s just run with this bound to a specific value


so there’s your function call!


and also the cljs.core.eq call

Yehonathan Sharvit16:10:04

there will always be a function call somewhere


so yeah, if we muck with the value of before the snippet’s code is run, and put back its old value afterward, then this could be a possible solution i think!


nice 😄 gl!

Yehonathan Sharvit16:10:02

BTW, there is a much cleaner solution

Yehonathan Sharvit16:10:16

to hook the js compiler


that sounds better, i was worried about effects that this could have on non-klipse code ont he page (analytics, ads, whatever)


so if it only affects the js generated by the snippet’s input cljs code, then that sounds good to me!


(there are probably edge cases / situations where this is unreliable, but at least it looks like it can be done)


ok, gonna have some breakfast and putter around and not check slack for a while 🙂 good luck!

Yehonathan Sharvit16:10:52

enjoy your breakfast

Yehonathan Sharvit20:10:01

@jrheard I somehow solved the infinite loop issue

Yehonathan Sharvit20:10:15

by hooking the cljs compiler emits function


that’s awesome!



Yehonathan Sharvit20:10:28

Take a look at the playground-dbg test page

Yehonathan Sharvit20:10:46

I inserted a guard on if and continue

Yehonathan Sharvit20:10:02

if is generted by the emit :if function

Yehonathan Sharvit20:10:17

continue is generated by emit :recur


nice - might take me an hour or two to process this and play around with it, hope that’s ok 🙂

Yehonathan Sharvit20:10:51

the thing I don’t like is that I had to copy/paste the whole code of the original emits from the compiler

Yehonathan Sharvit20:10:25

I didn’t find a way to “wrap” it - but I’m sure it’s feasible

Yehonathan Sharvit20:10:31

take your time to review

Yehonathan Sharvit20:10:52

I’m not planning to deploy it without thorough testing anyway


sounds great

Yehonathan Sharvit20:10:12

May I ask you where do you work? How long are u into Clojure[script]

Yehonathan Sharvit20:10:23

but first: what’s your name


my name’s JR Heard, easy 🙂

Yehonathan Sharvit20:10:32

but let’s move to private


I saw this post about requiring and being able to use libraries in klipse: Is there any way to require a library such as reagent to use in klipse?

Yehonathan Sharvit22:10:18

what do u want to do exactly @ghufran ?


Suppose I would like to go through the reagent tutorial: If it was already set up using klipse, I could evaluate the code and change it right on the page. But if they haven’t done that, I would like to be able to copy and paste the code from the page into klipse and evaluate it there. However, I would need to be able to require the reagent library, is there any way to do this?

Yehonathan Sharvit22:10:05

It doesn’t work for the moment @ghufran because reagent is not self-host cljs friendly