@jrheard I was off for the week end
@jrheard your blog post is wonderful!
It’s the first article featuring klipse that does graphics. Congrats
regarding infinite loops
the worker idea looks interesting but it makes the whole thing much more complicated and I’m not sure it worths it
do you know how figwheel prevents infinite loops
@bhauman how do you prevent infinite loops in figwheel repl?
@jrheard thx for the :optimizations tip - I have deployed a smaller version of the plugin
very cool!
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)
I’m thinking of another hack to prevent infinite loops
are u ready?
sure man
Function.prototype.call = function() { guard(); return window.cc.apply(this, arguments)}
Intercepting all js function calls
ha
by overrriding Function.prototype.call
interesting!
i wonder what that would do to performance, hm
can’t know unless we try, i guess!
what would guard() do?
guard = function(){
if (window.check) {
var now = new Date();
if ((now - start) > 1000) { window.check = false; throw("Infinite Loop")};}
}
gotcha
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
ok
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
there is this line
var direction = new cljs.core.Keyword(null,”north","north",(651323902));
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!
not sure
let’s check
and also the cljs.core.eq call
yeah!
very good point
there will always be a function call somewhere
so yeah, if we muck with the value of function.prototype.call before the snippet’s code is run, and put back its old value afterward, then this could be a possible solution i think!
yeah
I’m gonna try
it
nice 😄 gl!
BTW, there is a much cleaner solution
do tell!
to hook the js compiler
It’s here https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/compiler.cljc#L1009
oh nice
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!
Do you know how could I override this defmethod
https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/compiler.cljc#L919
it looks like if you just define a defmethod with the same signature after the first has been defined/imported, you should be good to go - http://app.klipse.tech/?cljs_in=(defmulti%20foo%20%3Abar)%0A%0A(defmethod%20foo%201%20%5Bthing%5D%20%22hello%22)%0A%0A(print%20(foo%20%7B%3Abar%201%7D))%0A%0A(defmethod%20foo%201%20%5Bthing%5D%20%22sup%22)%0A%0A(print%20(foo%20%7B%3Abar%201%7D))
(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!
np
enjoy your breakfast
@jrheard I somehow solved the infinite loop issue
by hooking the cljs compiler emits
function
!!!!!!
that’s awesome!
Could you please review my code here https://github.com/viebel/klipse/pull/131 ?
absolutely
Take a look at the playground-dbg
test page
I inserted a guard
on if
and continue
if
is generted by the emit :if
function
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 🙂
the thing I don’t like is that I had to copy/paste the whole code of the original emits
from the compiler
I didn’t find a way to “wrap” it - but I’m sure it’s feasible
take your time to review
I’m not planning to deploy it without thorough testing anyway
sounds great
May I ask you where do you work? How long are u into Clojure[script]
but first: what’s your name
hee
my name’s JR Heard, easy 🙂
but let’s move to private
sure
I saw this post about requiring and being able to use libraries in klipse: http://blog.klipse.tech/clojure/2016/03/29/klipse-clojure-libs.html Is there any way to require a library such as reagent to use in klipse?
what do u want to do exactly @ghufran ?
Suppose I would like to go through the reagent tutorial: https://reagent-project.github.io/ 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?
checking...
It doesn’t work for the moment @ghufran because reagent is not self-host cljs friendly