Fork me on GitHub

@gr.evocatus How did your prime number adventure work out? I ended up having to use this yesterday on Problem 437, because 10^8 was just too high of an upper bound for my homemade function. It generates primes up to 10^8 in ~35s on my computer, which is far faster even than this very fancy implementation: It’s pretty readable considering the complexity of what it’s doing, but I would still consider this fairly advanced Clojure (to me, anyway)


Do people leave some sort of network enabled repl like nRepl enabled on their production deployments just in case?


We have a Socket REPL running in several of our production processes, yes. But those ports are not open on those boxes except via loopback so it requires an ssh tunnel over the VPN in order to access them (and if someone can get into our VPN, we have bigger problems than an open REPL).


Is socket repl the way to go for that sort of thing?


I prefer that to having nREPL etc as a dependency in production.


You can use nc/`telnet` or unrepl or Atom/Chlorine....


Gotcha, thanks!


I'm so close to getting my data in outline form, but I'm a little off. The goal is to create a sublist under any of the strings that are repeated, such that it's correctly shaped to be fed to hiccup to make it into html:


;; Preamble
    (use 'clojure.walk)

    (defn map-entry [k v] (clojure.lang.MapEntry/create k v))

    ;; Test data
    (def stories
      '(("Node" "is defined")
        ("Node" "breadcrumb" "links to the parent process")
        ("Node" "breadcrumb" "links to the parent workflow")
        ("Node" "breadcrumb" "when following the parent process link" "reaches the expected process")
        ("Workflow" "is defined")))

    ;; Nest the data structure
    (defn branching-rule [node]
        (and (list? node) (every? list? node)) (group-by first node)
        (map-entry? node) (let [[k v] node]
                            (when k
                              (map-entry k (group-by first (map rest v)))))
        (map? node) (when-not (every? nil? (keys node))
                      (cons :ul (seq node)))
        :else node))

    (def outlined
      (prewalk branching-rule stories))

    ;; Format for hiccup
    (defn formatting-rule [node]
        (string? node) [:li node]
        (and (map-entry? node) (nil? (second node))) (first node)
        :else node))

    (def formatted
      (postwalk formatting-rule outlined))


formatted looks like this:

{[:li "Node"]
  [:li "is defined"]
  [[:li "breadcrumb"]
    [:li "links to the parent process"]
    [:li "links to the parent workflow"]
    [[:li "when following the parent process link"] (:ul [:li "reaches the expected process"])])]),
 [:li "Workflow"] (:ul [:li "is defined"])}


goal state is, I think, something like this:

([:li "Node"
          [:li "is defined"]
          [:li "breadcrumb"
            [:li "links to the parent process"]
            [:li "links to the parent workflow"]
            [:li "when following the parent process link"
              [:li "reaches the expected process"]]]]]]]
        [:li "Workflow"
          [:li "is defined"]]])


Hi all! I'm struggling with a very strange problem, I'm doing dirty stuffs, using clojure from maven (using just the exec plugin I was able to do the build, repl, etc.. so for some use cases it works very well. I've tried to integrate gorilla repl in the project, but when configuring the exec task I found that doing it like:

java clojure.main -m gorilla-repl.core
works fine, if I try to do it like
java clojure.main -e '(println "Clojure" (clojure-version))
                    (println gorilla-repl.core/run-gorilla-server)'
It fails with:
Caused by: java.lang.ClassNotFoundException: gorilla-repl.core
Do you have any hint to help me understand why is this happening?


You have to load the namespace before you use the function from it


requiring-resolve can be helpful in this case


I'm too used to java complexity to look for the simple reasons 😕


yep, with the require works fine...


thank you!


So I’m trying to instantiate a JavaFX KeyFrame class with this constuctor KeyFrame​(Duration time, KeyValue... values), but I keep getting java.lang.ClassCastException: class clojure.lang.PersistentVector cannot be cast to class [Ljavafx.animation.KeyValue; and I’m not sure why. Isn’t it correct to use a vector for java varargs?


That last argument is a varargs argument, so you need to pass it in as a Java array rather than as a Clojure vec


I tried using to-array but now I’m getting a different cast class exception class [Ljava.lang.Object; cannot be cast to class [Ljavafx.animation.KeyValue;


Hmm, you need a type cast on the to-array, but I’m not sure how to do that one.


into-array did the trick! Thanks

👍 1
Ivan Koz15:04:42

can i have an alias for imported java class like we do with require :as?

Ivan Koz16:04:32

@alexmiller any explanation why? Overhead? At first glance it looks like nice feature.


there's not a lot of value in doing so. imports are inherently a much different scenario than requires, despite their similar-looking syntax.


all fully-qualified Java class names are always in scope

Ivan Koz16:04:28

yeah i was looking for something like java.lang.Math :as m ... m/pow

Ivan Koz16:04:50

for now the only reasonable option is wrapping with macros


Clojure import serves only to make an unqualified name easier to write in the source, but the ability to alias classes is not a feature that Java has or that we want to add in interop support

Ivan Koz16:04:34

unqualified name easier to write <- this


you don't need a macro - you can use a function

Ivan Koz16:04:59

but macro is faster

Ivan Koz16:04:16

i mean i understood thank you, not trying to be annoying


but can't be applied, so is more limited


or use memfn


(although be wary of introducing reflection with it)


Math/pow is only 3 more chars... :)

Ivan Koz16:04:43

i was thinking if we already have import to make fully qualified names shorter, why not add aliasing, to make it like 1 character long 😃


now you have two problems names

Ivan Koz16:04:31

yeah as always 😃

Ivan Koz16:04:54

solve one bug to get ten more

Cas Shun17:04:04

hello, I have a collection of namespaced keywords like (:tree/pine :tree/maple :bush/rose :bush/cherry). I wish to either extract all keywords of a given namespace like :tree or :bush, or to partition the collection by their namespace. Is there a shortcut to this, or is filter/remove based on the name space the way to go?


group-by would help with the latter


I'm starting a new Clojure project and I'd like to learn to use deps.edn. A couple of questions. 1. Is deps.edn just for dependency management? Do I still need e.g. Leiningen to create uberjars for my application? 2. Am I able to use IntelliJ IDEA / Cursive REPL as fluently as with Leiningen? 3. Is there some document which provides light to these questions?


1. Yes. tools.deps.alpha is a library that does dependency management, and nothing else. Creates a classpath traversing deps.edn files recursively. The command-line tool clojure uses this and adds a convenient way to invoke code (aliases come in here) 2. I'm not sure what you mean by fluently. tools.deps.alpha currently doesn't have the ability to understand project.clj files if that's what you mean. But there are tools to create deps.edn files from project.clj files. 3. The reference, provides an in-depth explanation of all the above, and more. Here's a list of libraries that leverage deps.edn Also checkout Sean Corfield's deps.edn file for inspiration. It has a bunch of neat things.


Ya, deps.edn only manages dependencies. You can define dependent libraries, and it will pull them down on your machine and create a Java class path which points to them for you.


It currently supports maven repos, and git as places from which it can pull down dependencies.


by fluency I assume @U76D9RZRR means repl/editor integration, there are tools that try to build an ecosystem around tools.deps but eg. cider or cursive are easier to use with leiningen


You still need a way to perform any kind of build tasks you would want, independently of tools.deps


The Clojure CLI is a launcher for Clojure programs. When you launch a Clojure programs which require namespace or imports classes that are not part of the main namespace, you need to give the JVM (the runtime for Clojure programs) a path where it can search for them.


tools.deps can pull dependencies and generate the path to them.


Thus, the Clojure CLI is able to use tools.deps to get the path for your program.


You can still use leiningen as a build tool, but swap out its dependency manager for tools.deps by using this:


@U051SS2EU: Yep, I mean fluent repl/editor integration with Cursive.




I really love cursive and all my hot keys with it, e.g. how to jump between editor windows and repl etc.


So, basically with those tools (lein-tools-deps) etc. I can start using deps.edn as main dependency mechanism and still use Leiningen to build my uberjars etc?


Or is there some new standard way to create uberjars, use profiles etc. with deps.edn?


That said, a lot of people prefer using normal Clojure programs as tasks.


Basically, leiningen is like a framework for writing build tasks.


Where as there are now lightweight Clojure programs as independent tasks, all using tools.deps to grab the dependencies


The difference is that, each of these tools are independent. So they don't share any convention or structure.


Where as lein tasks have more convention and structure, as they have to follow the lein plugin mechanisms


Ok. I think I got the general picture.


I think where it matters is when you need customization. If you need to write custom build tasks, the pure Clojure program way is simpler to a lot of people, because you don't need to learn a framework like lein or boot.


But if you don't, lein is probably better, because you don't need to re-learn conventions of every single tasks.


Now, as to IDE support. It has started, but it's still not as solid as lein.


IDEs rely more on the dependency management of lein then its build tasks. They used lein to setup a REPL with the right dependencies of your project and to inject additional dependencies into the REPL.


Cursive has added support for tools.deps instead of lein, same with Cider. But its newer, not as battle tested, and there might still be some features missing.


Any experience using deps.edn with Cursive?


Sorry. I don't. But what I do know is that the feature hasn't been documented in the official Cursive doc yet.


Which should tell you a bit about its current state.


And how do you build uberjars with deps.edn? Just manually compiling classes and gather dependencies and calling jar tool or something like that? Or do you use e.g. Leiningen with lein-tools-deps to build uberjar anyway?


Like I think you need to use the beta release of Cursive to get the support


deps.edn itself will never do uberjar or other build tasks - it's just a dep manager. People have released libraries / tools to be used with deps.edn to replicate the most common leiningen tasks


You just use lein-tools-deps


Or any other uberjar tool with support for tools.deps as its dependency resolver


Such as depstar


You can also manually compile classes and jar them. You don't need to manually gather them though, that's the part you can use tools.deps for


Basically, if you wrote a program that did that, you'd have created a new uberjarring tool for tools.deps


And so some people have done just that and released their tool.


Maybe I just start using deps.edn with Cursive and let's see how it unfolds. 🙂


This clojurians slack is awesome (a bit unnatural for me to use that word as a Finn, but it is awesome 🙂 ).


And you guys are also awesome the way you help us beginners.


I have now a much better understanding about these tools.


Eh, our pleasure. I definitly love the Clojure community as well. And a few years back, they helped me out a lot as a beginner. So just trying to give back!

Cas Shun17:04:38

ahh, (group-by namespace coll) works then. Thank you @donaldball


anybody here that uses clj-http library? i'm trying to create a get request with more than one :query-params, and it's not working, tried to look on the documentation but didn't found anything there

Nate Sutton19:04:15

anyone have a handy way to remember the difference between cons and conj?


cons is for lists, conj is for everything else


conj on a list is cons

Nate Sutton19:04:53

well sure, that's what the docs say, but remembering which is which

Nate Sutton19:04:04

their order of args are different even

Nate Sutton19:04:19

just a thing you eventually remember, I guess?


just one of those things


ignore cons for two months and get used to conj.


in my experience it is used very infrequently. conj is used constantly


@nate_clojurians It may help to think cons is a sequence operation (associate the s with sequence) and sequence functions take the sequence as the last argument; conj is a collection operation and collection functions take the collection as the first argument.

Nate Sutton20:04:35

ah, that's another thing to learn. the order of args was a head-scratcher


cons converts its argument to a sequence and produces a sequence; conj produces a collection that is the same type as its argument.


map/`filter`/`reduce` etc are all sequence functions -- sequence as the last argument; nth/`conj` etc are collection functions -- collection as the first argument. It's pretty consistent once you know that's the driver for it.

Nate Sutton20:04:58

I'll try to keep that in mind

Nate Sutton20:04:56

so take would be a sequence function

hipster coder20:04:37

The cons artists switched the order of the jewls on you hahahaha

hipster coder20:04:37

user=> (cons 4 x)
(4 1 2 3)


what would be the function to return a seq with the item at a specific index changed for another one?


don't do that


I guess an array is made for specifically this


seqs are not indexed, if you want to do things by index you want something else

Nate Sutton20:04:35

for vector you can use assoc to update a value at an index


ah, I can use assoc as it's a vector


Has anyone taken any of the clojure courses on Udemy?