This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-02
Channels
- # announcements (21)
- # bangalore-clj (1)
- # beginners (122)
- # calva (29)
- # cider (9)
- # cljdoc (1)
- # cljs-dev (7)
- # cljsrn (1)
- # clojure (84)
- # clojure-dev (11)
- # clojure-europe (2)
- # clojure-houston (2)
- # clojure-italy (31)
- # clojure-nl (5)
- # clojure-uk (37)
- # clojuredesign-podcast (3)
- # clojurescript (14)
- # cursive (66)
- # data-science (5)
- # datavis (1)
- # datomic (6)
- # fulcro (16)
- # graphql (4)
- # jobs (2)
- # music (1)
- # off-topic (20)
- # pedestal (1)
- # re-frame (2)
- # reagent (2)
- # shadow-cljs (155)
- # spacemacs (5)
- # tools-deps (5)
- # vim (8)
- # yada (1)
A follow-up to the discussion in #off-topic :
Is there any practical difference between bound-fn
and binding-conveyor-fn
?
I'd say so too but then don't know why bound-fn
just doesn't use binding-conveyor-fn
under the hood
I found the symbol regex in the EDN reader: https://github.com/clojure/clojure/blob/c6756a8bab137128c8119add29a25b0a88509900/src/jvm/clojure/lang/EdnReader.java#L27
Edn is a subset of Clojure syntax - Clojure code is read with LispReader
But either I don’t understand Java regex syntax, or it doesn’t seem to match my understanding.
symbols seem to be officially described here: https://github.com/edn-format/edn
based on the official description, I came up with this mental model (which is a bit of short-hand):
- a
(alpha): [a-zA-Z]
- n
(num): [0-9]
- s
special: [\.\*+!\-_?$%&=<>]
- /
slash: \/
a symbol can be:
- single-char name: [as/]
- multi-char name: [as][ans]+
- single-char prefix, single-char name: [as]/[as/]
- multi-char prefix, single-char name: [as][ans]+/[as/]
- multi-char prefix, multi-char name: [as][ans]+/[as][ans]+
i.e. the first rule is read as “a symbol can be a single-character name: [a-zA-Z\.\*+!\-_?$%&=<>\/]
”
Because the set of symbols the reader can construct, and the set of all symbols is not the same, you cannot use the reader to determine what a valid symbol is
for (the set of all symbols) - (symbols the reader can construct), can you help me imagine what those are? or where they come from?
For example the reader won't read 1 as a symbol, but (symbol "1")
will construct such a symbol
user=> (def (symbol "1") "foo")
Syntax error compiling def at (REPL:1:1).
First argument to def must be a Symbol
I think there is some special handling of the /
character when calling the symbol function for creating namespaced symbols
so you can create invalid symbols at run-time, but you can’t actually def
them to anything?
You could also programmatically construct a form containing the 1 symbol and pass it to eval, bypassing the reader
user=> (intern 'user 'x 1)
#'user/x
user=> x
1
user=> (intern 'user (symbol "0") "foo")
#'user/0
user=> 0
0
user=> user/0
Syntax error reading source at (REPL:7:0).
Invalid token: user/0
When you type anything at the reply it goes through the reader first, and the reader doesn't accept the 1 symbol
does anyone follow any naming convention for functions without "active" side effects, but potentially returning different values at different time (e.g. deref
)?
stolen from tonsky: https://tonsky.me/blog/readable-clojure/#use--as-prefix-for-references
that is name of a ref. I am curious about names of "getters" which are pure, but the thing they get from - is not.
I feel like I'm missing something obvious, but has anyone set GOOGLE_APPLICATION_CREDENTIALS
or any environment var for their Clojure code to use via (System/getenv)
while using cider jack in?
@allandaviesza i always start a repl from cmdline and use cider-connect
... you could also use some configuration mechanism like juxt/aero
yea I've done that in the mean time
would be nice if I had a method to create an env var that required no work from other devs working on the project
This depends on the "configuration tool" you use.
You shouldn't really use System/getenv
directly because that's difficult to manage but rather use something more flexible like https://github.com/tolitius/cprop that allows you to use variety of approaches - EDN files, System properties, Env vars
That particular one is also used by Luminus: http://www.luminusweb.net/docs/environment.html
thanks for your suggestion 🙂
like writing it in to profiles.clj
(if it was to be committed)
@vlaaad looks like it's working! For some reason I glossed over this earlier when finding it via Google, many thanks for bringing it to my attention! 😄
is it (and if yes, is it practical, and if yes, how) possible to do timeouts when using pmap
?
As a feature of pmap, no
pmap is really most ideal for chunky computational tasks
Then whats the best way to do some network calls and such in parallel without huge amounts of added complexity?
future
may be of use
Something to that effect.
How would i implement something like pmap with Futures? The whole Futures Thing is somehow really confusing for me..
You may want to look claypoole's pmap
: https://github.com/TheClimateCorporation/claypoole#why-do-you-use-claypoole
a call to future returns immediately then executes the body on another thread
so you'll set up a bunch of requests that will all start at the same time
then the second map will block execution while waiting for the first future to return
(I'm referring to the code in the snippet above)
the best thing to do is to try it out using sleep
So the first map creates a list of Futures (as i understand, a future is comparable to a promise in Javascript, correct?) And the second map then awaits their completion one after Another using deref. Wouldnt in your example the Futures get created only when attempting to deref them because of the lazyess of map?
future
also returns what the body returns, the body being the expression within the call to future
yea thats a good point, so you can use mapv
which is not lazy
you're correct about them being comparable to a promise
I think future
is a lot more simple than a promise
No. But it is fairly common to write a regular function that wraps the protocol method implementation so that you can do "regular" stuff to it (metadata, instrumentation with Spec, etc).
@U04V70XH6 I did an experiment and it turns out to be Yes - you can alter metadata on protocol methods.
(ns myns)
(defprotocol CanFly
(fly [this height]))
(alter-meta! (get (ns-interns 'myns) 'fly) assoc :mymeta "Awesome")
@UM8SD6W8G Interesting!
@U2ECUGHME Can I ask what’s your context in trying to inject metadata into protocol methods? Writing a framework/tool, or..