This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-23
Channels
- # 100-days-of-code (5)
- # announcements (3)
- # beginners (68)
- # cider (2)
- # cljdoc (2)
- # cljs-dev (10)
- # cljsjs (2)
- # clojure (40)
- # clojure-austin (2)
- # clojure-dev (17)
- # clojure-italy (8)
- # clojure-spec (4)
- # clojure-uk (9)
- # clojurebridge (1)
- # clojurescript (48)
- # datomic (4)
- # emacs (4)
- # figwheel-main (93)
- # fulcro (8)
- # hyperfiddle (33)
- # jobs-discuss (3)
- # luminus (60)
- # off-topic (66)
- # onyx (42)
- # pedestal (11)
- # re-frame (35)
- # reagent (1)
- # reitit (39)
- # shadow-cljs (30)
- # specter (27)
Hi everybody, I have a fairly simple question that I can’t seem to find the answer to. I have a project.clj
file. My cljsbuild section looks something like this:
:cljsbuild {:builds [
{:id "dev"
:source-paths ["src/cljs" "src/cljc"]
;; The presence of a :figwheel configuration here
;; will cause figwheel to inject the figwheel client
;; into your build
:figwheel {:on-jsload "app.core/on-js-reload"
;; :open-urls will pop open your application
;; in the default browser once Figwheel has
;; started and compiled your application.
;; Comment this out once it no longer serves you.
;:open-urls [""]
}
:compiler {:main app.core
:asset-path "js/compiled/out"
:output-to "resources/public/js/compiled/app.js"
:output-dir "resources/public/js/compiled/out"
:source-map-timestamp true
;; To console.log CLJS data-structures make sure you enable devtools in Chrome
;;
:preloads [devtools.preload]}}
;; This next build is a compressed minified build for
;; production. You can build this with:
;; lein cljsbuild once min
{:id "min"
:source-paths ["src/cljs" "src/cljc"]
:compiler {:output-to "resources/public/js/compiled/app.js"
:main app
:optimizations :advanced
:pretty-print false}}
]
}
I’m trying to get the :min
build to fire when I run lein uberjar
. What do I need to put in my :profiles -> :uberjar
section to make this work? I’ve tried a few different things and they haven’t worked.
I think I figured it out. I added :prep-tasks ["compile" ["cljsbuild" "once" "min"]]
to the :uberjar
profile and removed the cljsbuild hooks.
is it a design feature that clojurescript has the same number precision issue as javascript ?
meaning once you pass the 53 bit accuracy you're on your own with your problems
just tried this out on http://clojurescript.io
cljs.user=> (apply * (repeat 54 2))
18014398509481984
cljs.user=> (+ 1 (apply * (repeat 54 2)))
18014398509481984
cljs.user=> (+ 8 (apply * (repeat 54 2)))
18014398509481990
sure does look like javascript's own math issues once numbers get really big and their floatiness kicks in 😞checked the documentation .... yes it's intended .. a bit sad though 😞
Cljs embraces the host
Maybe someday we'll have arbitrary precision integers and can use the N
suffix for that. https://twitter.com/mfikes/status/1036707072816148486
If curious, ^ is with https://github.com/mfikes/clojurescript/commits/exp-bigint and using a Chrome beta
I'm assuming chrome is implementing https://github.com/tc39/proposal-bigint ?
Is there a polyfill for Bigint?
This is also interesting https://developers.google.com/web/updates/2018/05/bigint
Ah so the bigint proposal will make it work with infix operators like +
So I guess it can't be polyfilled (or even transpiled?)
Yeah. One challenge for ClojureScript (when compared to Clojure), is that you can see for efficiency that (+ 17 18N)
wouldn't work because JavaScript itself disallows it.
(So BigInt doesn't really feel so much like it is part of the tower, but is a separate island.)
It's interesting - JS enhancements come in (at least) 3 groups 1. libraries, which can be polyfilled (Promises, Array methods) 2. syntax enhancements, which can be transpiled (generator functions, classes) 3. runtime enhancements, which can be neither polyfilled or transpiled (Proxy objects?) Group 1 is easy to use from CLJS. The 2nd group is not as relevant for CLJS because we have macros. But 3 might be a challenge
Fortunately, it is fairly easy to play with this new BigInt
thing. Through the magic of using ClojureScript as a git dep:
clj -Sdeps '{:deps {org.clojure/clojurescript {:git/url "" :sha "ec78503abada584d2de5d779433fd2d8de967c94"}}}' -m cljs.main -ro '{:launch-browser false}' -r
and then point Chrome at http://localhost:9000/
and you should be able to do this
cljs.user=> (+ 3312545466734532653465365N 414578429875420942442535454757253N)
414578433187966409177068108222618N
Yeah that's really cool
You can even start to see interesting bits of Clojure leaking into it: Since the reader is Clojure, if you leave off the N
suffixes in the above, it still works.
The efficiency challenge is that this cannot be easily made to work
cljs.user=> (+ 1 2N)
TypeError: Cannot mix BigInt and other types, use explicit conversions
So, to integrate it into the tower, what, we'd need overflow checks that auto-coerce when necessary? Probably cost prohibitive?
I guess then there's also the issue of that tower working with JS libs? Could the tower work in a host-interopy way?
Yeah, ClojureScript doesn't performed checked arithmetic at all. I don't know the rationale or history behind that.
The most challenging problem I see is the simple change of making 2N
read as as a BigInt
instead of as a number. This alone feels like it forks the language in a breaking way.
A concrete example: Consider if someone copied this code from Clojure to ClojureScript
(defn foo [x]
(int (+ 3N x)))
This works today: (foo 2)
evaluates to 5
, but if 3N
is changed to be read as a BitInt
we have a lot of challenging work to do.ah, I guess there's plenty, honestly. Where do you usually go for support on that library?
i really only use the essential functionality—creating/sending raw transactions—so https://web3j.readthedocs.io/en/stable/index.html has been plenty for me
i found that using the java and js libs directly worked with a little less friction, but my use case is pretty scoped
yeah, makes sense. Honestly I think most of my trouble has been coming from ganache-cli. what do you use for local dev?
had never seen ganache. i just run a local node and access geth over http. ipc is pretty simple as well. i would say if you dont need anything specific from ganache to work directly with geth or parity, hasnt put up much of a fight for me
good luck! its also an easy transition to other setups. i started with a local data directory (tmp garbagechain), then moved to rinkeby, then rinkeby using infura, etc..
the way my team from 8 years ago landed on that bomb was this (in native js of course, but you get the point)
cljs.user=> (js/JSON.parse "{\"surprise\": 18014398509481991}")
#js {:surprise 18014398509481990}
.... we sent the "surprise" back to the server as "we are editing that entry" and backend machine said how about no
I asked a similar question in #beginners but I’ll try here, since I’m having trouble finding a good way of doing this that doesn’t involve writing my own parser or printer: I have a CLJS document containing data e.g.
"{:foo \"bar\"
:baz 123}"
and I want to find the line number + position of the value at the path [:baz]
The analyzer includes some meta, like
:form ^{:line 1, :column 1, :end-line 2, :end-column 10} {:foo "bar", :baz 123}
(set! *print-meta* true)
(cljs.js/analyze-str cljs.env/*compiler* "{:foo \"bar\"\n:baz 123}" nil {} prn)
in Lumo or Planck produces some interesting outputif I’m running code in a bootstrapped CLJS env already, can I access the analyzer data in that environment somehow?
I’m trying to build my CLJS project as a JAR and install it locally. I have some tasks that need to run before that happens though, so in my :profiles
section of my project.clj
, I have something like this:
:install { ;:omit-source true
:prep-tasks [["sass4clj" "once"]
["minify-assets"]
["cljsbuild" "once" "min"]]
}
However, it’s not running those prep-tasks at all. What am I missing?