Fork me on GitHub
#clojure
<
2020-01-27
>
andycoffwa00:01:20

Curious results when using reader literals in a vector. This works fine in the repl:

#java/zoned-datetime "2000-01-01T00:00Z"
However, I get an error when I try to place this in a vector and run in the repl:
[#java/zoned-datetime"2000-01-01T00:00Z"]
Execution error at finance.api.db$eval45052/<clinit> (db.clj:115).
No reader function for tag java/zonded-datetime
This also works fine:
[#inst "2018-03-28T10:48:00.000"]
Notice the extra d in java/zonded-datetime in the error message? I have cleared cache in Cursive and tried this in a clj repl. This is mostly a curiosity that I'm interested in seeing if anyone else has come across.

cfleming08:01:02

Just to be clear, you also see this in a command-line clj REPL, right? So it’s not a Cursive issue?

andy.fingerhut01:01:33

Does it make a difference if you have at least one space character before the string?

andy.fingerhut01:01:52

Your example within a vector above does not have one, but the earlier one not in a vector does.

andy.fingerhut01:01:14

Oh, yeah, and that error message with a different name is very weird.

andy.fingerhut01:01:28

I would do a grep over all of your code to see if it contains any occurrences of 'zonded', just in case.

andycoffwa01:01:39

Good suggestion :thumbsup:. I found it. Silly mistake. I had a typo in my print-dup function which must only be used when serializing sequences 😖

andy.fingerhut01:01:28

I did some quick REPL experiments with my own data reader function with a tag cljol/uedge , and it seemed to work at the REPL both inside and outside of a vector, regardless of whether there was a space after the #cljol/uedge

bv03:01:49

https://clojurians.slack.com/archives/C053AK3F9/p1580096279197800 << not strictly speaking a beginners question; do forgive the x-post. would dearly like a hand sorting this import out

seancorfield04:01:15

It's Sunday evening in the US so things are a bit quiet in here @benkay ... I'll follow-up in #beginners

Setzer2210:01:25

I'm working on a bug, but the stack trace is getting erased (optimized?) at some point by the JVM so I just get a "NullPointerException" without a cause or stacktrace. Is there a way to workaround this behavior?

andy.fingerhut10:01:58

Do you get this exception in a REPL?

andy.fingerhut10:01:20

First, you can do something like (def e1 *e) to save the Exception object in the var e1

andy.fingerhut10:01:42

Then try (.printStackTrace e1) to see if it is empty that way or not.

Setzer2210:01:26

Indeed, I can see the trace that way

andy.fingerhut10:01:26

If it is, then the default behavior for many JVMs when starting up is to allow it to optimize away the contents of stack traces. Many people always provide a command line option when starting their JVMs to prevent this from occurring.

andy.fingerhut10:01:03

That option for at least many JVM flavors is: -XX:-OmitStackTraceInFastThrow

Setzer2210:01:31

Great! Many thanks 😀

andy.fingerhut10:01:01

With Clojure 1.10.x at least, the default behavior in the REPL is to show just a 1 or 2 line summary when an exception is thrown.

andy.fingerhut10:01:30

But saving it in a var lets you try other ways to examine its contents. You can also see it in a Clojure datafied way by just evaluating e1

andy.fingerhut10:01:35

There are various middleware/plugin kinds of things that some people put into Leiningen profiles that modify how stack traces are shown, but Java's .printStackTrace has a pretty consistent format.

andy.fingerhut10:01:39

Hmm, looks like I get the same only-1 or 2-line description of an exception in a REPL for Clojure versions back to 1.6.0, so the short summary in the REPL isn't a new thing.

Alex Miller (Clojure team)14:01:20

No, that has always been the case. Other repls vary

enn13:01:52

Other than Cursive, is there a tool that will show me public vars that are defined but not used project-wide?

sogaiu13:01:55

@enn may be clj-kondo can do that?

enn13:01:18

Based on the feature list, it can only detect unused private vars (i.e. it's local to a namespace)

sogaiu13:01:38

it might be worth asking borkdude

dpsutton14:01:04

clojure-lsp can handle this

tianshu14:01:23

can you share the experience for using clojure-lsp? @dpsutton

borkdude14:01:55

@enn clj-kondo does offer this information as part of its analysis export. This is a simple script that just prints them: https://github.com/borkdude/clj-kondo/blob/master/analysis/src/clj_kondo/tools/unused_vars.clj Check out: https://github.com/borkdude/carve which is a tool based on this.

dpsutton14:01:52

Sure. I get project wide refactors, unused var info, nav, docs, arity checks, completions statically

Ramon Rios15:01:10

Hello Friends. Let me ask you somenthing quick: I'm trying to apply a reduce for replace-text in a word document. i want to get a vector with maps such as this

{:variable "$test$" :value "this is the replace"}

; the function that i'm trying to apply.
(.. getRange (replace "$test$" "this is the replace" (new FindReplaceOptions)))
My tought is: how could i get each value of this map at once to apply the necessary changes? Could anyone help me with some insight?

borkdude15:01:34

@ramon.rios Something like:

user=> (let [s "$test$"] (reduce (fn [s {:keys [:variable :value]}] (clojure.string/replace s variable value)) s [{:variable "$test$" :value "test-value"}]))
"test-value"
?

Ramon Rios17:01:17

(defn fill-template-with-data [docx template-data tmp-dir]
   (do
     (reduce
      (fn [{:keys [variable value]} template-data]
        (.. docx getRange (replace variable value (new FindReplaceOptions))))
      template-data)
     (. docx (save tmp-dir))))

Ramon Rios17:01:25

Did not worked as expected

Ramon Rios15:01:54

I think so, let me test that. Thank you @borkdude

dpsutton17:01:15

anyone know how to check the tls version of javax mail? we have it enabled but not sure how to see which version it uses

jumar19:01:10

I don’t know of the top of my head but I would try javamail debug logging

andrea.crotti20:01:52

Given a vector like [1 3 5 2] not sorted but with distinct elements, what's a good way to extract a sub vector given a from and to number? For example passing 1,5 I should get [1 3 5]

andrea.crotti20:01:01

Actually sorry they are not numbers they are keywords

andrea.crotti20:01:14

The numbers was just to show an easy example

noisesmith20:01:33

index math is different, but it's the right behaviour

user=> (subvec [1 3 5 2] 0 3)
[1 3 5]

noisesmith20:01:00

oh - were the args matching elements and not indexes? they were

noisesmith20:01:20

there's drop-while / take-while

andrea.crotti20:01:22

They were matching elements

andrea.crotti20:01:04

Yeah I used that for the beginning, I guess I can use it also for the if I conj the second element

noisesmith20:01:41

I think partition 2 1 idiom helps here

andrea.crotti20:01:02

Ah cool I'll try thanks

noisesmith20:01:28

@andrea.crotti this is weird if the indexes aren't found, but works

(defn inclusive'
  [vect a b]
  (subvec vect
          (.indexOf vect a)
          (inc (.lastIndexOf vect b))))

andrea.crotti20:01:59

ah cool I was looking for indexOf or similar

andrea.crotti20:01:08

it's not wrapped in a core function apparently then

noisesmith20:01:34

clojure is very opinionated about linear time searching

noisesmith20:01:41

makes sure it's never the simple thing

andrea.crotti20:01:02

yeah performance in this case it's not an issue, the vector will have 10 elements 😄

noisesmith20:01:44

haha until just now I thought this was the work slack :D 👋

andrea.crotti22:01:11

Well I was doing it for my work 😁

andrea.crotti22:01:45

A tiny library that might be OSS soon anyway

andy.fingerhut20:01:13

They are not wrapped. They are mentioned in the list and vectors section of the Clojure cheatsheet: http://jafingerhut.github.io

hindol20:01:29

(take-while (complement #{5}) (drop-while (complement #{1}) [1 3 5 2])) But the last item will be missing. This will output [1 3]. I have a feeling I am missing a simple trick.

hindol20:01:42

Probably we can define a take-until function.

andrea.crotti20:01:51

very nice with complement, and yeah I'm just adding it at the end

noisesmith20:01:43

if you do that, you can get strange results - eg. tacking the thing on the end even though it didn't exist after the start-index at all

noisesmith20:01:20

this is where (partition 2 1 coll) is sometimes useful - getting the "peek" of an adjacent element at the end

noisesmith20:01:29

(then map first or map second to get the real result)

andrea.crotti20:01:41

uhm I'm making sure (via assertions) that the elements I look for exist, and they are unique

andrea.crotti20:01:51

so I think it's safe in this case

Nico20:01:07

can I ask a core.logic question here or only in the core.logic channel?

Nico20:01:24

I've asked there, but it seems very low-population compared to here

jimmy20:01:00

I replied in the channel.

aarkerio21:01:04

hi! what is the clojure version of this Java code: TextDocument outputOdt = TextDocument.newTextDocument();

aarkerio21:01:41

I tried : (import org.odftoolkit.simple.TextDocument)

aarkerio21:01:19

(def ^:dynamic newdoc (newTextDocument.))

aarkerio21:01:54

but I'm getting: Unable to resolve classname: newTextDocument

Alex Miller (Clojure team)21:01:34

you want (TextDocument/newTextDocument) - invoke a static method

dpsutton21:01:40

that import looks wrong as well? should it be (import org.odftoolkit.simple TextDocument)

noisesmith22:01:30

this version doesn't work - if you split prefix/suffix you need to wrap it in a collection (import (foo.bar Baz))but I'd only do that if I'm using multiple things from foo.bar

👍 4
noisesmith22:01:08

the only difference with import between ns / non-ns is the keywordize of :import, since it's a macro and quotes args already

dpsutton21:01:06

oh that's the non-ns form. sorry