This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-01
Channels
- # announcements (7)
- # babashka (41)
- # beginners (117)
- # cider (3)
- # clj-kondo (145)
- # cljdoc (25)
- # cljs-dev (19)
- # clojure (197)
- # clojure-dev (14)
- # clojure-europe (4)
- # clojure-italy (3)
- # clojure-nl (2)
- # clojure-spec (11)
- # clojure-uk (21)
- # clojuredesign-podcast (5)
- # clojurescript (29)
- # code-reviews (4)
- # cursive (87)
- # data-science (11)
- # datomic (29)
- # duct (2)
- # emacs (10)
- # graalvm (1)
- # lumo (13)
- # malli (2)
- # nrepl (5)
- # off-topic (25)
- # onyx (1)
- # pathom (6)
- # reagent (20)
- # reitit (4)
- # rewrite-clj (7)
- # shadow-cljs (114)
- # spacemacs (16)
Hi! If I define two specs a
and b
that define two maps, is it possible to generate c
as the union of the two specs ?
e.g .
(s/def ::a (s/keys :req-un [::foo]))
(s/def ::b (s/keys :req-un [::bar]))
could I define a s/def ::c
from ::a
and ::b
that is equivalent to s/keys :req-un [::foo ::bar]
?Ah it's sufficient to do (s/and ::a ::b)
, sorry, I didn't expect it to be that straightforward
Ah it's sufficient to do (s/and ::a ::b)
, sorry, I didn't expect it to be that straightforward
Hi, I’m trying to parse a fairly large xml file (230MB) using clojure.data.xml but if I accidentally evaluate something that is too big then the REPL crashes. Any tips on how to work with big files in the REPL?
Be very careful what you evaluate 🙂. Other than that, setting print-length can offer some protection. https://clojuredocs.org/clojure.core/*print-length*
Also perhaps your JVM's max memory settings could/should be increased? e.g. -Xmx2G
or something like that.
Without specifying it, the default max memory is auto-calculated by the JVM when it starts up, perhaps different than you would want it to be.
Thanks @U0CMVHBL2
Also, how do I get rid of all the \n
in the output? I tried with :include-node? #{:element}
but then the string content of the element was also removed
Has somebody a github actions
clojars deploy example using deps.edn
(`clojure` command)?
Has there ever been a heated debate on Clojure vs Clojurescript (jvm/node) on this channel? And who won? :)
@arto.eg Even though I develop a lot of ClojureScript for the frontend I always prefer Clojure for the backend. Performance and tooling is generally a lot better. But, I do find js libs and sdks a lot simpler to integrate with. Things like uploading a file to S3 is just way less convoluted. For some libs I prefer the rest-api over the Java SDK.
I’d like to do some 2d graphics with Clojure in JVM. Basically graphics for arcade style game. Focus more on easy to use than on perfomance/visual quality. What would be good libs to look at?
googling for java game-engine
gave this https://litiengine.com/ and seems to close enough to what I was looking for
I run this statement through transit [{'(add-hash {:note "hello"}) [:artifact/note2]}]
and when I receive it on the other side I get [{(add-hash {:note "hello"}) [:artifact/note2]}]
where the single quote on character 3 has now disappeared
(defn transitize [query]
(let [out (ByteArrayOutputStream. 4096)]
(transit/write (transit/writer out :json) query)
(.toString out)))
Maybe my problem is how I am putting it into transit?the quote means "read, but don't evaluate". Clojure is reading it and making a list - this is all expected behavior
Right I had a feeling it was evaluating it while packaging it. How can I tell it not to do that?
I don't understand what you want it to do
if you want it to be data, it's data on the other side so you've accomplished the goal of ' already
if you want it to be evaluated, you'll need to eval it on the other side
The problem is that when I un-transit the data, I end up with [{(add-hash {:note "hello"}) [:artifact/note2]}]
and pathom says "invalid expression". But when I throw [{'(add-hash {:note "hello"}) [:artifact/note2]}]
into pathom it works perfectly. So either I need that single quote to stick around, or I need some other solution that will satisfy pathom
I think you're misidentifying the problem
but not being familiar with the pathom api and your actual code it's hard for me to suggest something
the quote is a reader shortcut for (quote ...)
Ah I found the answer. I've understood what @bfabry was suggesting. I can write (<!! (parser {} (quote [{(add-hash {:note "hello"}) [:artifact/note2]}])))
and it works perfectly
which means on the function side after reading off the wire, it looks like (<!! (parser {} (quote query)))
and so it'll work for everything
Hello, how do I replace -
to \-
? I tried this code below, but it returns "-"
Try (clojure.string/replace "-a-" #"-" (clojure.string/re-quote-replacement "\\-"))
The characters $
and \
are special when doing a regex/string replacement using Clojure.string/replace. The doc string mentions $
, but not \
This also works. (clojure.string/replace "-a-" "-" "\\-")
. Note that the second arg is a string, not a regex, which makes a difference in replace
's behavior, again mentioned in the doc string.
I tried all of the mentioned above. I've got "\\-a\\-" for all of them in the repl
That is a sequence of.5 characters in memory
Different ways of printing a string produce either something that can be read back in via Clojure's reader, thus requiring extra \ escape characters, and some do not. println does not, by default.
I've setup victoriametrics, and I need to escape the dash character
, I try it maybe works with two dashes
Try (count s)
on a string to see how many characters it really is, no matter how it prints. Or (map int s)
to see the sequence of Unicode code points it contains.
user=> (map int (clojure.string/replace "-a-" "-" "\\-"))
(92 45 97 92 45)
That is 5 characters
it totally works, thank you very much!
Escaping can be tricky, I agree, and it can be extra confusing given that different ways of printing strings can add escaping, vs. others that do not.
true, and I needed this because in promql queries the dash is a special character, and I needed to escape that one too 😄
The dash character is not a problematic character for URL's, so your need to escape this must be for the benefit of "victoriametrics"... perhaps it might be better to use standard URL encoding?
https://www.urlencoder.io/ for experimentation
that also totally works, never thought about like this, thank you for the new perspective. (Interesting but with match%5B%5D%3Daseso_free%5C-ram
it doesnt work, but with match[]=aseso_free%5C-ram
it does)
Question , is there any way to have clojure.test tests with some sort of data provider? Like say I want to run the same test 10 times but with different inputs ?
yeah, for short snippets are is nice, but I was writing integration tests which were like a page long
at some point, writing your own test macros that do more makes sense
heck, even normal atoms work I guess. Just write a function that does take inputs, set an atom, run the test
also, even without dynamic bindings, is
calls inside a function bubble up to the containing test
so you can have a function that takes args which contains all your assertions, and call that with different args for your various setups
It might be my test reporter, but when I do this with is
, it reports the same source location for any failure.
It correctly reports the test case name, but if I reuse the function in that test case, I don't know what's failed.
This is good feedback for future versions of clojure.test
if/when it gets broken out of core to a Contrib lib that can evolve independently 🙂
@eraserhd Yeah, is
will just report the location of itself, rather than further up the call chain.
My feedback is that the sort of literate is
/`are`/`testing` seemed really nice, except it never works out that I can make sentences from them.
I wonder if testing
at the call site helps here
Yeah, it would
user=> (require '[clojure.test :as t])
nil
user=> (defn foo [x] (t/is (pos? x)))
#'user/foo
(t/deftest foo-use
(t/testing "first"
(foo -1))
(t/testing "second"
(foo -2))
)
#'user/foo-use
user=> (foo-use)
FAIL in (foo-use) (NO_SOURCE_FILE:1)
first
expected: (pos? x)
actual: (not (pos? -1))
FAIL in (foo-use) (NO_SOURCE_FILE:1)
second
expected: (pos? x)
actual: (not (pos? -2))
nil
I've very little experience with other test runners, I'm really interested to see what someone can do with it.
(testing "that when this bla bla then that" (is ...) (is ...) (is ...)) (testing "that some other thing....)
Like: You can also do this... And if you want to bla you can pass an additional X, etc.
would I be close in assuming that the time complexity for float-array
on a vector is on average linear? The vector is not a linear chunk of memory (necessarily) so it would need to be flattened or copied, is that right?
Yes, it is copied, and is close enough to linear time that it is reasonable to think of it that way (pedantically, there is an O(log N) factor in there with a base 32 log).
Can I force a macro def to return a var of a symbol? I notice that it's possible to get the var, if I def
the marco'd def
(defmacro defdummy [name]
(let [name (with-meta name {:some :here})]
`(def ~name 1)))
(def k (defdummy z))
(meta z) => nil
(meta k) => {:some :here, :line 21, ....}
it seems strange, and I bet this wasn't always like this in clojure.it's unclear to me what you are asking? def
returns a var and there are other ways to make vars, which would allow you to return them
intern
, resolve
, var
all potentially useful, depending on goals
I would love it I can return get var?
true on the symbol that was defined from within a macro body
well, symbols aren't vars so that doesn't make sense
a symbol is name that resolves (possibly) to a var in the scope of a namespace
the reson I'm asking is that something broke in overtone, could be my fault. But the print-method aren't picking the type, so def's that have huge AST, are being printed, which is sometimes a mb of data.
user=> (defmacro defdummy [name] `(def ~(vary-meta name merge {:some :here}) 1))
#'user/defdummy
user=> (defdummy z)
#'user/z
user=> (meta z)
nil
user=> (meta #'z)
{:some :here, :line 1, :column 1, :file "NO_SOURCE_PATH", :name z, :ns #object[clojure.lang.Namespace 0x65e61854 "user"]}
user=>
That follows the pattern used by deftest
. Note that (meta z)
is asking for the metadata on the value of z
whereas (meta #'z)
is asking for the metadata on the var z
.but what I'm able to reproduce is that print-method isn't receiving any type because the metadata
In your code above, k
is bound to the Var
, not the value.
Yes, despite being less efficient, for the use case of overtone, it would make sense to have the var instead of the symbol
(so the value of k
is #'z
)
no, usually not what you want if you're making something new
user=> (meta (var z))
{:some :here, :line 1, :column 1, :file "NO_SOURCE_PATH", :name z, :ns #object[clojure.lang.Namespace 0x65e61854 "user"]}
^ That is var
called on a symbol defined by a macro.(defmacro defdummy [name]
(let [name (with-meta name {:some :here}]
`(do (def ~name 1)
(var ~name))))
(defdummy z)
(var? z) => false
z
is 1
, not a Var
#'z
is a Var
I think you're going down the wrong path and you should go back and understand why your first thing didn't work
this code is ancient, but it did work until recently (this was first reported about like a year ago)
in your very first example:
(defmacro defdummy [name]
(let [name (with-meta name {:some :here})]
`(def ~name 1)))
(def k (defdummy z))
(meta z) => nil
right there, you are asking for meta on the symbol z that you just made, which is nil
the meta is on the var
user=> (meta #'z)
{:some :here, :line 1, :column 1, :file "NO_SOURCE_PATH", :name z, :ns #object[clojure.lang.Namespace 0x695a69a1 "user"]}
in other words, defdummy is doing exactly what you want it to do afaict
can't I bind z to the var of z
!?
is that what you meant to ask? b/c it does not sound sensible
what are you actually trying to do that doesn't work?
(nothing has changed in this area of clojure afaik)
https://github.com/clojure-emacs/cider/issues/2737 this was reported recently
maybe not, but there was a change while back from 1.4 to 1.5 that functions dont carry metadata anymore, so I tought it wasn't unlikely that further optimization on symbols has been carried out, not sure.
that's a mighty long while back
but, I'll try to find another way to solve this, use a different way of specifying type for instruments that don't rely on custom metadata.
I think, again, it would be best to actually understand what is wrong first, before randomly changing things
can you reproduce the behavior outside cider just using a bare repl?
it seems far more likely given the frequency of change and this description that something has changed in cider, rather than in clojure or overtone here
it looks like (m/harpsichord) is invoking an overtone function that plays the sound, then returns a large map, which cider prints
that's what a repl is supposed to do
is that what the overtone function is supposed to return?
maybe cider is installing some print-method extensions that do something based on the type that happens to be returned here
generally, records print as typed maps:
user=> (defrecord R [a b])
user.R
user=> (->R 1 2)
#user.R{:a 1, :b 2}
ok, I can test older cider, good point. My first gut was that the print method was broken. But I'll rule out other possibilites. Thanks for looking at this 🙂
well, I agree that's a good place to look. First, I'd try to repro outside of nrepl/cider/etc - that will tell you whether it's cider or not. Then I'd capture the result of harpsichord to look at it's type, metadata and understand how it is likely to be printed. You might be missing a prefers-method or something.
the key is right here: https://github.com/overtone/overtone/blob/master/src/overtone/studio/inst.clj#L265-L273
I assume for your issue debug that harpsichord returns an Inst, and that's being given meta of ::instrument, and a print-method is being installed for ::instrument.
in the case that fails, that's not working
first, I'd try to verify that (harpsichord) returns an instance, that has the right meta
exactly, I believe I tried that, I added print-method for moth cases Inst and ::instrument.
The meta of the return value from (harpsichord) has overtone to-string helper, it's totally strange, I think it's from one of those nested macros.
I'm testing old cider now with nixos, making a sandbox of older cider version. Doing it the hard way 😛
make sure you check both class
and type
class will tell you the actual Java class. type is the same, but can be overridden with the :type metadata
print-method uses the latter
gotta run...
tracked it down https://github.com/clojure-emacs/cider/commit/ecfea39a7f727ea8d607557a747d4f439422695b 😉 pretty printer
4wiw, fixed https://github.com/overtone/overtone/commit/2005bd7c40b8f348d615e61c0687c79143696a2c
is anyone using Polylith? is it still alive and well? I noticed the repo seems to not have had any commits for a while.
I don't want to invest in figuring it out and using it if the creators have found a better approach or lost interest.
and that's because it takes me a lot more time to figure things out and implement them so I have to choose more carefully than more talented people who can work quickly through things, glean some ideas, and move on.
open to suggestions for how to build and use something on my machine that might be broken out into smaller services in deployment (which is what I understand Polylith to be about).
I don't have 32GB of RAM, which is a factor for me... I can't spin up lots and lots of little clojure apps locally.
or maybe I'm taking the wrong approach.
there was a post in september from a creator of polylith on clojureverse -- it sounded like they were still using it. fwiw, i think the following is the thread: https://clojureverse.org/t/the-origin-of-complexity/4839
cool! it might still be alive.
could be the case that there are fewer commits because it reached a usable point.
good evening!
how do I print the source of a function/def in the repl?
how do I import the repl namespace?
(require '[clojure.repl :refer :all])
or (use 'clojure.repl)
ah i forgot the quote!
thank you
hm it doesn't work?
I have a very simple (def d 123)
but (source d) doesnt work? : source not found ?
source
only works for code read from files
ah...
and if I want to recall previous repl definitions?
now that you say it the name makes sense 😄
by default, the basic repl doesn't do that
oh too bad
many repls let you up-arrow and there are some libs that do more
ok! thank you
Hi folks!
What if I tell you that I'm trying to do an evil thing: monkey-patching Clojure to add support for triple-quoted string literals.
I've just sketched a proof-of-concept implementation here: https://github.com/vdmit11/clojure-triple-quote-strings
It sort of works, I'm already able to do (defn """ ... """)
with Python-style multi-line docstrings.
But, there is one thing I can't tame: it seems as if REPL somehow tokenizes the input.
That is, this split to 3 strings:
clojure-triple-quote-strings.core=> """foo"""
""
"foo"
""
But this thing works:
clojure-triple-quote-strings.core=> ["""foo"""]
["foo"]
And read-string
works of course:
clojure-triple-quote-strings.core=> (read-string "\"\"\"foo\"\"\"")
"foo"
Seems the issue is somehow related to the REPL, as if it splits input into tokens before passing the input to the reader, but I can't find the code where that happens.
So, is anybody able to give me a hint?
And, generalizing: how do I debug reader process?
Any recommendations on tools?
Is there an IDE where I can step over Java and Clojure (combined) with the debugger?it is likely you are using lein, which uses nrepl for the repl, and nrepl is a client/server architecture, and the client lein uses is reply, and to support whatever features reply isn't just a dumb client passing data back and forth
It turned out to be a little challange for me to include a compiled .jar file as a part of deps edn with bare clojure (still figuring that out). But I think you're probably right, it is something about repl client. I've seen the nrepl message, but for some reason completely ignored the fact that it is running over a network. Thanks for the hint, I'll try to dig into that direction.
@vdmit11 in case you haven't seen it, perhaps you'll find the following to be of interest: https://archive.clojure.org/design-wiki/display/design/Alternate%2Bstring%2Bquote%2Bsyntaxes.html
Actually string interpolation is easy. Can be implemented in 2 lines of code:
(require 'cuerdas.core)
(set! *data-readers* (assoc *data-readers* 'f (fn [s] `(cuerdas.core/istr ~s))))