Fork me on GitHub
#clojurescript
<
2019-08-24
>
Silenced Ego04:08:38

Hi. Is there any reason to use loop form in CLJS? Or is it just a waste of time, because recursion will do the same thing?

dpsutton04:08:29

Recursion has an implicit limit based on the stack. Loop/recur do not have this limitation

Silenced Ego04:08:43

even for javascript

dpsutton04:08:02

About which? Loop/recur are loops which have no stack issues and recursion is function invocation on both jvm and js vms. You can recur to a function to get recursion without adding onto the stack though

dpsutton04:08:42

(I wasn’t sure which condition for JavaScript you were mentioning)

dpsutton04:08:43

It’d be interesting if one of the vms got tail recursion while the other didn’t to see if the languages would forego tail call optimization on the platform where it was available.

Silenced Ego05:08:37

@dpsutton pretty sure ES6 has tail call optimization

dpsutton05:08:09

Didn’t know that. But looks like it’s just the spec. >> Update 2018-05-09: Even though tail call optimization is part of the language specification, it isn’t supported by many engines and that may never change. The ideas are still interesting, however and explained in this blog post.

Silenced Ego05:08:28

ah, yea that makes sense. thanks

dpsutton05:08:36

Not sure if that’s authoritative though and I didn’t know es6 included it so thanks for letting me know!

hamid tsh07:08:08

hi, how can i add autoreload by speficic time in figwheel project?

padraic09:08:17

Hi, I'm just wondering about how I would go about instantiating a library wrapper around a series of api calls. I am developing a library in which I have an initialisation step which takes some configuration from the user and puts it in an atom, and sets an initialized? flag as true. There are then multiple functions in the library with which I want to run a check on the initialized? flag and throw an error if false. I have created a macro for this which works but is somewhat unsatisfactory:

(defmacro defn2 [name args body]
  `(def ~name (fn ~args (system-check ~body))))
The reason why I find it unsatisfactory is that much of the codebase of the library is interdependent, so I want to prevent the user calling f(x), g(x), h(x) and so I would instantiate all those functions with defn2. However, I have other functions which may call h(g(f(x))) and so I would call system-check three times rather than once. Even having to call system-check once per function seems a bit unneccessary. Is there a pattern to solve this?

jumpnbrownweasel14:08:58

Just a thought: Create an fn to deref the atom and check for nil there (throw an error if nil), and call this fn rather than derefing the atom directly when you need it.

jumpnbrownweasel14:08:01

You wouldn't need an initialized? flag.

nmkip15:08:54

Hi, I'm watching this course to start learning about clojurescript and I'm getting some weird behaviour. Not sure what's happening. Can someone help me out? I will try to explain what's happening in a thread 🙂

nmkip15:08:27

This is the app component. When I uncomment the header stuff a clojurescript error appears saying Invalid :refer, var giggin.components.header/header does not exist The other three components gigs, orders and footer have no problem. What's weirder is that sometimes the header works, until I make a change inside the header.cljs file and it starts crashing again with the same error. The folder structure is: src | giggin | components footer.cljs gigs.cljs header.cljs orders.cljs core.cljs state.cljs

nmkip15:08:44

I can send screenshots or share screen if needed 😄

David Pham15:08:00

Did you check if the namespace is written correctly in the griffin.components.header and if the header var exists in that file?

nmkip15:08:10

and this is the core.cljs

nmkip15:08:49

and this is the error

thheller16:08:09

try restarting the shadow-cljs process. seems like an update got lost and is out of sync with your files

nmkip02:08:52

yes, restarting did the work! Thanks 🙂