Fork me on GitHub
#clojure
<
2023-06-19
>
didibus02:06:10

Is there a very simple searchlib? I want so say given: [dark cloud 2, darc kloud, dark cloud] , search for the entry of "dark cloud" for example, and get the results in order of relevance. I dont need full lucene, I dont need indexing or anything like that, I'll be searching over small strings on a small collection.

Bob B02:06:14

and just to put options out there, something like clj-fuzzy might provide an algorithm that'd be usable in your context, like sorting by levenshtein distance or whatever. clj-fuzzy hasn't been updated in a while, but that might be because it's one of those libraries that doesn't really need to change much (because it's largely string algorithms)

didibus02:06:41

Thanks, I'll explore both, clj-fuzzy might be more minimal and work for my needs

joakimen06:06:21

This might be somewhat of a fringe requirement, but does anyone know of any project (preferably Clojure of course) that lets you configure a given GitHub repo declaratively from a edn or json-file? I often find myself wanting to apply the same settings to most/all of my personal repos, such as • protect main-branch • allow non-trunk rebase from PR UI • automatically delete head branches I could do it using gh, but if someone has solved this in a data-driven way, where I could just store my preferred repo config in git and apply it at will, would be even nicer

pavlosmelissinos08:06:16

I'm not a huge fan of terraform because its DSL is weird but it's ubiquitous, so 🤷 If you go down that path there's also https://github.com/luchiniatwork/terra which supposedly allows you to write terraform configurations with EDN syntax but I haven't used it myself and it hasn't been active for years so I'm not sure how well it supports modern Terraform

pavlosmelissinos08:06:49

That said, it's probably simpler to use the https://docs.github.com/en/rest/quickstart?apiVersion=2022-11-28 directly (plain HTTP calls). It won't be declarative and you'll have to write your own utility functions but it will fit your use case like a glove (and you'll understand exactly how it works)...

joakimen08:06:21

Yeah was wondering if IaC might be the way to go here... It just felt a bit like over-engineering to just keep my personal projects tidy, but maybe not? Pulumi also seems to https://www.pulumi.com/registry/packages/github/api-docs/repository/, and from a blog post from last year, seems to support Clojure indirectly via the java sdk > Pulumi Adds Support for Java, one of the Largest Language Ecosystems in the Cloud > With new support for Java, Pulumi expands reach to the large community of Java developers who previously have not been able to use infrastructure as code to tame cloud complexity. Organizations can now use all JVM-based languages such as Java, Scala, Clojure, Groovy, Kotlin to build, deploy, and manage cloud infrastructure. I'll keep tabs on the IaC route and think about it! Thanks for the reply 🙂

pavlosmelissinos08:06:41

Oh, I missed the part where you mentioned personal projects... I'd probably go down the HTTP API route if I were you if it's just to tweak a few settings in new repos. You'd lose state management but I don't think it's a dealbreaker for personal projects. However, I also don't think IaC is overkill, especially if you have a lot of personal repos and you set it up gradually.

👍 2
fuad13:06:02

I think IaC tools (Pulumi/Terraform) are perfect for this use case. You can use Pulumi with YAML which, trading off some flexibility for the nice, static, declarative style.

👍 2
emccue14:06:17

Someone made an interesting feature request for my resolver

emccue14:06:57

Whats particularly interesting, given that I just cloned tools.deps in a lot of areas, is that clojure just fails in this case

emccue14:06:06

clojure -Sdeps '{:deps {org.jboss/jandex {:mvn/version "3.1.2"}}}' -Stree
Error building classpath. Could not find artifact org.jboss:jandex:jar:3.1.2 in central ()

seancorfield15:06:50

Yeah, that's been a fairly long-standing feature request for tools.deps. I just ran into it with the MySQL connector lib which changed to a relocation on a patch release (8.0.31).

😃 2
Alex Miller (Clojure team)15:06:41

It’s a nontrivial fix

emccue16:06:48

Is the thing that makes it nontrivial that lib names are detached from coordinates usually?

Alex Miller (Clojure team)17:06:53

it just affects a lot of assumptions in the code

seancorfield17:06:24

Presumably, this case is similar to the b.o.m. case? You have a coord that has no associated JAR but leads to what look like transitive dependencies...

Alex Miller (Clojure team)17:06:27

no, you really need to replace it's identity entirely (lib and coord) with an alternate

Alex Miller (Clojure team)17:06:47

there is danger in including both the original and relocated coords in your deps tree if you don't canonicalize them to the same thing

Alex Miller (Clojure team)18:06:04

since this was logged I've added a canonicalization phase that should be able to support this, but I have not really tried to make that happen yet and I suspect there are paths that don't canonicalize

Alex Miller (Clojure team)18:06:27

the problem with groupIds that start with a number has similar scope issues - this means you can't use a symbol to represent the lib (as we do everywhere now)

seancorfield18:06:56

The mysql/mysql-connector-java case is particularly problematic there since 8.0.30 resolves as-is and com.mysql/mysql-connector-j is a "different" group/artifact so tools.deps wouldn't even realize they are the same library. And the 8.0.31 resolves via relocation to the other coords. Ugh!

emccue18:06:05

well once y'all figure out what to do i'll steal it

emccue18:06:16

as is the thing i do and person I am

seancorfield18:06:43

(~/clojure/mysql)-(!2015)-> cat deps.edn
{:deps {mysql/mysql-connector-java {:mvn/version "8.0.30"}
        com.mysql/mysql-connector-j {:mvn/version "8.0.31"}}}

Mon Jun 19 11:25:26
(~/clojure/mysql)-(!2016)-> clojure -Stree
org.clojure/clojure 1.11.1
  . org.clojure/spec.alpha 0.3.218
  . org.clojure/core.specs.alpha 0.2.62
mysql/mysql-connector-java 8.0.30
  . com.google.protobuf/protobuf-java 3.19.4
com.mysql/mysql-connector-j 8.0.31
  . com.google.protobuf/protobuf-java 3.19.4

seancorfield18:06:15

And then if you run clojure -Tantq outdated :upgrade true and innocently accept all the upgrades, they both end up on 8.0.33 and tools.deps can no longer resolve the first one. It's a tricky one to solve.

seancorfield18:06:37

(imagine either of these coming in as transitive deps!)

bherrmann17:06:07

Is there a way to do this? (def [a b c] [1 2 3]) I know I could do (def a 1) (def b 2) (def c 3) or (def temp-coll [1 2 3]) (def a (nth temp-col 0)) (def b (nth temp-col 1)) (def c (nth temp-col 2)) or something clever with "binding" This is when poking with the repl, and then presumably I will convert to a "let" later in the code's life....

pppaul17:06:59

templates may be an option

didibus17:06:19

Not by default, but you can write a macro for it

4
respatialized17:06:34

are you typing these forms directly into the REPL? if you are, I'd suggest using a (comment ...) form in a source file to contain the let binding you're building up rather than using temporary defs to prototype a function.

2
respatialized17:06:28

defining vars from the REPL can make things a little tricky to reproduce and debug, and writing a macro to make that easier might be solving the wrong problem.

p-himik17:06:45

For a one-off:

user=> (doseq [[s v] '{a 1, b 2, c 3}] (intern *ns* s v))
nil
user=> b
2
(note that it's a map in there so you can't rely on its order)

👍 2
pppaul18:06:13

https://clojuredocs.org/clojure.template/do-template this is a bit newbie friendly compared to writing a macro. you can get most of the behaviour that you displayed. hope this helps

(clojure.template/do-template
  [name val]
  (def name val) a 1 b 2 c 3)
this will give you vars a b c with vals 1 2 3

👍 6
🤯 2
daveliepmann18:06:14

For this I use cider-eval-region, by default bound to <kbd>C-c C-v r</kbd>

bortexz18:06:25

Created a small macro for this (bindings are like let instead of two vectors):

(defmacro deflet
  [bindings]
  (let [defs (->> (partition-all 2 bindings)
                  (map (fn [[s v]] (list 'def s v))))]
    `(do ~@defs)))

(macroexpand-1 '(deflet [a 1 b 2 c 3]))

=> (do (def a 1) (def b 2) (def c 3))
PS: I didn’t know about clojure.template, thanks for pointing it out !