Fork me on GitHub
#clojurescript
<
2019-04-19
>
Lu02:04:38

(type 'h1) => cljs.core/Symbol (type (first '('h1))) => cljs.core/List Do you guys know why the second example doesn't return Symbol?

Mno02:04:08

probably because the quoted list isn’t evaluated

Mno02:04:03

Ah yes or that.. What Nate said.

Lu02:04:39

Yeah but what about this? (some #(= 'a %) '(3 'a 4)) => nil

Lu02:04:43

It works if the coll is a vector (some #(= 'a %) [3 'a 4]) => true

Lu02:04:51

Not sure whether it might be a bug

dpsutton02:04:17

Use list rather than quote and try not quoting the a if you are quoting the list

dpsutton02:04:15

Remember what ‘a expands to and what quoting a form does (when you’re quoting a s expression and one of its members is itself a quoted form

Alex Miller (Clojure team)03:04:20

’(3 ‘a 4) will be (3 (quote a) 4)

john12:04:44

(quote (3 (quote a) 4)) rather, right? That's why calling first returns the list.

jaihindhreddy14:04:53

'(3 'a 4) ---read--> (quote (3 (quote a) 4)) ---eval---> (3 (quote a) 4) 🙂

Alex Miller (Clojure team)14:04:28

' expands to (quote ...), which then is evaluated to return just the thing inside which has been read, but not evaluated

jaihindhreddy14:04:40

' expands to (quote ...) at read time if I'm right. Because eval understands only datastructures

john14:04:31

Right right

👍 4
john14:04:35

first would rather return quote if triggered at read time.

Alex Miller (Clojure team)14:04:38

@U883WCP5Z yes, what you have above is just right

👍 4
Alex Miller (Clojure team)14:04:46

a quick way to check the read form is often to syntax quote in front:

`'(3 'a 4)  ;; (quote (3 (quote user/a) 4))

parrot 4
Alex Miller (Clojure team)14:04:32

works in a surprisingly large set of cases as a quick check

👏 4
Alex Miller (Clojure team)14:04:56

or just quote in front too I guess

Alex Miller (Clojure team)14:04:33

for exact same reasons as above

jaihindhreddy14:04:13

Are reading and resolving two different phases in the compiler?

Alex Miller (Clojure team)14:04:28

"resolving" is not a phase

Alex Miller (Clojure team)14:04:36

what do you mean by that?

Alex Miller (Clojure team)14:04:52

and I would say reading is a different phase than compiling, not something "in" the compiler. the compiler works on data structures - they may have been read, or you may have constructed them (via macros or some other mechanism)

Alex Miller (Clojure team)03:04:59

and a is not equal to (quote a)

cfleming03:04:30

When working with promises at the REPL, am I correct in thinking that there’s no way to get the REPL to wait for the promise to be resolved and then return that value as the result of the evaluation?

john12:04:21

You can do it in webworker contexts

john12:04:54

There's a few methods to achieve it. One is sharedarraybuffers, which I used to implement repl waiting functionality with

cfleming21:04:06

Interesting, but is there any way I can easily use this in a CLJS REPL?

john21:04:53

Not for the general repl that runs on the main thread, that ships with cljs

john21:04:07

But if some part of an app needs it, where you know you can get by in a worker context, you can use it

john21:04:38

Like for just heavy parsing or whatnot

thheller07:04:27

@cfleming correct. can't block.

vinurs11:04:05

the load example is, how can i translate it into cljs?

vinurs11:04:28

i just write this, (.load storage #js {:key :username})

vinurs11:04:40

but the output is #object[Promise [object Promise]]

metehan12:04:12

hi, what is the fastest way to start with clojure script to have a react app with reframe

metehan12:04:28

are there some boilerplates for newcomers

borkdude15:04:06

Is it possible to have - a foo.cljs file + - a foo.cljc file that defines a CLJS function bar and to call the bar function in foo.cljs? or this this foo.cljs + foo.cljc construction only used for referring macros?

thheller15:04:32

no, not possible. foo.cljc will only be used for CLJ side of things (ie. macros)

borkdude15:04:49

good. can you explain a bit?

Alex Miller (Clojure team)15:04:00

a .cljs file should always be loaded in preference to .cljc

borkdude15:04:57

There is spec/alpha.cljs and spec/alpha.cljc.

thheller15:04:30

CLJS will load .cljs and the :require-macros in that will load the spec/alpha.cljc as a MACRO ns

borkdude15:04:31

And the defmacros from spec/alpha.cljc can be used from spec/alpha.cljs in self-hosted mode

thheller15:04:05

self-hosted works the same way in that sense. spec/alpha.cljc will be loaded as spec.alpha$macros ns, so it is a separate ns from spec.alpha

borkdude15:04:40

ok so this only works when requiring macros, that’s good to know

thheller15:04:00

without the :require-macros CLJS won't touch the .cljc file (if a matching .cljs file exists)

Alex Miller (Clojure team)15:04:46

Clojure is the same way - .clj is loaded in preference to .cljc file

Alex Miller (Clojure team)15:04:15

in other words, platform-specific overrides common

borkdude15:04:15

Summarized: when you have a foo.clj(s) + foo.cljc, in Clojure, the foo.cljc will be ignored and in ClojureScript only macros will be read from .cljc

thheller15:04:39

as Alex said: if the platform specific file exists it will be loaded

thheller15:04:55

:require-macros will therefore load a .clj file over a .cljc file as well

thheller15:04:34

so this .cljs+`.cljc` pattern is really only for self-hosted stuff

thheller15:04:58

otherwise .cljs+`.clj` is much simpler to work with

borkdude15:04:55

foo.clj + foo.cljc Clojure: foo.clj is loaded, foo.cljc is ignored. ClojureScript: foo.clj is loaded when requiring macros, foo.cljc is ignored. --- foo.cljs + foo.clj Clojure: only foo.clj is loaded when required ClojureScript: foo.cljs is loaded when required, only macros are read from foo.clj --- foo.cljs + foo.cljc Clojure: only foo.cljc is loaded when required ClojureScript: foo.cljs is loaded when required, only macros are read from foo.cljc --- foo.cljs + foo.clj + foo.cljc Clojure: only foo.clj will ever be loaded, foo.cljc is ignored ClojureScript: foo.cljs is loaded when required, only macros are read from foo.clj, foo.cljc is ignored ---

thheller15:04:44

why make it so complex?

thheller15:04:12

loading CLJS code .cljs over .cljc. loading CLJ code (directly or via :require-macros) .clj over .cljc

thheller15:04:16

first case was also incorrect. foo.clj + foo.cljc -> CLJS loads .cljc and :require-macros loads the .clj. .cljc is not ignored for CLJS

borkdude15:04:19

you’re right. the .cljc file is still used for normal CLJS functions

borkdude15:04:36

but what if you have also macros in there?

thheller15:04:05

will be used as self-host macros

thheller15:04:36

at least I think it will? I'm actually not sure ... self host hurts my head

thheller15:04:57

it loads .cljc files in :cljs mode so it should in theory pick .cljc over .clj in that case

borkdude15:04:29

so I guess cljs.spec.alpha.cljc is not a .clj file, only because of self-host?

thheller15:04:04

probably yeah

naomarik17:04:46

why does the second thing cause this? Stack trace of root exception is empty; this is likely due to a JVM optimization that can be disabled with -XX:-OmitStackTraceInFastThrow. ---- Exception ---- ---- Exception Stack Trace ---- java.lang.NullPointerException: nil

4
frozenlock18:04:05

If I want to use an external react widget library, do I need to write it a deps.edn so that it will be loaded after the React provided by Reagent?

frozenlock19:04:48

Hmm... then I must be something else wrong. Does that ring any bell? Uncaught TypeError: Cannot read property 'PureComponent' of undefined

lilactown19:04:00

how are you including the external library in your project?

frozenlock19:04:05

First I tried loading it directly via the HTML. When I got the error I thought it was because it was loaded before React, so I added the foreign-libs bit and removed it from the HTML, but still get the same error.

frozenlock19:04:07

The error comes from the lib js itself when loading it.

lilactown19:04:59

honestly I'm not sure, I haven't used the raw CLJS compiler in awhile

lilactown19:04:17

I am not sure how the foreign-libs stuff works. my guess is you'll also need to provide React using the foreign-libs interface as well

lilactown19:04:32

I use shadow-cljs for everything 🙂

frozenlock19:04:36

I'm in a similar position; I always use cljsjs or make my own wrapper. For some particular reasons in this project I need to load everything differently and it's throwing me off.

frozenlock19:04:31

Could it be a JS compilation issue? (I vaguely remember encountering some JS once that needed to be compiled for the browser.)

lilactown19:04:34

my best guess is that highcharts-react is trying to access React.PureComponent and it's not there

frozenlock19:04:11

Well yeah, this part I got 😛 That's the how/why I'm trying to figure out.

lilactown19:04:20

is React even on the window?

frozenlock19:04:01

Yes, the whole app is running fine. It's just this library that won't load.

lilactown19:04:31

sry, I forget even how cljsjs works. in shadow-cljs, libs are not exposed on window

lilactown19:04:14

I'll let someone else weigh in who might know more about foreign-libs

frozenlock19:04:33

Alright. Thanks for your input, I appreciate it!

frozenlock19:04:32

I'm leaning more and more with the JS not being compatible with cljs (webpackUniversalModuleDefinition), but I don't know enough about the subject 😕

Mario C.20:04:08

I am using Om and I have om/IShouldUpdate defined within my component but for some reason it is not being called. I dont see my println... I am updating the state with om/update-state!