Fork me on GitHub
#clojurescript
<
2017-03-02
>
Pishty00:03:36

hello guys, am getting this assertion error when in try to compile my cljs (Assert failed: Circular dependency detected, re-frame.interop -> reagent.ratom -> reagent.impl.util -> cljsjs.react -> cljsjs.react) , i tried to exclude reagent/ratom from the reframe dependency but i still got the same error

tech_hutch01:03:02

How can you check if something is a ClojureScript object or "plain" JavaScript?

anmonteiro01:03:01

if by “ClojureScript object” you mean a map

tech_hutch01:03:04

But that will return false for vectors, won't it?

tech_hutch01:03:14

I mean maps, vectors, sets, etc.

tech_hutch01:03:27

Basically, anything ClojureScript defines.

tech_hutch01:03:24

I guess I could check each individually--`string?` map? vector? etc.

tech_hutch01:03:37

Actually I guess strings are plain JS strings

anmonteiro01:03:52

hrm, I think cljs.core/coll? will tell you if you have a ClojureScript data structure

tech_hutch01:03:10

Thanks, that seems to be what I need!

tech_hutch02:03:48

In JavaScript, evals will have access to surrounding variables in the scope that eval() was called in. Is it possible to do the same in ClojureScript? It doesn't seem to see them.

tech_hutch03:03:28

Come to think of it, I suppose I could pass any JavaScript function to eval it with, so I could have one that makes the variables in the enclosing scope.

darwin08:03:43

and I don’t think you are correct with the statement "evals will have access to surrounding variables in the scope that eval() was called in”, javascript eval has only access to global scope I believe

thheller09:03:52

@darwin eval has access to local scope in the browser (and node)

thheller09:03:00

(function() { var foo = 1; eval("console.log(foo)"); })(); logs 1

thheller09:03:23

@tech_hutch CLJS does many things to ensure sane scope semantics, that means it will sometimes introduce new scopes and re-bind variables (especially in loops). generally you should probably try to avoid eval

tech_hutch11:03:53

thheller: "CLJS does many things to ensure sane scope semantics" so variables introduced with, e.g., let cannot be accessed from an eval string? And I normally wouldn't use eval (in this language or others), but I have a use.

thheller11:03:32

just be aware that things probably won't work in :advanced builds

tech_hutch11:03:11

I'm using Node, so I'm not using :advanced.

thheller11:03:55

as for variable names I recommend looking at the generated JS

thheller09:03:49

also everything is namespaced so (def x 1) is not x but your.ns.x

thheller09:03:26

but with :advanced that will be something else entirely, so stay away from eval as best you can 😉

octahedrion09:03:21

anyone know of a lib that simply provides all math functions as cljc ? e.g. #?(:clj (Math/round x) :cljs (js/Math.round x)) etc

octahedrion09:03:34

-- oh hey it's ok...i didn't know you can do Math/math-fn in cljs too

thheller09:03:45

@octo221 beware though, some fns on Math behave differently IIRC

octahedrion09:03:45

hmm yes in JS there are some different signatures

octahedrion09:03:43

so maybe it would be better to hand-code each variant in cljc

kommen12:03:29

Should the Javascript Module support (https://clojurescript.org/guides/javascript-modules) work for the browser as a target or is it for :target :nodejs only right now?

mruzekw13:03:02

As far as I’m aware the target doesn’t matter

dnolen14:03:20

yes target doesn’t matter

darwin14:03:39

@thheller yep, you are right with eval scope

dnolen14:03:38

@kommen that said, really the JS module stuff is about the browser - under Node.js you don’t need advanced compilation

tech_hutch15:03:40

(This is for a Discord bot, by the way.)

thheller15:03:28

seems dangerous to use eval for anything that might see user input but as far as eval is concerned it should work

tech_hutch15:03:05

The only user input here is mine.

tech_hutch15:03:27

Sorry, I should have said this is for a Discord selfbot.

thheller15:03:48

this is on node you said?

thheller15:03:10

you might get further with using the vm package instead of plain eval

briprowe15:03:54

Is there metadata you can apply to a function definition that prevents it from being dead code eliminated?

tech_hutch15:03:42

Yes, this is on Node

thheller15:03:29

node has vm.runInContext or vm.runInThisContext that gives you way more contorl

tech_hutch15:03:55

So vm is a built-in Node module? I haven't used it.

thheller15:03:38

lets you sandbox things easily as well

kommen15:03:29

@dnolen ok thank you. I just thought I read something that it works for nodejs target only for now, but couldn’t find and and also couldn’t make it work with boot

tech_hutch15:03:46

I'm not sure vm is really necessary. I don't really need to constrain the eval.

tech_hutch15:03:43

Actually, I guess I could set the variables I need as the sandbox.

tech_hutch15:03:18

From my understanding, that would make them globals in the eval, right?

jaydeesimon15:03:47

Hello all. Question about setting up a pipeline with core.async. I have code that takes on the following shape:

jaydeesimon15:03:08

Is there a more idiomatic way to write this?

hlolli15:03:26

don't know, but this wont work outside a go/go-loop?

jaydeesimon15:03:36

oh. it seems to work. I thought only the <! and >! needed to be wrapped in a go block

hlolli15:03:22

in clojurescript nothing in core.async works outside a go macro. (please correct me if Im wrong)

jaydeesimon15:03:05

that seemed to work just fine without any go block

jaydeesimon15:03:09

just to confirm, that’s ClojureScript and not Clojure

dnolen16:03:31

take! is async you don’t need go block

dnolen16:03:48

go block is for things which need to appear as if they block <! >! etc.

jaydeesimon16:03:15

thanks for clarifying

foobar16:03:07

Is there an om next channel?

danielneal16:03:42

It all happens in #om

foobar16:03:44

nm found it

danielneal16:03:54

The #om-next channel is much quieter

foobar16:03:08

Ok, thanks

tech_hutch17:03:49

I was just trying the keyword-map macro from https://github.com/plumatic/plumbing/blob/master/src/plumbing/map.cljx#L104 in the repl at http://clojurescript.net, but it always seems to return an empty map. Does anyone know why?

tech_hutch17:03:12

(I'm just copy-pasting it into the repl.)

jaymartin17:03:11

How can we build better "first contact" experiences for new programmers and Clojurians? Our open source learning group is hosting the free online webinar Essential Klipse this Saturday at 7 pm UTC to address that question. Everyone is welcome! http://discuss.thevalueoflearning.org/t/webinar-discussion-2-essential-klipse/39?u=jay

jr17:03:35

@tech_hutch I don't think you can use #js but you can wrap the map with JSValue to get a js literal

jr17:03:58

(defmacro keyword-map [& syms]
  (JSValue. (zipmap (map #(keyword (name %)) syms) syms)))

tech_hutch17:03:18

Okay. So JSValue is a constructor, I'm assuming?

jr17:03:05

you may have to import it from cljs.tagged_literals

tech_hutch17:03:33

(I don't think I'll use the macro, since it's only one time, but thanks anyway)

shaun-mahood18:03:25

Do I have to do something different to include goog.labs namespaces compared to other goog namespaces?

jr19:03:56

no just require the namespace you need

jr19:03:51

those provide statements become the namespace symbol

shaun-mahood19:03:40

@jr: I must be doing something wrong then - :require [goog.labs.userAgent.util] should work, right?

jr19:03:27

yeah that's correct

shaun-mahood19:03:52

Ok thanks - must be something else going on then

jr19:03:24

cljs.user=> (require '[goog.labs.userAgent.util :as util])
nil
cljs.user=> (util/getNativeUserAgentString_)
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"

jr19:03:47

might depend on which closure compiler version you are using

anmonteiro19:03:12

@shaun-mahood FWIW, in Lumo:

Lumo 1.1.0
ClojureScript 1.9.456
 Docs: (doc function-name-here)
 Exit: Control+D or :cljs/quit or exit

cljs.user=> (require '[goog.labs.userAgent.util :as util])
nil
cljs.user=> (util/getUserAgent)
""

shaun-mahood19:03:19

I'm trying to get openlayers to compile with Clojure, day 3 of learning what I don't know and figuring things out - error driven development 🙂

shaun-mahood19:03:06

They have their own google compiler utility, so my hunch so far is that they're doing something "interesting" that I haven't figured out yet.

Oliver George21:03:47

@shaun-mahood you might find the cljsjs package for openlayers enlightening https://github.com/cljsjs/packages/tree/master/openlayers

shaun-mahood21:03:11

@olivergeorge: I'm using it without success so far 🙂

Oliver George21:03:13

Note the deps.cljs uses :libs not :foreign-libs

Oliver George21:03:41

It's been a while since we used that. Not sure I can give comment on current status.

Oliver George21:03:24

There's half a chance there's code in this old repo which might give you helpful clues

shaun-mahood21:03:41

Oh that might totally help - a lot of the things I've been looking at are areas I haven't had to use much (I spend most of my CLJS time without needing to do any interop), so having another reference is awesome. Thanks!

Oliver George21:03:43

@shaun-mahood Good luck! This stuff is a bit interop heavy.