Fork me on GitHub
#clojurescript
<
2016-07-04
>
hueyp00:07:53

is there an equiv to with-local-vars in cljs? or should I just switch to an atom?

mfikes02:07:53

@hueyp: One thing I’ve wondered about is if you need some imperative code for speed reasons in a tight loop, whether bashing on 1-element array values buys you anything over atoms. Such code ends up being pretty difficult to read, though.

lockdown02:07:11

Is the use of the closure library encourage over other more mainstream libraries that do the same thing?

mfikes02:07:52

@hueyp: Looks like David wrote some macros based on such arrays to simulate mutable locals: https://github.com/swannodette/chambered/blob/master/src/chambered/macros.clj

hueyp02:07:09

@mfikes: thanks, I’ll take a look … in my case it isn’t for speed, I just am swap!’ing an atom, but the inner function returns the next value + some extra data and but I want that extra data .. in clj I was using with-local-vars

hueyp02:07:39

could just js-obj and set! on it mebe? 😜

hueyp02:07:46

I haven’t had time to poke yet

mfikes02:07:57

@hueyp: Yeah, for that I’d just let ps be an atom, and replace the var-set with reset!

hueyp02:07:19

:thumbsup: thanks 🙂

lwhorton03:07:57

this is super basic — but what’s the proper way to get a map’s key and val without knowing the :key?

lwhorton03:07:10

(first (vals m)) just cannot be idiomatic

mfikes03:07:02

@lwhorton: Does the map have exactly one key-val pair in it?

mfikes04:07:08

Either that, or perhaps (val (first m))

lwhorton04:07:31

hmm, so there’s simply no (key m) or (val m), unless its a MapEntrie (whatever that is)?

lwhorton04:07:54

bummer .. thanks for the info

shaunlebron04:07:09

@lwhorton: not sure what the use-case is for a map with one key-value pair

shaunlebron04:07:34

you probably want something like {:key “foo", :val “bar”} instead of {“foo” “bar”}

shaunlebron04:07:05

it’s only idiomatic to use {“foo” “bar”} if you’re intending to use ”foo” to lookup ”bar”

bensu06:07:44

@lockdown: always reach for google closure first if possible. lots of good stuff there, and it will be always be easier to integrate in your cljs project

novakboskov07:07:14

@vandr0iy: I'm on Emacs but the point is to start two REPLs, one clojure REPL and run (start) in user namespace to start all the mount states (it includes web server and few other stuff) and then run lein figwheel to start clojurescript REPL. Dmitri Sotnikov, the author of Luminus use Cursive so try ask him on GitHub if you have more troubles.

vandr0iy08:07:50

@novakboskov: I'll try this kind of workflow, thanks! But my point was: I'm completely unable to start a repl that my .cljs file would be able to see. Like: -start emacs -open .cljs file -C-c M-j and then: -trying to call some method defined in the .cljs file I opened before -> nope -(in-ns my.cljs.ns) -> nope -recompile .cljs file I'm talking about with C-c C-k -> nope, "no clojurescript repl opened" & similia errors galore. I opened the issue, appearently solved since february, on github, no replies yet...

nha16:07:34

Has anyone published an npm module written in clojurescript that runs in both node and the browser ?

misha19:07:49

good day, gentlemen I am having a trouble with lein cljsbuild once db:

:cljsbuild {:builds {:db {:source-paths ["src/ddd/ios/db"]
                                      :compiler {:output-to "target/db/db.js"
                                                        ;:main     "ddd.ios.db.db.main"
                                                        :output-dir    "target/db"
                                                        :optimizations :advanced}}
(ns ddd.ios.db.db)
(defn ^:export main [])
If I uncomment :main "ddd.ios.db.db.main", I get:
Compiling "target/db/db.js" failed.
java.lang.IllegalArgumentException: No implementation of method: :-find-sources of protocol: #'cljs.closure/Compilable found for class: nil
Otherwise – it compiles. :optimizations :none works as well. Am I missing something obvious?

bensu21:07:30

@misha: is the file under src/ddd/ios/db/db/main.cljs

bensu21:07:45

or is the file src/ddd/ios/db/db.cljs?

misha21:07:26

@bensu src/ddd/ios/db/db.cljs

bensu21:07:27

:main needs the namespace, not the function

bensu21:07:39

so in your case it would be :main ddd.ios.db.db

misha22:07:42

@bensu, oh, sweet, thank you

misha22:07:29

re-natal template is messing with me :main "env.ios.main". assumed main is a function, like in java convention