Fork me on GitHub
#clojure
<
2019-09-24
>
paul a00:09:50

is it possible to set environment variables with deps.edn on a per-alias basis?

seancorfield00:09:32

You could set system properties (but not env vars)

sova-soars-the-sora05:09:51

Hi Experts, How would you represent a ranked collection in clojure? Like that of ranked users on some number of points?

henrik05:09:40

A map of numbers to UUIDS. (sort-by :points users) is another option.

alfredx05:09:26

By ranked you mean sorted?

4
alfredx06:09:38

There are various options but if your data size is big, and care about performance, you probably need to consider with peculiarities in your use case (read/write patterns)

henrik08:09:31

If it’s a lot of data, it probably needs to be handled inside a database.

gerred11:09:08

something like:

gerred11:09:44

if you already had it in your stack, a sorted set in Redis is another good way to do this.

ataggart14:09:26

Depending on how you’re using it, a sorted-map or priority queue might work.

sova-soars-the-sora14:09:36

Thanks all, the data-set is not too big. Likely fewer than 10k entries

sova-soars-the-sora14:09:26

How can I get the index (rank/sort position) of an map matching on a specific key after i do (sort-by) ? tanks

ataggart15:09:24

Which data structure did you settle on?

arohner15:09:14

Some dependency in my webapp is causing a java app to appear on my dock (macOS). Is there a clever way to figure out which dependency is doing that? (Excluding obvious things like partitioning the requires)

hiredman16:09:16

there is some command line option you can pass to avoid that happening if I recall

hiredman16:09:03

-Djava.awt.headless=true

bronsa16:09:25

apple.awt.UIElement=true also may help

zalky16:09:37

Hi all, from what I've read a lot of effort went into improving error reporting in Clojure 1.10. However, I just updated a somewhat minimal project and the error messages seem less helpful than they were in 1.9. For example: In 1.9:

clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: No such namespace: a, compiling:(my/example/ns.cljc:16:16)
In 1.10:
clojure.lang.Compiler$CompilerException: Syntax error compiling at (my/example/ns.cljc:16:16).
{:clojure.error/phase :compile-syntax-check, :clojure.error/line 16, :clojure.error/column 16,
:clojure.error/source "my/example/ns.cljc"}
The error messages no longer tells you what heuristic was broken, just that it's a general syntax error and where to find it. I'm wondering if there may be some configuration or dependency that I might be missing?

paul a16:09:40

while i don't have any specific examples handy, i've had the same feeling.

paul a16:09:02

actually, that example is exactly what i would point to - name errors are not as easy to recognize.

noisesmith17:09:03

in this case it's not a missing dep, it's invalid syntax, newer clojure versions are more strict about syntax that older versions let slide

noisesmith17:09:23

oh - never mind, that wasn't your point

seancorfield17:09:37

@zalky What REPL/tooling are you using when you see that? Not all tooling has caught up with the underlying changes in 1.10/1.10.1 so some tooling now shows worse errors.

👍 4
zalky17:09:53

@U04V70XH6, I thought it might be something related to that. I'm using boot 2.8.3, and nrepl 0.6.0.

noisesmith17:09:51

what do you see if you evaluate *e after getting that error in a repl (eg. require / :reload or load-file)?

noisesmith17:09:07

that could help establish if the error display is eliding the interesting part

👍 4
zalky17:09:10

Ah, I think you may be right! I believe the discrepancy is due to my setup, which involves connecting my cider repl to a remote nrepl server and a running watch task that recompiles all my clojure code on change. When the watch task tries to reload the code, it seems like it only emmit the partial error. If I try to reload the namespace from the cider repl, the full error shows up, which includes both the syntax check, and the no such namespace error. So I guess I need to figure out what is responsible for emitting the error from the watch task.

noisesmith17:09:16

I wouldn't be surprised if the tool had a new version that behaved better with newer clojure versions

seancorfield17:09:27

I doubt that combination has been updated to leverage the new error triage machinery. 2.8.3 is the latest stable release of Boot so I think you're just out of luck there.

noisesmith17:09:42

oh, boot limits the cider / nrepl layer? never mind, I misread, cider wasn't in charge of the watcher

seancorfield17:09:26

In order to take advantage of the error reporting improvements in 1.10(.1), tooling needs to be updated to conditionally use the new triage function introduced there.

seancorfield17:09:13

clj / clojure does this (of course) and I suspect Leiningen may have been updated (maybe?). I would expect the latest CIDER to do it -- that team is very active -- but Boot's last release was back in April and although 1.10 came out in December last year, 1.10.1 didn't appear until June. So I suspect the Boot team didn't really have the new handling on their radar that soon after 1.10...?

Alex Miller (Clojure team)18:09:22

I don’t know what boot is exactly doing in this case so hard for me to say. But the Error Reporting section of https://clojure.org/reference/repl_and_main covers the various things now available to use.

zalky18:09:19

So, after some digging, the tool in question (danielsz/system) uses clojure.stacktrace/print-throwable to emit the error. The error being emitted does in fact have the full error with all the relevant information, but it seems that clojure.stacktrace/print-throwable prints only the first part of the error (in the :via property). Is there some better way to produce a printable string of the error?

Alex Miller (Clojure team)18:09:14

Yes, as described in the link I posted prior

👍 4
zalky18:09:50

Roger that. Looks, straightforward, thanks!

noisesmith17:09:01

it looks like that error reporter is showing the ex-info data but not the error message

denik17:09:15

deps.edn question: I'm using a repo that has three artifacts (https://github.com/roman01la/uix), core, dom and rn, each with their own deps.edn. How can I use tools.deps with git resolution to make this work?

dominicm17:09:37

@denik you're looking for :deps/root

dominicm17:09:57

@denik that's actually listed at the top of the readme 😛

denik17:09:30

:man-facepalming: thanks @dominicm

denik19:09:26

Writing a grammar in instaparse I get stuck at the following problem:

(let [expr   "> abc :foo bar baz :and 300"
      parser (insta/parser
              "expr = token (<whitespace> token)*
              <token> = cmd | search-phrase | key-arg-pair
              
              cmd = '>' | 'cb' | '>cb'
              search-phrase = not-cmd-and-words-or-numbers
              key-arg-pair = keyword <whitespace> arg
           
              <keyword> = #':[a-zA-Z0-9]+'
              <arg> = (keyword | not-cmd-and-words-or-numbers)
           
              (* not cmd and then any words and numbers *)
              <not-cmd-and-words-or-numbers> = !cmd words-numbers
              words-numbers = word | number (<whitespace> words-numbers)*
              
              <word> = #'[a-zA-Z]+'
              <number> = #'[0-9]+'
              whitespace = #'\\s+'
              ")]
  (clojure.test/is
   (=
    [:expr
     [:cmd ">"]
     [:search-phrase [:words-numbers "abc"]]
     [:key-arg-pair ":foo" [:words-numbers "bar" "baz"]]
     [:key-arg-pair ":and" [:words-numbers "300"]]]
    (parser expr))))
output:
FAIL in () (command_bar.cljc:102)
expected: (= [:expr [:cmd ">"] [:search-phrase [:words-numbers "abc"]] [:key-arg-pair ":foo" [:words-numbers "bar" "baz"]] [:key-arg-pair ":and" [:words-numbers "300"]]] (parser expr))
  actual: (not (= [:expr [:cmd ">"] [:search-phrase [:words-numbers "abc"]] [:key-arg-pair ":foo" [:words-numbers "bar" "baz"]] [:key-arg-pair ":and" [:words-numbers "300"]]] [:expr [:cmd ">"] [:search-phrase [:words-numbers "abc"]] [:key-arg-pair ":foo" [:words-numbers "bar"]] [:search-phrase [:words-numbers "baz"]] [:key-arg-pair ":and" [:words-numbers "300"]]]))

denik19:09:31

argis supposed to match multiple words through the underlying not-cmd-and-words-or-numbers. Instead search-phrase takes precedence.

aengelberg19:09:54

instaparse doesn’t guarantee precedence unless you use an ordered choice operator (`/` as opposed to |), or a negative lookahead (`!`) to enforce that certain rules are a “last resort”

denik19:09:34

wisdom from the source! thanks @aengelberg. still I'm not able to force precedence, even with the ordered operator

aengelberg19:09:09

ah, looking more closely at your grammar I can see why that wouldn’t work

aengelberg19:09:20

@denik it seems like the DSL you’re implementing has the property that once you start adding keyword arguments, everything from that point forward should be part of a keyword argument pair (not a search phrase)

aengelberg19:09:35

but you aren’t encoding that into the grammar

denik19:09:31

@aengelberg exactly right. isn't this part encoding it?

key-arg-pair = keyword <whitespace> arg
<keyword> = #':[a-zA-Z0-9]+'
<arg> = (keyword | not-cmd-and-words-or-numbers)

aengelberg20:09:55

that part is accurately defining what keyword arguments look like, but when you write :kw arg1 arg2, arg2 could legitimately either be the second argument or a new search phrase

aengelberg20:09:22

so it isn’t ruling out the possibility of more search phrases after your keywords

denik20:09:52

hmm, I wonder how to do that. search-phrase should also only match once

aengelberg20:09:30

I think you need to re-organize the grammar top-down. at a high level it should look something like this:

expr = cmd search-phrase+ key-arg-pair+

aengelberg20:09:07

I’m making some assumptions there, and also missing the whitespace, but that might be a starting point

denik20:09:44

ok thanks @aengelberg any way to match search-phrase only once?

aengelberg20:09:09

expr = cmd <whitespace> search-phrase <whitespace> key-arg-pair*

denik20:09:04

ah, (<whitespace> token)* is preventing that

denik20:09:10

ok, I'll try my luck

aengelberg20:09:39

i might not have gotten the bits and pieces exactly right, but the idea is to tell instaparse “all the search terms go first, then all the keyword arguments”