This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-07
Channels
- # announcements (5)
- # asami (17)
- # aws (11)
- # babashka (67)
- # beginners (90)
- # calva (13)
- # cider (17)
- # circleci (6)
- # clj-kondo (3)
- # clojure (53)
- # clojure-europe (12)
- # clojure-france (8)
- # clojure-germany (3)
- # clojure-losangeles (1)
- # clojure-nl (4)
- # clojure-norway (4)
- # clojure-spec (15)
- # clojure-uk (8)
- # clojurescript (41)
- # cursive (7)
- # data-science (6)
- # datomic (8)
- # emacs (10)
- # exercism (1)
- # figwheel-main (2)
- # fulcro (5)
- # graalvm-mobile (97)
- # graphql (1)
- # hyperfiddle (7)
- # inf-clojure (6)
- # interop (4)
- # introduce-yourself (5)
- # jobs (3)
- # kaocha (3)
- # malli (8)
- # meander (8)
- # music (3)
- # nrepl (7)
- # observability (1)
- # off-topic (45)
- # overtone (2)
- # polylith (63)
- # portal (2)
- # re-frame (26)
- # reveal (8)
- # ring (3)
- # shadow-cljs (56)
- # tools-build (5)
- # vim (11)
- # xtdb (8)
Is there an elegant way to handle big integers in ClojureScript? Some libraries or tricks?
Usually just include big.js, but this wiki describes some of the differences: https://github.com/MikeMcl/big.js/wiki If you're looking for a CLJS example, Fulcro RAD has a namespace worth checking out: https://github.com/fulcrologic/fulcro-rad/blob/develop/src/main/com/fulcrologic/rad/type_support/decimal.cljc
There's js/BigInt
that exists in browsers and on Node. And it supports arithmetic just fine, so you don't have to treat it in a special way at least there. But (number? ...)
returns false
, so it might not work in some cases, and some libraries might not know about it.
=> (def a (js/BigInt "900719925474099100"))
#'cljs.user/a
=> (def b (js/BigInt "900719925474099101"))
#'cljs.user/b
=> (+ a b)
#object[BigInt 1801439850948198201]
=> (number? a)
false
I saw there's a library called bn.js. Is it necessary to be used in ClojureScript? Or js/BigInt
is exact what I want?
js/BigInt
by itself does not need any libraries, it's built-in.
But hard to say whether you need something in addition to that because we don't know your exact requirements.
Hello, I'm getting a warning when setting the meta of a record, yet it works:
cljs.user> (defrecord A [])
cljs.user/A
cljs.user> (meta (A. {:tag 1}))
WARNING: Wrong number of args (1) passed to A at line 1 <cljs repl>
{:tag 1}
Any idea how to resolve this ?The warning is not from meta
but from (A. ...)
. The text of the warning is rather clear IMO - you have defined a record that expects no arguments (`[]`), and yet you pass one argument when creating it.
If you want {:tag 1}
to be the metadata of a newly constructed record, then you have to extract that map from under (A. ...)
and replace meta
with with-meta
.
the thing is that when defining a record, the constructor can take 3 additional arguments on top on the positional fields: __meta
, __extmap
and __hash
. Setting the __meta
does seem to work despite the warning, I'm properly getting it back when calling meta
on the result. If that's discouraged I would except a warning about that instead of the arity.
Ah, I see what you mean. The docstring says that there are two additional arguments though, not 3:
Two constructors will be defined, one taking the designated fields
followed by a metadata map (nil for none) and an extension field
map (nil for none), and one taking only the fields (using nil for
meta and extension fields).
So in your case, it should really be (A. {:tag 1} nil)
. Even though when transpiled, the constructor does become a function with 3 arguments. But regardless of how many arguments you provide, there's still that warning, so seems like there's an issue in parsing the new
statement.I'm guessing it's this line ? https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/analyzer.cljc#L2558
when I require an npm dependency for the first time (like (require '[moment])
) the Var is nil. After manually reloading the browser the Var is set correctly. Is this expected? Using figwheel-main.
no, in an ns macro
does it matter?
There's a difference between require
and :require
. The ns form should use only the latter, and its inner vector should not be quoted.
yes, that’s what I’m using. Just for context, I’ve used clojure for several years, but new to clojurescript.
expanding on your snippet
(ns my.ns
(:require [moment]))
(println moment)
This prints nil
. After a reload of the browser it prints the object as expected.I see in the output folder that the js file is generated with a line that says require("moment")
and the bundler webpack
is re-run. but still nothing until I refresh the browser
Oh, so you're using some non-trivial setup then, given that webpack is involved. Sorry, no clue then. I use only shadow-cljs and have never had such issues.
custom reader conditionals eg. (node vs browser): did this ever go anywhere? https://clojure.atlassian.net/browse/CLJS-2396 according to shadow-cljs docs not https://shadow-cljs.github.io/docs/UsersGuide.html#_conditional_reading
I installed react-native-localize
and performed a (js/require "react-native-localize")
. However, the repl prompts the package not found.
I probably can't help, but the next question someone will probably ask you is how you're compiling/building your clojurescript (lein, boot, shadow-cljs, other) and where you're running it (in a browser, in nodejs, other)
I hate to do it as the guy is a saint but you'll probably get a faster and more specific answer in the shadow-cljs slack, but also the best information you'll find without asking someone will be in the shadow-cljs user manual
it sounds like what you've done should work, shadow-cljs respects/integrates NPM and normally finds npm modules, have you killed your cache (in .shadow-cljs) and done a full rebuild?
also can you see the package in your node_modules subdirectory, with a reasonable package.json?
if you look into your .shadow-cljs/builds/<your-build-name> directory, you can see where shadow-cljs is physically moving your dependant packages
@U2FRKM4TW that's a better question thanks, js/require works right but if shadow-cljs hasn't bundled the dependency then it won't, and is it the (ns (:require... part that actually prompts shadow-cljs to bundle in the npm package?
I think so - I'm not an expert here. And maybe it's common to use js/require
in React Native, which I myself don't use, but you definitely don't do that if you target a browser.
did you reload the app after adding the package? in react-native metro is responsible for loading packages and as such is only available if metro has seen it
if you load the namespace with the require via the REPL first then metro won't see it
Hi @U63D7UXJB when is the files in .shadow-cljs/builds/<your-build-name> directory,
generated, and how are the moved? I see they are all named in the format of .cljs.cache.transit.json
Just saw this section: https://shadow-cljs.github.io/docs/UsersGuide.html#_compiler_cache which answers what the files.