This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-25
Channels
- # announcements (8)
- # aws (50)
- # aws-lambda (6)
- # babashka (25)
- # beginners (119)
- # bristol-clojurians (5)
- # calva (25)
- # chlorine-clover (23)
- # cider (6)
- # cljs-dev (125)
- # clojure (63)
- # clojure-austin (1)
- # clojure-belgium (1)
- # clojure-dev (48)
- # clojure-europe (11)
- # clojure-italy (2)
- # clojure-nl (5)
- # clojure-spec (3)
- # clojure-uk (66)
- # clojurescript (14)
- # core-logic (5)
- # datomic (13)
- # emacs (10)
- # events (2)
- # fulcro (37)
- # graalvm (11)
- # hoplon (95)
- # jobs-discuss (9)
- # juxt (11)
- # kaocha (16)
- # meander (13)
- # off-topic (24)
- # pedestal (4)
- # re-frame (36)
- # reagent (10)
- # reitit (15)
- # ring-swagger (5)
- # shadow-cljs (23)
- # spacemacs (2)
- # sql (13)
- # tools-deps (32)
- # xtdb (11)
Does case
not support values from other namespaces? This snippet is printing out thing2
:
(ns some-ns)
(def value 12)
(ns my-ns
(:require [some-ns :as sn]))
(case 12
sn/value "thing1"
12 "thing2"
"default")
That’s cool. So it’s not just calling =
for me?
It’s easy enough to fix, but the behavior is surprising. Thank you.
Just as a general piece of advice, if you see something surprising, your first step should be (doc case), which explains all this
Yeah, I did end up looking at the docs and found this as well. I was just baffled that I’ve been using Clojure for this long and apparently have never run into this before. But I think most of the time when I’m using case
it’s for matching on keywords and most of the other times I just stick to cond
It is often surprising when Clojure's behavior on a construct differs from an apparently "identical" construct in a different language. for
is probably the most common difference that trips people up. case
is on the list too tho'...
Yeah, that’s true. I assume the rationale for case
behaving like this is the “constant dispatch time” as mentioned in the docs, no? Or is there another reason for it?
Compile-time constant, yes.
yes, Clojure does a lot of work to restructure these cases into a TABLESWITCH bytecode on the jvm which is constant time lookup (which requires constants)
I seem to recall a 2x2 grid of the four clojure state options (atom, ref, agent, var) in the official docs, does anyone remember where it’s located?
I don't think that's in the reference docs
I do know what you're talking about - the axes are coordinated/uncoordinated and sync/async
sync/uncoord = var, atom
sync/coord = ref
async/uncoord = agent
Need some advice. I have 2 very long-running processes (30 min - 1 hour and 2-4 days). I am currently using callbacks, but I am wondering if there's a better way, considering computing resource usage. Anyone have any experience with this and can give me feedback? Thanks. I should note that I am running this code in Datomic Cloud, but it is not related to database processes.
Using callbacks how? (It's hard for me to suggest you an alternative, because neither what you're doing nor the issue with it are clear to me)
The long-running processes are using callbacks to return the result to the API consumer.
Why not return the values normally, as the result of calling a function ?
The API consumer is customer-facing and needs to reply with "pending" or something like that before returning the actual result. I am thinking of using channels for this.
I would use a database for that. Make yourself a "jobs" or "tasks" table with state and result columns, and query that.
Good idea! Thanks @U06GS6P1N
@arohner it's here http://clojure-doc.org/articles/language/concurrency_and_parallelism.html#clojure-reference-types
What is the difference between
and
??
so that includes Strings (paths), Files, URLs, URIs
and whatever else you install (should be extended to the newer Path too)
I changed the former to the latter and it broke our build pipeline. When I played with it in the repl the results seemed the same to me so I am curious as to what happened.
"broke" = ?
I’m not 100% familiar with the whole system. But changing the former to the latter caused the CI build to fail. But changing it back caused it to work.
I thought they had the same result
(jio/file "string") literally just calls (File. "string")
they differ in behavior on nil
(File throws, file returns nil)
I assume when CI failed, it probably produced some information
Yea I get file not found etc
dunno, doesn't make sense to me
That’s why I came here after getting it working again. Because to me it should be the same behaviour.
without more info, not sure I can help
Seems like the issue was caused by code I was unaware of in the deployment/testing process. Asynchronous file creation/deletion will do it :)
I noticed the use of !
in some source codes. Why is this meant for? I know is for documentation purposes but I guess I have heard few opinions such as: when we are interacting with Databases or external services. Is that true?
I use it for any public function that performs a side-effect
historically it means "this has a side effect", but the usage is inconsistent
lacking ! doesn't mean it's pure, but having it is a pretty good sign something is impure
see also io!
- meant to be called inside code that isn't safe to run in a transaction (AKA impure / stateful code)
user=> (doc io!)
-------------------------
clojure.core/io!
([& body])
Macro
If an io! block occurs in a transaction, throws an
IllegalStateException, else runs body in an implicit do. If the
first expression in body is a literal string, will use that as the
exception message.
nil
I think it was supposed to be used with clojure's mutable-like things. Some people extend it to external state also though.
if you write to a file inside a ref transaction, you are asking for a bad time, io! can help prevent that
same for external non-idempotent API calls
but then again, in practice we don't use refs as much as was originally imagined, and swap! doesn't error on io!, so here we are
Does anyone know how to spec a map that looks like { : key { :<uuid value> { :a "val" :c "val" :d "val"} :<uuid_n> {...other similar maps}}}? Not sure how to get spec to validate/generate a dynamic key with the value as a map.
(s/map-of keyword? (s/map-of keyword (s/map-of keyword? string?)))
Thx alex, that works. Had only seen s/coll-of used in any spec guides and hadn't run across s/map-of (or s/vector-of, etc).
nvm, found it in the main guide lol. Missed it.