This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-04-15
Channels
- # announcements (10)
- # beginners (113)
- # calva (2)
- # cider (75)
- # clj-kondo (1)
- # cljdoc (2)
- # clojure (142)
- # clojure-europe (11)
- # clojure-gamedev (6)
- # clojure-italy (7)
- # clojure-nl (8)
- # clojure-spec (3)
- # clojure-uk (50)
- # clojurescript (47)
- # cursive (7)
- # data-science (22)
- # datomic (12)
- # dirac (3)
- # events (1)
- # fulcro (114)
- # gorilla (1)
- # jackdaw (5)
- # joker (3)
- # kaocha (10)
- # leiningen (1)
- # liberator (2)
- # mount (6)
- # nrepl (1)
- # off-topic (16)
- # pathom (34)
- # pedestal (3)
- # re-frame (19)
- # reagent (11)
- # remote-jobs (5)
- # shadow-cljs (127)
- # spacemacs (12)
- # test-check (15)
- # tools-deps (8)
- # vim (4)
@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. https://stackoverflow.com/a/48137788/4210855 It generates primes up to 10^8 in ~35s on my computer, which is far faster even than this very fancy implementation: https://github.com/hypirion/primes/ 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).
I prefer that to having nREPL etc as a dependency in production.
You can use nc
/`telnet` or unrepl
or Atom/Chlorine....
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]
(cond
(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]
(cond
(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"]
(:ul
[:li "is defined"]
[[:li "breadcrumb"]
(:ul
[: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"
[:ul
[:li "is defined"]
[:li "breadcrumb"
[:ul
[: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"]]])
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).
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
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.
Or maybe you just need into-array
http://asymmetrical-view.com/2009/07/02/clojure-primitive-arrays.html
@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
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
you don't need a macro - you can use a function
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... :)
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 😃
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 https://clojure.org/reference/deps_and_cli, provides an in-depth explanation of all the above, and more. Here's a list of libraries that leverage deps.edn https://github.com/clojure/tools.deps.alpha/wiki/Tools
Also checkout Sean Corfield's deps.edn file for inspiration. It has a bunch of neat things.
https://github.com/seancorfield/dot-clojure
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.
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?
Where as there are now lightweight Clojure programs as independent tasks, all using tools.deps to grab the dependencies
You can see the full list here: https://github.com/clojure/tools.deps.alpha/wiki/Tools
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.
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.
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?
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 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
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!
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
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 https://clojure.org/reference/deps_and_cli, provides an in-depth explanation of all the above, and more. Here's a list of libraries that leverage deps.edn https://github.com/clojure/tools.deps.alpha/wiki/Tools
Also checkout Sean Corfield's deps.edn file for inspiration. It has a bunch of neat things.
https://github.com/seancorfield/dot-clojure
@deleted-user It may help to think cons
is a sequence operation (associate the s
with seq
uence) 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.
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.
The cons artists switched the order of the jewls on you hahahaha
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?
Has anyone taken any of the clojure courses on Udemy?