Fork me on GitHub
#clojure
<
2022-02-06
>
zhuxun204:02:01

What is the current state of building serverless apps in clj/cljs? Do people use cljs->node.js to speed up the cold starts? Or do they use graalvm to compile clj into binaries?

borkdude08:02:33

@U6SEJ4ZUH Some people build serverless stuff with #nbb (CLJS interpreter on Node.js) as well. See https://blog.michielborkent.nl/aws-lambda-nbb.html Also see https://www.loop-code-recur.io/simple-site-analytics-with-serverless-clojure/ for an extensive example. It works on Google Cloud as well, #babashka is also used, e.g. on #holy-lambda. #nbb and #babashka are good for prototyping, when you want to optimize further you can use compiled CLJ(S) and GraalVM native-image.

pinkfrog09:02:42

I am now seeing a weird error:

flowthing09:02:22

Try evaluating (ns-unalias 'user 'log) before running "Load current file...".

pinkfrog09:02:33

I wonder why I shall do that

flowthing09:02:52

Also, make sure there's only one require in the user namespace that uses the log alias.

flowthing09:02:51

Difficult to say for sure, but one possibility is that you've previously required e.g. [app.logging :as log] and now [something.else :as log].

flowthing09:02:27

ns-unalias will remove the current alias mapping.

pinkfrog09:02:06

I found out this only happens after I performed a repl/refresh

hanDerPeder10:02:53

This happened to me as well. Worked around it by removing the path containing user.clj from refresh-dirs. This works fine for me so haven't thought about it enough to figure out why it happens.

pinkfrog11:02:27

I ended up adding the following at the top of the user.clj file

(doseq [sym '[main log]]
  (ns-unalias 'user sym))

seancorfield19:02:31

As usual, I'll take this opportunity to say "Don't use refresh/reload -- develop better REPL habits instead where you eval every single change as you make it so the REPL is always up to date!". These sorts of weird problems are exactly why I tell people not to use this stuff: when it works, it's "magic" -- when it breaks, it's an impenetrable mess.

flowthing19:02:00

Yeah, a big +1 to avoiding refresh/reload.

hanDerPeder21:02:16

Do you take care to unalias vars when you rename a function? In my experience old names leads to more annoyances than using reload.

seancorfield21:02:59

How often do you rename functions? 👀

phronmophobic23:02:05

> How often do you rename functions? During development, I don't always think of the best name on the first try. I try to settle on a good name before others have a chance to rely on the name, but not necessarily before a feature is fully implemented. Is that not normal?

seancorfield23:02:01

@U7RJTCH6J Sounds about right to me, so function names become an API that generally doesn't change once you have "clients" in the code that depend on them. I will occasionally clean out a ns and eval it again but I find that's fairly rare and I just have a couple of Clojure snippets bound to a hot key for that in my editor. It's a localized "reset" just on that one ns that doesn't actually remove the ns -- and therefore doesn't break any code that depends on (which the reload/refresh stuff does).

👍 3
pinkfrog09:02:46

Only happens for the dev/user.clj

pinkfrog09:02:19

It is triggered when I run calva load current file and dependencies

pinkfrog11:02:10

How to you align the clojure data struct in log file? Mine is cluttered on the console:

Ben Sless12:02:59

Do you want text logs or structured logs?

pinkfrog13:02:47

Better text logs with structured json if any. Else structured logs

Ben Sless15:02:44

It's one or the other I'm afraid. If you do structured logging (just log data structures) then you can pipe the output to another process which can pretty print it. JSON in jq, edn in jet, etc

qqq13:02:33

I know about Datalog / Datomic, but it's not what I'm looking for here. With MySQL / Postgres, we have: the database & the query language (SQL). Is there something similar (open source / free for commercial use) where the query language is clojure/scheme-ish. The DB does not have to be relational (i.e. something built on kv store, document stores, mongodb, dynamodb, ... are fine too.) The main idea is that: • there is some persistent store of state • we type in some query in a Clojure/scheme-ish langauge • the query read from /modifies the persistent store • the persistent store is the only 'data' on heap; i.e. the query, after running, does not leave other state on the heap (that is not part of the persistent store) -- in particular, we can capture all state by capturing the persistent store

p-himik13:02:42

The problem definition is not clear. What exactly do you mean by "Clojure/Scheme-ish language"? Datalog can be expressed using Clojure data structures/functions, but it doesn't suit you. SQL can be expressed using Clojure data structures/functions, but it doesn't suit you as well.

Casey06:02:25

Datahike? Datascript? Datalevin?

myguidingstar08:02:28

you can query with EQL (edn query language) using a library called https://github.com/wilkerlucio/pathom, but you have to bring your implementation for your own data store. For instance, https://walkable.gitlab.io is for sql databases.

Carlo17:02:16

In a deps.edn project, I tried do include:

io.github.shrynx/circle-packing {:git/sha "5e00fd45e6b6c03a6ffc5af0703231c88962bdc6"}
when I try to start the repl, I get:
error in process sentinel: nrepl-server-sentinel: Could not start nREPL server: Error building classpath. Manifest type not detected when finding deps for io.github.shrynx/circle-packing in coordinate #:git{:sha "5e00fd45e6b6c03a6ffc5af0703231c88962bdc6", :url ""}
note that that repo is not on clojars, but reading the deps.edn guide it didn't seem that was a prerequisite. What's the true prerequisite to be able to import a library this way? Does the library have to be a deps.edn project too?

p-himik17:02:41

Apart from the sha, you must specify the URL.

p-himik17:02:59

The sha itself doesn't point to anything - it needs a context, which is the repo.

Carlo17:02:29

By which I mean, deps.edn is capable of inferring that from the fact that io.github.shrynx/circle-packing is of this specific form?

p-himik17:02:40

Huh, you're right! I didn't know about that convention.

Carlo17:02:56

Yes, I just found out too, reading the guide; and also, from the error message, you can see that deps.edn knows about the URL. Which confuses me, I don't understand the manifest type not detected part

p-himik17:02:01

> Does the library have to be a `deps.edn` project too? Ah, I believe so, yes. Or pom.xml.

Carlo17:02:24

yes, indeed; thank you @U2FRKM4TW!

p-himik17:02:43

Right, that links confirms that. No problem, and thanks for teaching me about that convention. :)

🙌 1
berkeleytrue17:02:11

Is there a fork-join (aka S' combinator aka Pheonix Compinator) in clojure.core? basically h f g a-> (h (f a) (g a)) ?

p-himik17:02:06

The closest thing that comes to mind is (apply h ((juxt f g) a)).

Noah Bogart17:02:35

You can make your own with juxt: (fn [h f g a] (apply h ((juxt f g) a)))

Noah Bogart17:02:42

Damn, too slow lol

😄 2
berkeleytrue17:02:34

haha nice! Thanks for the replies. I always forget about juxt!

p-himik17:02:51

Well, if the amount of functions is fixed, then spelling it out would probably be better (and shorter, in the case of just 2 functions).

berkeleytrue17:02:40

yeah, that is what I was doing initially.

berkeleytrue17:02:55

Just thought there might be something in core already.

hiredman19:02:34

In the java world forkjoin refers to a mechanism for executing tasks on multiple threads

berkeleytrue19:02:04

yeah kinda the same idea. fork-join is what I know it by from Rxjs.

Max02:02:09

I think the “fork” terminology might’ve been borrowed from APL? Don’t quote me on that