This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-21
Channels
- # announcements (1)
- # beginners (20)
- # biff (5)
- # calva (43)
- # cider (5)
- # clj-commons (7)
- # clj-kondo (11)
- # clojure (58)
- # clojure-brasil (1)
- # clojure-denmark (1)
- # clojure-europe (27)
- # clojure-nl (1)
- # clojure-norway (13)
- # clojure-uk (2)
- # clojurescript (71)
- # data-science (32)
- # datalevin (6)
- # datomic (19)
- # emacs (1)
- # gratitude (3)
- # honeysql (8)
- # hoplon (15)
- # hyperfiddle (3)
- # introduce-yourself (1)
- # lsp (19)
- # malli (4)
- # nbb (7)
- # other-lisps (5)
- # practicalli (1)
- # re-frame (14)
- # releases (1)
- # ring-swagger (1)
- # squint (118)
- # xtdb (9)
- # yada (2)
is there something in clojure core that act like or
, but is a runtime value (instead of a macro)? i.e. for use like (reduce or true bools)
(reduce #(or %1 %2) true bools)
just don't put true
for the init value...
yeah I know I can make an anon fn, the question is if something like this already exists in core
not that I know of
(some true? ...) maybe? but unlike reduce it will give you nil in case of all false
Btw, there is (some-fn true?)
that acts that way, but I find #(or %1 %2)
better at communicating the intent, so I guess I’ll stick to that
Could also do either (some identity bools)
or (some true? bools)
, it returns nil
if all are false, but has the benefit of early termination.
my real context was (update acc :bool-field or another-bool)
, so there was no coll of bools, that was an example…
Is a double colon legal syntax in the middle of a var name? Example in 🧵
$ clj
Clojure 1.11.1
user=> (def foo:bar 5)
#'user/foo:bar
user=> foo:bar
5
user=> (def baz::qux 10)
Syntax error reading source at (REPL:3:14).
Invalid token: baz::qux
10
Syntax error reading source at (REPL:3:18).
Unmatched delimiter: )
user=>
The error is pretty clear, no? From https://clojure.org/reference/reader#_symbols: > • Symbols beginning or ending with ':' are reserved by Clojure. A symbol can contain one or more non-repeating ':'s.
Context: I've been using single colons as a light-weight grouping prefix, e.g. widget:foo
and widget:bar
. In the context of debugging clojure-mode's failure to syntax-highlight this correctly (https://github.com/clojure-emacs/clojure-mode/issues/653), I ran into this.
@U2FRKM4TW the section you quote suggests that the syntax error is a bug, no?
Misread
No need to remove the original message though. It just creates clutter since the thread is still there.
my bad
Is there anything that lets me turn an arbitrary form into the string of what would be executed if it was evaled? Essentially, IIUC, going from
(println foo (bar) (…))
to
`(println ~foo ~(bar) ~(…))
I think? So you evaluate all the subforms but leave the final outer form unevaled with just the values that would be passed to it.
My intent is something akin to a 'dry run' mode in a program I'm writing where I can log the form that would be evaluated but with the arg values in place.I just had to
(defmacro debug
[body]
(if (seq? body)
`(list '~(first body) ~@(rest body))
body))
#'user/debug
(debug (println (+ 1 2) (- 2 1)))
(println 3 1)
(defmacro dry-run
[[f & b :as body] & _]
`(log/infof "Would execute ‘%s’"
(list (quote ~f) ~@b)))
@UAEH11THP Thanks! Yours looks more robust. :)
it's the same as yours haha (other than the consideration "what if body is a plain value")
mine still breaks probably if it's used on a macro (like (debug (-> foo (bar 1) (baz 2)))
)
Yeah. I imagine that something that would be truly robust here would actually be a bit difficult.
hmm if only macros then
(defmacro debug
[body]
(if (seq? body)
`(if (not (:macro (meta (var ~(first body)))))
(list '~(first body) ~@(rest body))
~body)
body))
Does anyone know if it is technically permissible to send multiple cookies with the same name in one request? like how urlparams you can do a=b&a=c
to get multiple values
My feeling is whilst it's possible (after all, it's just k/v pairs on the response), the browser's behaviour might make it indeterminate
if you have Set-Cookie: foo=bar;foo=baz
then it might be interesting to see if the browser accepts that and what happens when it sends it back to the server.
https://httpwg.org/specs/rfc6265.html#sane-set-cookie > If the user agent receives a new cookie with the same cookie-name, domain-value, and path-value as a cookie that it has already stored, the existing cookie is evicted and replaced with the new cookie.
> Although cookies are serialized linearly in the Cookie header, servers SHOULD NOT rely upon the serialization order. In particular, if the Cookie header contains two cookies with the same name (e.g., that were set with different Path or Domain attributes), servers SHOULD NOT rely upon the order in which these cookies appear in the header.
` Servers SHOULD NOT include more than one Set-Cookie header field in the same response with the same cookie-name. (See Section 5.2 for how user agents handle this case.)`
I know with a Set-Cookie header there is defined behavior, i'm thinking of the Cookie
header
I'm finding this verbiage (in bold) difficult to understand (from docstring for clojure.data.json/read
):
:value-fn function
Function to transform values in maps ("objects" in JSON) in
the output. For each JSON property, value-fn is called with
two arguments: the property name (transformed by key-fn) and
the value. The return value of value-fn will replace the value
in the output. If value-fn returns itself, the property will
be omitted from the output. The default value-fn returns the
value unchanged. This option does not apply to non-map
collections.
If value-fn returns itself, the property will be omitted from the output. That sounds like identity
but I am not sure.not identity but something similar to (fn foo [k v] foo)
makes sense now, thanks. seems like a bit of a strange choice on implementation though.
this is the way to effectively remove some properties from output
it’s a clever way to indicate “omit this” without a sigil that could be a valid object in json
it’s an unambiguous object in memory available to both the value-fn
definition and the calling code
Definitely too clever for my very smooth brain. I understand now with the examples provided, though, thanks @U11BV7MTK
promise
uses a CountDownLatch for coordination and an atom for the result, the atom's initial value is the CountDownLatch
Is there a doc about function naming conventions? Are they usually named with a verb or just the thing it returns?
For example, say I have an env that sometimes is called (by mistake) test
but it should be staging
. I write a function to correct it, would the convention be to call (correct-env env)
or (corrected-env env)
?
Or is there's no consensus on that
verbs are good. noun may be implied by the arg name and/or namespace context so might not even be necessary. "correct" seems like it doesn't say much about what is being corrected or what a correction would be, so if there's something more specific, I'd try to use more specific words ("staging" seems like an important word here for example)
Zach Tellman's "Elements of Clojure" book has a lot of good advice on naming https://elementsofclojure.com/
And the community style guide has a big section on naming things https://guide.clojure.style/#naming