Fork me on GitHub
#clojurescript
<
2018-08-23
>
john02:08:39

I'm mulling over ideas on how to build SharedArrayBuffer backed persistent data structures in clojurescript and I'm thinking it might be possible to make a garbage-less implementation. There's some interesting discussion on garbage collection for functional languages/data structures.

👍 4
richiardiandrea02:08:48

Wow that would be interesting

john02:08:55

But I'm thinking, if all transactions on the SAB are kept behind a swap/deref interface, then we can leave it to whatever host environment to deal with the memory after it has been dereferenced off the SAB.

john02:08:35

And if any new "top-level" references are created on the SAB that share structure with other pre-existing "top-level" references, it will share their structure. But if a permutation occurs and no top-level references still reference a particular node, the thread doing the permutation handles the free-ing of any old unreferenced data after the new structure is produced.

john02:08:24

And a "top-level" reference would be one created outside of, prior to, any "swapping transaction" into the SAB

john02:08:34

By some make-new-ref function, like creating a new atom.

john02:08:06

So, the thread doing the permutation on the SAB is responsible for all the cleanup/free-ing of un-referenced data, but the algorithm backing the swap/deref interface takes care of all that for the user

john02:08:14

And you could potentially have multiple different languages participating in mutating the SAB, via WASM or Graal or whatever

john02:08:45

All sharing clojure's persistent data structures between each other

john03:08:10

But I'm still thinking through this "top-level" reference vs others. Like, a VectorNode would be immutable, but ephemeral, and only lasts as long as it is connected to some TopLevelVectorRef

john03:08:51

And, again, a dereference of that value off the SAB will produce a host-native persistent implementation that is managed by the host gc

richiardiandrea03:08:13

Uhm, quite a plan 👍 😄

richiardiandrea03:08:27

Need to take the time to read that but it is interesting, thanks for the link!

john03:08:22

Yeah, give it a read and let me know your thoughts if anything comes to mind. Seems like the functional/GC angle may be an under-exploited opportunity

ackerleytng05:08:53

trying to compile something for http://webtask.io (awesome service, btw!) but there's a limit of 100kb cljsbuild seems to be compiling the npm dependencies in. is there a way to prevent that?

Karol Wójcik05:08:06

@ackerleytng did you specified the target of the build?

Karol Wójcik05:08:24

Should be nodejs with optimization simple

Karol Wójcik05:08:45

You should output bundle to one file like bundle.js. Then you need that bundle and node_modules

ackerleytng11:08:50

Oh mine was set to :advanced. How do I output a bundle

Karol Wójcik13:08:45

@ackerleytng You can use :output-to compiler flag 🙂

ackerleytng13:08:07

as in :output-to "some/path"?

ackerleytng13:08:30

that only changes the output path right?

Karol Wójcik14:08:02

Please try to specify the output-dir to target and output-to "to-some-file-in-root-of-your-project"

Karol Wójcik14:08:32

then that file together with node_modules is the only thing you need 🙂

ackerleytng14:08:06

hmm... would you happen to have an example? I have

{:id "prod"
                        :source-paths ["src"]
                        :compiler {
                                   :output-to "server.js"
                                   :output-dir "target/js/compiled/prod"
                                   :target :nodejs
                                   :optimizations :simple
                                   :hashbang false}}

ackerleytng14:08:11

is that correct?

Karol Wójcik14:08:32

That's correct

ackerleytng14:08:09

hmm. but it still compiles my dependencies into the single server.js file, which makes it too big

Karol Wójcik15:08:29

Well I don't think it compiles your dependencies.; OO

Karol Wójcik15:08:58

Could you please move the server.js to some folder where you do not have node_modules?

Karol Wójcik15:08:02

then node server.js

Karol Wójcik15:08:35

If it runs then your node_modules are in the bundle

Karol Wójcik15:08:46

if not then the problem is with the size of your project

ackerleytng22:08:00

I can see one of my dependencies (bluebird) bundled in, because i see this in server.js

/**
 * bluebird build version 3.5.0
 * Features enabled: core, race, call_get, generators, map, nodeify, promisify, props, reduce, settle
*/
My project is just 125 lines of clojurescript, inclusive of comments, I doubt it's the size of my project...

ackerleytng22:08:53

thanks so much for your help!

Karol Wójcik05:08:01

May I please look into the project or it’s not on github?

otwieracz10:08:38

I have created ClojureScript SPA with Shadow-CLJS.

otwieracz10:08:02

However, right now I am facing dilemma how to set the backend url my SPA is talking to.

otwieracz10:08:10

How to include some other JS?

thheller11:08:37

@slawek098 what do you mean "how to set"? you mean passing a variable to your code?

otwieracz11:08:57

I think so, yes.

otwieracz11:08:19

Like including config.js in JS.

thheller11:08:03

how is you app initialized? do you call an init function from your HTML?

thheller11:08:21

I would pass the data in there. so instead of calling init without any arguments like so https://github.com/shadow-cljs/quickstart-browser/blob/master/public/index.html#L10

thheller11:08:59

you call <script>start.browser.init({"url":""});</script>

otwieracz11:08:06

OK, I will have a look. Thanks!

otwieracz11:08:38

I've got one more question. I've got „mixed” project with lein and shadow-cljs (lein for backend, shadow for frontend, some .cljc code is shared)

otwieracz11:08:01

Backend is hosting API with Liberator (and Ring).

otwieracz11:08:33

I thought - maybe it will be possible to merge them when creating uberjar?

otwieracz11:08:53

Like, let shadow cljs build js file and then include it in lein build, and host it with ring?

otwieracz11:08:53

Is this somehow supported?

thheller11:08:45

well you can either run shadow-cljs release your-app && lein uberjar and just make sure your :output-dir is included in the uberjar

thheller11:08:21

or embed shadow-cljs into your lein project.clj and use an alias to run the release task before calling uberjar

thheller11:08:46

as far as the JS is concerned your ring app only needs to serve the file. nothing more.

otwieracz11:08:04

And how can I slurp file relative to JAR contents?

thheller11:08:18

(slurp (io/resource "path/to/file.js"))

otwieracz11:08:40

That might be even better.

veddha12:08:05

can someone tell me how to use media query css at fulcro?

hlolli12:08:04

if all fails you can always @veddha.riady

(fulcro.client.dom/style "@media {..}")
there's #fulcro I don't use Fulcro

melodylane14:08:12

Hi all, is anyone here using cider with figwheel-main? I'm trying to get a minimal figwheel-main/reagent project setup. I used the figwheel-main template and then followed the instructions from cider. I get an error loading cider when trying to resolve cider/piggieback/wrap-cljs-repl. Could not locate cider.clj on classpath. I'm a Clojure/Clojurescript noob and not too sure how to begin debugging issues like this.

melodylane14:08:00

I added cider/piggieback to both my project's dev dependencies and to my profiles.clj just to try to make sure it's being included

bhauman14:08:23

@lane yeah this is still a bug in cider for now

melodylane14:08:49

ok, good to know. Thank you! Figwheel is really awesome 🙂

bhauman14:08:55

you need to add :repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]}

bhauman14:08:09

to your project.clj

bhauman14:08:22

@lane your welcome 🙂

bhauman14:08:45

you can add :repl-options to your :dev profile

melodylane14:08:13

hmm, i did add that inside the dev map like {:dev {:repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]}}

melodylane14:08:59

do I need to add it in my profiles.clj or something?

melodylane14:08:12

(i was referring to the project.clj before)

bhauman14:08:34

when you launch cider do you specify lein?

bhauman14:08:11

no need to add it to profiles

melodylane14:08:23

My cider-default-cljs-repl is nil so I guess not

bhauman14:08:15

do you have a deps.edn in your directory?

bhauman14:08:52

when you launch cider it should ask you whether you want to use lein, unless of course your only have a project.clj in your directory

melodylane14:08:56

nope. Just dev.cljs.edn

bhauman14:08:21

and you are using the latest version of CIDER?

melodylane14:08:38

I updated it last night I think, let me try to get the version

melodylane14:08:14

CIDER 0.18.0snapshot (package: 20180822.1325)

bhauman14:08:42

hmmm I think this could be because of a typo in your project.clj

bhauman14:08:05

can you show me the section where you add the the :repl-options?

bhauman14:08:17

that says cider/piggieback

bhauman14:08:24

it should say cider.piggieback

melodylane14:08:43

Evaluating an alert expression in emacs and then seeing the alert happen is magical

melodylane14:08:15

Do you know of any documentation about the / vs .. I'd just like to learn about what they're doing exactly. I know that / is used to access a function inside a particular namespace, but I'm not sure about the dot.

bhauman14:08:35

the namespace is cider.piggieback

melodylane14:08:08

So when you do cider/piggieback in the dependencies is that including the cider.piggieback namespace?

melodylane14:08:09

And is that a language thing or something that just happens to be the case here? Like would it be com.bhauman.figwheel-main/some-fn?

bhauman14:08:34

@lane in dependencies it is different

bhauman15:08:34

cider is the group-id in cider/piggieback like how org.clojure is the group-id in org.clojure/clojure

👍 4
otwieracz17:08:25

It seems like I must be handling URLs completely wrong.

otwieracz17:08:48

Currently I've got links like:

otwieracz17:08:54

[:> bs/NavItem {:event-key 2 :href "/config/system"} [bold-if-active :config-system "System config"]]

otwieracz17:08:18

But when I tried deploying my app in Tomcat, it ends up completely wrong.

otwieracz17:08:04

Opening kinda works (more on that later, because API url is wrong), but click on „System config” link redirects me to instead of

otwieracz17:08:22

I do understand why is this happening, but how to do this right?

neural18:08:23

hi all!!!! Trying to use figwheel-main but it is not giving me a repl. tryed: lein new fighwheel-main new.app

manutter5118:08:15

Is it the extra "h" in fighwheel?

neural18:08:00

no sorry... lein new figwheel-main new.app

neural18:08:51

when i run lein fig:build its go until open my browser... but never gives me a repl!

neural18:08:38

`(defproject nu.app "0.1.0-SNAPSHOT" :description "FIXME: write this!" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :min-lein-version "2.7.1" :dependencies [[org.clojure/clojure "1.9.0"] [org.clojure/clojurescript "1.10.339"]] :source-paths ["src"] :aliases {"fig" ["trampoline" "run" "-m" "figwheel.main"] "fig:build" ["trampoline" "run" "-m" "figwheel.main" "-b" "dev" "-r"] "fig:min" ["run" "-m" "figwheel.main" "-O" "advanced" "-bo" "dev"]} :profiles {:dev {:dependencies [[com.bhauman/figwheel-main "0.1.5"] [com.bhauman/rebel-readline-cljs "0.1.4"]] :resource-paths ["target"] ;; need to add the compliled assets to the :clean-targets :clean-targets ^{:protect false} ["target"]}})`

exit218:08:20

Hello all, I’m trying to use :npm-deps to install some node modules into my project. It’s generating the node_modules directory but not actually downloading them when I run lein deps. I also have the :install-deps flag as true.

gaverhae18:08:18

Are you using lein cljsbuild?

gaverhae18:08:02

The npm-deps is an option passed to the cljs compiler, I don't think it's visible to leiningen at all. You'll need to actually compile something to get it to download.

exit219:08:35

its working now, I think I had some stale install @gaverhae

ackerleytng22:08:26

my javascript (compiled for nodejs) is 176K after :advanced compilation, and I see

/**
 * bluebird build version 3.5.0
 * Features enabled: core, race, call_get, generators, map, nodeify, promisify, props, reduce, settle
*/
in the compiled code. How do I compile without pulling in these dependencies that can remain in node_modules?

ackerleytng23:08:21

actually... the simplest hello world

(defn ^:export webtask-function
  [ctx cb]
  (cb nil "hellozzz"))

(set! (.-exports js/module) webtask-function)
is already 92Kb. was trying to use clojurescript for a serverless application but i guess not.