This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-01
Channels
- # aleph (3)
- # announcements (10)
- # babashka (6)
- # bangalore-clj (4)
- # beginners (91)
- # biff (7)
- # cider (25)
- # cljs-dev (1)
- # clojure (109)
- # clojure-europe (9)
- # clojure-norway (5)
- # clojure-uk (1)
- # clojurescript (22)
- # cursive (22)
- # data-science (1)
- # datalevin (5)
- # datomic (7)
- # emacs (7)
- # etaoin (1)
- # events (3)
- # graphql (12)
- # hyperfiddle (1)
- # inf-clojure (1)
- # lsp (69)
- # luminus (1)
- # meander (21)
- # nbb (4)
- # off-topic (27)
- # other-languages (12)
- # rdf (58)
- # releases (3)
- # remote-jobs (2)
- # rum (12)
- # shadow-cljs (4)
- # sql (3)
- # xtdb (1)
What are the specific requirements for git libs to work in deps.edn? I am trying to use a package (nfs4j) that works fine via Maven coordinates but doesn’t via gitlib, and I have no idea how to debug:
❯ clj -Srepro -Sdeps '{:deps {org.dcache/nfs4j-core {:git/url "" :git/sha "23aaab51822633fcbc35e9d79b23ce40c64441b9"}}}' -e "(import org.dcache.nfs.vfs.VirtualFileSystem)"
WARNING: Implicit use of clojure.main with options is deprecated, use -M
Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass (URLClassLoader.java:445).
org.dcache.nfs.vfs.VirtualFileSystem
(if you’re wondering why I care: its because that package is not hosted on maven central, and I don’t know how to restrict specific deps to a specific mvn repo, and I don’t love that some random third party repo can just hijack any dependency it likes)
You can set GITLIBS_DEBUG=true to see the git commands. Once it's on disk, it's just pulling in the :paths per deps.edn
clj -Spath will show you the classpath it's using in both cases
Possibly if it relies on compiled classes
But that lib would need to have instructions to prep in its deps.edn
maybe that’s just not expected to work at all and git libs are strictly for clojure libs?
is it possible for you to get a jar by other means? curl it from some download page? Then you could just add a :deps/local
path to the jar itself.
gitlibs are more intended for clojure libs and has a way to prep libs but that requires the project to declare how to prep itself. No pure java lib will do this
Yeah, this is not expected to work. Gitlibs are for Clojure source libs
gotcha, thanks! I’ll do the “jar via other means” bit, thanks for the suggestion @U11BV7MTK 🙂
Oh? It is possible to do -e
with unquoted classes? I always thought that needed to be quoted due to interpreter stuff.
That's really a question about import, which works with either quoted or unquoted class symbols
What's everyone's feeling about using tap>
in libraries? Do anyone expect that nothing will ever tap>
except for their own code?
Generally should be added and removed for debugging
I wouldn't intentionally commit code containing tap>
for an OSS library. I've occasionally done that at work but it was a mistake. We still have a couple of tap>
calls in our production code but we probably meant to remove them before deployment.
So maybe if there's a way to turn it on or off. Let's say someone wants to offer tracing in their lib as a feature, you can go the log route, but that makes more assumptions or pulls in additional dependencies.
tap>
isn't "reliable" as a logging tool... debug-level tracing maybe... but that shouldn't be a concern for your users
> tap is a shared, globally accessible system for distributing a series of informational or diagnostic values to a set of (presumably effectful) handler functions. It can be used as a better debug prn, or for facilities like logging etc.
So if a lib wants to offer diagnostic features, or informational events, would it not be a good fit?
It is a shared bus, there is no way to subscribe to only a subset of what is published
The docs for tools like portal set things up to unconditionally inspect values that get sent to tap
Ya, but that still seems fine to me, the use-case is diagnostic features, or informational events
its not part of the main behavior, its all cross-cutting to what the lib does.
So it seems you would want to have it be an opt-in, but if you were interested in diagnostics or informational events about the behavior of a lib, you could turn tapping on for the lib
I see next.jdbc did something different: https://github.com/seancorfield/next-jdbc/blob/7d5ee09e793720ed4f650dbc3762a3130f030296/doc/getting-started.md#logging This is what I was thinking at first, provide some ad-hoc way to give a callback to the lib
The main issue is that tap>
has a buffer behind it that drops items when it is full. So when things are busy, you'll just lose data.
Which is good so that you don't get paged accidentally in prod because someone forgot to disable the library debug and caused your whole service to brownout 😛
If you needed to log for compliance, or actual user behavior, I would not rely on it, but this diagnostic use case seem apt to it I feel.
We have two-level logging in production already. Well, three if you include New Relic. It's actually been amazingly productive to have WARN+ go to New Relic, a console log that is ERROR+, and a full, rolling log that is DEBUG+.
(tbh, the E+ console log is the least valuable but still provides a good basis for automated "alerting" via scripts that scan log files)
I just remember one issue where a library we were using was logging a ridiculous amount of debug data, and it slowed everything down as logging became a bottleneck. I guess nobody has realized the library was going to start logging stuff. You don't normally assume that.
You can configure clj-kondo with :discouraged-var
to track tap>
usage before you commit anything in an OSS lib
Hey.
I used two slashes in a keyword and it worked on JVM Clojure. But now I installed a linter and it complains because it fails later in the data structure as it incorrectly parses things.
So should keywords with more than one slash be used or not? borkdude
showed that it's not allowed in CLJS but in babashka I can use keywords with two slashes. And in JVM I can use both - symbols and keywords with multiple slashes.
Why is it different everywhere? Why not either deny this everywhere or allow everywhere?
I used this for multiple months now without any issues on JVM and it worked just as I expected it to work -- name part contains the second slash.
https://clojure.org/reference/reader - "'/' has special meaning, it can be used once in the middle of a symbol to separate the namespace from the name, e.g. my-namespace/foo
. '/' by itself names the division function." (keywords are "like symbols")
for best future compatibility, you should not use multiple slashes in keyword names
Thanks. I'll try to add this chat into my issue of Clojure LSP so that they would add it into message. https://github.com/clojure-lsp/clojure-lsp/issues/1163
https://clojure.org/reference/transducers#_sequence > These sequences will consume input incrementally as needed and fully realize intermediate operations. This behavior differs from the equivalent operations on lazy sequences. Could someone please explain the difference?
things like mapcat and sequences are truly lazy - an intermediate step might produce an infinite number of values and that's ok
with transducer mapcat, an infinite intermediate sequence is fully consumed (via internal reduce) and this would hang
So producing a sequence with sequence
will not do any chunking and will perform all of the xf + f over coll immediately?
chunking is irrelevant here
sequences "pull" as needed so can deal with lazy intermediate results
transducers "push" the input values into the transducer stack. if it produces an infinite output, you have no way to just get some of it
When using the sequence
function to create a sequence from the application of a transducer to a collection, is this resulting in both a push and a pull, since there is a sequence and transducers involved? I think I'm getting a little tripped up because the term "sequence" is overloaded?
it's a pull interface over a push transducer
this is a subtle difference, and in many cases a non-difference. it mostly matters when an operation is an expander (can produce multiple outputs for one input value) like cat, mapcat
Thanks @U064X3EF3. It's a little mind bending right now but I'll give it more thought and it'll sink in more over time. The push vs. pull comparison is going to give me something to think about.
Sorry, wrong slack 🥴
I'm trying to understand protocols in Clojure and was reading the example given on https://clojure.org/reference/protocols#_basics:
(defprotocol P
(foo [x])
(bar-me [x] [x y]))
(deftype Foo [a b c]
P
(foo [x] a)
(bar-me [x] b)
(bar-me [x y] (+ c y)))
(println (bar-me (Foo. 1 2 3) 42))
I added a println
on the last line to allow easy feedback when running it in http://replit.com
Now I tried to move the protocol into a different namespace like so:
(ns proto)
(defprotocol P
(foo [x])
(bar-me [x] [x y]))
(ns main
(:require [proto]))
(deftype Foo [a b c]
proto/P
(foo [x] a)
(bar-me [x] b)
(bar-me [x y] (+ c y)))
(println (bar-me (Foo. 1 2 3) 42))
Causing Unable to resolve symbol: bar-me in this context
I am missing something... but I do not understand what.the protocol functions "live" in the namespace where they are defined with defprotocol
so in the last line, bar-me
should be proto/bar-me
(and this is an important bit of abstraction - calling a protocol function and a non-protocol function look the same from the invoker's point of view)
I didn't get what x
was in the example, but it is what is sometimes also referred as this
?
so x
is actually an instance of Foo
Thanks a lot, it was really helpful for me
I think we actually have a web site issue to make this example suck less :)
I am trying to create an editing prompt at the repl to have the user edit an existing value: the user is prompted with the value and and can backspace and edit at will before pressing ‘Enter’ to have the value read, kind of as read-line
does.
What is the best way to do this? I imagine some kind of pushback reader…thanks for any comment.
I guess you just mean reading a line at a time, which should be fine with just using read-line
@hiredman, Yes, a single line at a time: print a value with the cursor positioned at the end: the user can edit at will, and press Enter
I would be fine with backspace characters appended to the initial string, as long as the user can ‘edit’ over it.
that will only work if the repl is running in a real terminal, but a repl can in theory be running on any input and output streams
and the in and out of a repl don't always match the stdin and stdout of the process running the repl
Threads, please! Don't clog up the entire main channel for a single conversation!
If you don't use threads, some people are going to get notified on every message in the channel -- and it also means earlier questions get scrolled off the screen and more likely to get lost in the "noise".
@U06BUCH6D when you mouse over a message, Slack shows a speech balloon icon for reply in thread.
slack has a pretty comprehensive set of preferences for notifications that a user can tune for themself
Folks answering questions should use threads by default in the main channels like #beginners and #clojure -- if you're in a smaller channel, it's fine to chat directly in the channel.
Many people here have asked us (the admin team) to encourage the use of threads in large channels. Please respect those people's wishes.
again, there hadn't been another message in the channel for an hour, it is hardly noisy
Anyway, to get back to my question, it looks like an interesting problem: print the string to be edited by the user and grab the edit with read-line or something similar.
If there was a way to ‘populate’ the background with chars from the editable value. Sorry, not familiar with tty vs *in*
and *out*
streams
line editing is a feature of the terminal, in and out streams are just conveyors of bytes
Hi there, I would like for my backend to return the fields that did not validate against spec. Is there a library that extracts that in the wild by any chance? I know this is not properly a good pattern in spec1 and I'd be willing to try other alternatives in case... Thanks in advance!
thank you, I can definitely write custom parsing code but I'd rather go for a library, if anything is available
the thing to keep in mind is a spec describes a tree, so the failure result isn't just a list of failed keys, it has to account for and be able to explain failures at different locations in the tree
something like this is what I am playing with right now https://github.com/metosin/malli#error-messages
yes I'd have to parse that data structure and extract the fields that are failing
in this example for instance
{:problems
({:path [],
:pred
(clojure.core/fn
[%]
(clojure.core/or
(clojure.core/contains? % :dosage)
(clojure.core/contains? % :volume))),
:val {:foo :bar},
:via
[:contrast-agent/updatable-model],
:in []}),
:spec :acontrast-agent/updatable-model,
:value {:foo :bar}}
I'd have to get to the contains?
formdoable, but I am wondering if there is anything out there that does that for me 😄
oh found this...it's a good start I guess https://github.com/bnoguchi/awesome-clojure-spec
and I think I have got (somehow) a winner 😄 https://github.com/athos/spectrace
Ah, tried and it does not seem to work against the above use case, where an empty map is missing some required keys
if you predicates are opaque functions like :pred above, then it is going to be difficult to get anything reliably
the reason spec's combinators exist for building specs, instead of just making new predicate functions, is specs expose their structure for things like reporting and generative testing
Ok thanks...in a way I just need to know which field is failing the predicate, I was experimenting with malli
yesterday and it seems to fit the bill...