Fork me on GitHub
#clojurescript
<
2018-08-03
>
vemv05:08:07

Can be used in a cljsbuid + figwheel project? I guess not given but also I'd be surprised a whole language feature simply isn't supported

Mario C.05:08:31

How do I print one of these guys? #<[object Object]>

lilactown15:08:30

js/console.log

šŸ‘ 4
Petrus Theron08:08:37

How do I unwrap optionally quoted EDN literals as user input in ClojureScript using read-string? E.g. (cljs.reader/read-string "'[1 2 3]") returns ' and not (quote [1 2 3]) as I would expect, but I'm interested in [1 2 3]. The user can also input "[1 2 3]" and I want the same output. Do I need to parse result and look for the presence of the quote symbol?

Petrus Theron08:08:39

I made a Cljs tool that translates boot-clj and Leiningen :dependencies to the newer deps.edn format: https://theronic.github.io/depsy/ (source on GitHub)

Petrus Theron08:08:05

@U04V70XH6 thx for boot-tools-deps šŸ™‚

paologf09:08:47

Hello, Iā€™m trying to use js* with a composed string as argument but I got Invalid js* form error. Iā€™m not sure if what Iā€™m doing is possible.. This works (js* "require('nano')(url:'')") but this one not (js* (str "require('nano')" "(url:'')")) . Of course I want to get the IP part from a configuration file, so as a variable. Thanks

thheller10:08:08

@paolo.galizzi whats the point of using js*? just do (let [nano (js/require "nano")] (nano #js {:url the-ip}))

thheller10:08:05

or better yet (ns ... (:require ["nano" :as nano])) (def the-thing (nano #js {:url ...}))

paologf10:08:55

Mmm good pointā€¦there isnā€™t a really reason why I was using js*.. Iā€™ll try as you suggest..thanks!

thheller10:08:28

js* is an implementation detail and should never be used directly

Schpaa10:08:36

Relating this to closurescript-beginners; is there a faq that covers all aspects of initializing a CLJS project, covering shadow, cursive, cider, lein, clj-tools, boot and god knows what else there is?

Schpaa10:08:31

Iā€™d like to contribute, if this is possible

Schpaa10:08:17

Or perhaps just a list of repositories where each entry is sanctioned by the respective author of above mentioned, I donā€™t know what to call it, complecting element in the CLJS universe? ;-)

Schpaa10:08:48

Personally Iā€™d like a map of the current landscape and how/where the pieces have an effect in the process of developing

dumrat10:08:42

@schpaencoder: I haven't seen anything like this. I've followed this which is a good intro to shadow-cljs: https://www.jacekschae.com/learn-reagent-free?coupon=SHADOW. purelyfunctional courses by Eric are awesome. But such resources are few and far between. Frankly, my experience is that clj/cljs is not newb friendly. cljs more so. The only exception I found so far is re-frame which has great documentation. There seems to be no one-place where all aspects of a non-trivial cljs (with clj) project are discussed. It feels like clj/cljs stuff is done by very smart people who don't have time to do handholding. clj/cljs entry skill level requirement is very very high.

dumrat10:08:22

Luminus tries, but is not perfect.

dumrat10:08:04

For me, luminus has been the only thing that let me actually do something in clojure without making me go completely insane

Schpaa12:08:47

@dumrat great course, I learned a new thing too, how you have to tell shadow what nrepl to use, and that I have to revisit atom, because yum those in-line error messages

Schpaa12:08:10

I would like to think that everything in Clojure-land is composable, however, only the toolmakers know how

Schpaa12:08:13

@dumrat first time Iā€™ve noticed the name luminous as well, thanks

Schpaa14:08:53

Suddenly I remembered why I ditched atom. Using 300% of my cpu while idle.

šŸ‘ 4
šŸ˜± 4
šŸ’Æ 4
nustiudinastea14:08:55

hi all, not sure if it's the right place to ask re-frame question but I will give it a go. Do you know if its possible to trigger multiple events in re-frame, from an event handler? The :dispatch keyword takes a vector with only one event as far as I know. Is this even an acceptable pattern?

dumrat14:08:30

@nustiudinastea: You can use dispatch-n. As far as I remember, it goes like this:

(reg-event-fx
 ::my-event
 [_ _]
 {:dispatch-n [[::event-1 args]
               [::event-2 args]]})

nustiudinastea14:08:12

ohh snap, didn't know about :dispatch-n. Will look it up, thanks so much!

nustiudinastea15:08:55

@dumrat dispatch-n works beautifully. Thanks for the tip

vemv15:08:34

> Can be used in a cljsbuid + figwheel project? Any luck with this one?

lilactown15:08:15

I tried this in shadow-cljs as well and didnā€™t have any luck šŸ˜ž

lilactown15:08:25

there seems to be very little info on tagged literals in general

šŸ˜¶ 4
thheller16:08:17

they are intentionelly not supported in shadow-cljs in .cljs source files. if you just want to use tagged literals in EDN thats fine and works via cljs.reader/register-tag-parser!

vemv16:08:24

> they are intentionelly not supported @thheller interesting! what's the reasoning behind?

thheller16:08:13

caching nightmares. its basically impossible to have reliable caching with those in place.

šŸ‘ 4
thheller16:08:19

and they are also quite annoying in to use in actual source code IMHO

thheller16:08:02

better to just require a ns and use (that-ns/foo ....) than rely on some compiler magic and use #that-ns/foo ...

thheller16:08:24

@mfikes made a good point about their use in the REPL though. so I will probably enable them there

vemv16:08:06

> better to just require a ns my use case was to create a #bigdec, which could resolve to the implementation du jour (transit, big.js) as they are always subject to change of course one could create a fn for that (Adapter pattern), but seems overly verbose for such a basic notion (big decimals)

thheller16:08:09

I think its unlikely that you'd actually be able to swap the entire implementation by just switching the reader literal

thheller16:08:40

since you'll still need some other ops to actually do something with them

vemv16:08:10

That's right. At least some verbosity is killed

vemv16:08:57

in general it seems important that values look like 'values' , not like function calls

Mario C.16:08:28

I noticed a function defined as so: (defn funny-looking ( . . . )) This is the first time I see a function defined without an argument list. I know its not a type-o because the app is working as intended. But what is the difference from a normal function defined as (defn serious-looking [] ( . . . )) ?

vemv16:08:14

That's a multi-arity function

šŸ‘ 4
thheller16:08:30

@mario.cordova.862 probably looking at a multi-arity fn? (defn foo ([] ...) ([a] ...))?

šŸ‘ 4
mfikes16:08:16

Yeah @vemv, I felt that the ability to have ratio value literals could be useful: https://github.com/mfikes/precise

āœŒļø 4
mikerod18:08:18

From what I see so far, I donā€™t know that you can effectively use resolve calls during macroexpansion-time when using macros in CLJS - I may be wrong, so seeing if anyone can shed some light on the situation. Consider this: foo/mac.clj

(ns foo.mac)
(def a "hello")
(defmacro foo [] [(resolve 'a)])
(ns foo.bar (:require-macros [foo.mac :as f]))
(enable-console-print!)
(println  (f/foo))
I get something like [nil].

mikerod18:08:59

Trying to track through the CLJS compiler and analyzer to see what is going on during macroexpansion, and I belive it is due to *ns* being boudn to cljs.user during resolve being called at macroexpansion time

mikerod18:08:10

What isnā€™t clear to me, is if you can even effect that behavior in the analyzer

mikerod18:08:19

In particular, when I get about as deep as cljs.compiler/emit-source, there is a direct binding to ana/*cljs-ns* 'cljs.user This is then used in cljs.analyzer/macroexpand-1* via binding [*ns* (create-ns *cljs-ns*)] resulting in the *ns* being bound to cljs.user when the macro fn is called.

mikerod18:08:49

since cljs.compiler/emit-source doesnā€™t appear to yield to any passed down ā€œcompile envā€ to bind ana/*cljs-ns* to, I think there isnā€™t a effectively way to instead bind ana/*cljs-ns* to the CLJ namespace that the macro was written in. This may be a known limitation. Itā€™d be good to hear more about it though. I couldnā€™t find anything related on this topic doing searches.

dnolen19:08:05

@mikerod *ns* is always bound to the current namespace, not where the macro was written

dnolen19:08:32

so while there might be an issue thatā€™s also how *cljs-ns* should work

dnolen19:08:14

I donā€™t know that thereā€™s a good way to do what youā€™re talking about even in Clojure

mikerod19:08:03

@dnolen ah yeah, I guess I tried to get too fancy in my example, but consider trying to resolve something from clojure.core - that also doesnā€™t work in CLJS

mikerod19:08:04

and in Clojure it would, but I think I can accept the general idea though that doing macroexpansion time resolve (or similar) can be risky

mikerod19:08:47

I think it should just be fully-qualifying the symbols and maybe thatā€™d be it. so (resolve 'foo.mac/a) instead

dnolen19:08:10

you can use resolve, look at the cljs.spec.alpha macros, they need to do this

mikerod20:08:42

@dnolen You are referring to using cljs.analyzer.api/resolve like in cljs.spec.alpha/exercise-fn ?

mfikes20:08:42

The Graal.JS REPL has landed on ClojureScript master.

{:deps {org.clojure/clojurescript {:git/url ""
                                   :sha "04e6bd9073daa905543d7decab95a2252c2e53e2"}}}
then
$ clj -m cljs.main -re graaljs -r
Cloning: 
Checking out:  at 04e6bd9073daa905543d7decab95a2252c2e53e2
cljs.user=> (.eval js/Polyglot "R" "sum(1:100)")
5050
cljs.user=> (.eval js/Polyglot "ruby" "(1..100).reduce(:+)")
5050
You need to have Graal Java in path for this
$ java -version
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
GraalVM 1.0.0-rc4 (build 25.71-b01-internal-jvmci-0.45, mixed mode)

šŸ‘ 20
benzap01:08:23

That polyglot stuff is giving me chills, so much potential!