Fork me on GitHub
#clojurescript
<
2020-08-22
>
zach00:08:34

gotcha, thank you!

Sergey Larionov05:08:23

Hello everybody, I'm learning clojure and trying to figure out some things and in shadow-cljs source I found this: https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/cljs/model.cljc#L1 Is anybody familiar with how it works? I see a lot of references to this model from all over the source but can not find a place where those functions/variables are defined. Like for example this one, https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/cljs/ui/main.cljs#L58

dpsutton05:08:10

its just a namespace for keywords

dpsutton05:08:30

(assoc db ::m/tool-id tid) is an example where m is [shadow.cljs.model :as m]

Sergey Larionov05:08:41

I see, thanks. How is it different from just :tool-id?

dpsutton05:08:16

things like :tool-id can be very hard to find. lots of different contexts ect. adding a namespace can greatly simplify things. an example from a webapp, imagine you have routes for :user and views for :user and then objects have user. it can be quite helpful to qualify things like :transaction/user. can add some context to the notion of user. then you can easily discover other usages of users on transactions and not all users, be they users on a transaction, or a refund, or login, or email, etc.

dpsutton05:08:58

and you can use namespace aliases for existing namespaces. and rather than type out shadow.cljs.model/tool-id the alias ::m accomplishes the same thing but with brevity for reading and writing code

Sergey Larionov05:08:09

got it, thanks. But in this particular case it seems like there is only one single namespace model for all the keywords, is that right?

thheller07:08:22

@sergey.larionov yes the intent here is just to namespace keywords. the library I'm building is EQL based and uses mostly namespaced keywords. this is a good talk explaining the "why". https://www.youtube.com/watch?v=IS3i3DTUnAI

thheller07:08:56

basically its just to make keywords more unique and I don't like to mess with too many aliases so I just group everything under one namespace. otherwise you get issues with circular dependencies and such.

Sergey Larionov11:08:32

I see, thanks a lot

scknkkrer12:08:25

Is there anything I’ve missed with the load-file ? I can call it directly, but I cannot wrap it for a forward-usage as a function.

p-himik12:08:04

Not really an answer to your question, but it does have an interesting comment: ;; INTERNAL - do not use, only for Node.js.

scknkkrer12:08:17

I’m using in Node.js. 😳

p-himik12:08:52

I don't think it automatically resolves the "INTERNAL" part. :) But it's still interesting why it wouldn't work in your scenario.

scknkkrer13:08:32

{:type :js-eval-exception, :error {:status :exception, :value "Execution error (SyntaxError) at (<cljs repl>:1).
Unexpected identifier
"}, :form (blo), :js "try{cljs.core.pr_str.call(null,(function (){var ret__6698__auto__ = track.core.blo.call(null);
(cljs.core._STAR_3 = cljs.core._STAR_2);

(cljs.core._STAR_2 = cljs.core._STAR_1);

(cljs.core._STAR_1 = ret__6698__auto__);

return ret__6698__auto__;
})());
}catch (e18323){var e__6699__auto___18324 = e18323;
(cljs.core._STAR_e = e__6699__auto___18324);

throw e__6699__auto___18324;
}"}

scknkkrer13:08:59

But I can call it in a literal code.

(load-file "blabla.cljs")

thheller14:08:54

load-file is a special form in the REPL. it cannot be used dynamically in a function.

scknkkrer14:08:03

But in Clojure parts, can do. Is this some implementation detailed block or something ? I need some hacky-trick to solve my problem, I guess.

thheller14:08:52

CLJ can do it yes, CLJS cannot

borkdude14:08:12

I'm trying to implement assert-expr in CLJS, but I'm getting undeclared var messages..:

$ plk
ClojureScript 1.10.597
cljs.user=> (require '[clojure.test :as test])
nil
cljs.user=> test/assert-expr
            ^
WARNING: Use of undeclared Var cljs.test/assert-expr at line 1
nil
cljs.user=> clojure.test/assert-expr
            ^
WARNING: Use of undeclared Var cljs.test/assert-expr at line 1
nil
cljs.user=> cljs.test/assert-expr
            ^
WARNING: Use of undeclared Var cljs.test/assert-expr at line 1
nil
What's going on here?

thheller15:08:26

@borkdude its implemented in clojure so it is on the macro side of things. in self-hosted that would be the cljs.test$macros ns

borkdude15:08:38

I think I implemented the multimethod in a .cljc file like so: In require:

[clojure.test :as test :refer [is]]
#?(:clj [cljs.test :as cljs-test])
One defmethod for Clojure:
defmethod test/assert-expr 'thrown-with-data?
     [msg [_ data expr]] 
And one for CLJS:
defmethod cljs-test/assert-expr 'thrown-with-data?
     [_menv msg [_ data expr]]
Yet I'm getting:
WARNING: Use of undeclared Var sci.core-test/thrown-with-data?
at the call site (only in CLJS)

kingcode15:08:50

Is there a cljs lib or other tool to facilitate the development of Mozilla extensions for Firefox?

risto18:08:37

Hey everyone, How do I get Cider to work with Krell? I found these instructions but I'm not sure what needs to be done here: https://github.com/vouch-opensource/krell/wiki/Tooling-Integration---Emacs%2C-Cursive%2C-VSCode-etc.#nrepl-emacs-etc Should it go into a file somewhere and which command would I run? Sorry for the noob question

dnolen20:08:02

@risto might want to ask in #cljsrn I know people did get it working, I don't use Cider just Cursive & CLI so I can't be of much help

risto20:08:10

Ah thanks I'll ask there 🙂 I found https://increasinglyfunctional.com/2020/05/07/clojurescript-react-native-krell-emacs.html blog post, but I'm also an emacs noob too 😓 It doesn't seem to read the directory variables afaict

Sam Ritchie21:08:59

I've been working with Fraction.js to implement a ratio data type in cljs, for a generic arithmetic system; is there a way to extend some multimethod to generate instances of Fraction when the reader encounters a ratio? or is this not extensible as a user?

Sam Ritchie22:08:13

Actually, I know the answer here (I could find a way to hack it but this would make my literals unparseable by others), and I have a better solution here, I think

Sam Ritchie23:08:34

Yup, that is a good idea too for user interaction. My situation here is that the sicmutils library likes to emit these big quoted lists representing an equation, and numbers autoquote so you get ratio outputs

Sam Ritchie23:08:37

But not in CLJS. I think the elegant thing here is, implement tagged literals for the user as you suggest @alexmiller (but on the CLJS side I can’t tag an actual ratio literal, right?),

Sam Ritchie23:08:31

But then for the quoted list, have ratios emit ‘(/ numerator denominator) since that will parse into a ratio just fine, and my override of / will do the right thing in CLJS too

Sam Ritchie23:08:57

Would #ratio 1/2 work at a CLJS repl? I would think for self hosted at least, but maybe always, the inputs have to be parseable first. Could pass a string of course