This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # aleph (3)
- # beginners (98)
- # boot (24)
- # cljs-dev (13)
- # cljsrn (16)
- # clojure (97)
- # clojure-dusseldorf (2)
- # clojure-italy (2)
- # clojure-losangeles (2)
- # clojure-russia (48)
- # clojure-spec (28)
- # clojure-uk (79)
- # clojurescript (79)
- # community-development (2)
- # cursive (4)
- # datomic (35)
- # duct (1)
- # events (1)
- # fulcro (43)
- # heroku (1)
- # jobs (1)
- # lein-figwheel (2)
- # luminus (1)
- # lumo (12)
- # nyc (1)
- # off-topic (6)
- # om (1)
- # pedestal (7)
- # portkey (9)
- # proton (1)
- # re-frame (45)
- # reagent (27)
- # rum (2)
- # shadow-cljs (78)
- # spacemacs (3)
- # specter (2)
- # testing (2)
- # vim (41)
@seancorfield thanks for the link, very useful. It's pointing me towards either maps or records as I'm building a small DSL
Yeah, I think core.match is rarely used in reality. It has a fairly specialized use case -- structural pattern matching isn't an idiom in Clojure like it is in some other languages.
The default starting position is pretty much always "start with maps, switch to records only when you need them"
uberjar is a task that lein can perform, do you mean they remove the uberjar specific config?
it's not apropriate to use uberjar on a library, and leiningen should not be generating uberjar config for a libarary project
its kind of hard to adapt.. i'm used to npm.. which is easy to get private from github
if what you want is to use a library like monger, you don't need to install it, just add it to your dependencies. If you need to use a library for your project, you'll need a private repo (or alternatively everyone can install it on their own machine, but having a private repo saves a lot of trouble)
Yes.. I guess it does.. I'm trying with this https://github.com/tobyhede/lein-git-deps but it doesnt help at all
@rcustodio You normally wouldn't pull in a dependency from GitHub in Clojure. What are you trying to do?
I guess the simple answer is: don't do that -- it's not idiomatic in Clojure. Why do you want to do that? What problem are you trying to solve?
We are developing libraries, but they are private, when we develop services we will need to use that private libraries... this lein-git-deps is practical like npm, easy to explain and use, and it doesn’t need an additional server to keep the private repo
Ah, OK. Probably worth looking at running an internal Archiva repo or similar. For now if you're good working from your internal Git repo and SHAs...
We still gonna use lein-git-deps, seems like its not idiomatic and the clojure community kind of disapproves it, but it's a practical way that will help us for now... thanks for your tips.. if lein-git-deps start to get in the way we see the archiva repo
Any idea why eval-match always matches on A? (defrecord A ) (defrecord B [x]) (defrecord C [x y]) (defn eval-match [x] (cond (type x) A "Type A" B "Type B" C "Type C" (str "No Match: " x))) (eval-match (A.)) (eval-match (B. 1)) (eval-match (C. 1 2))
@sundarj I tried case, but I couldn't get it to match, it always returned No Match (defn eval-match [x] (case (type x) A "Type A" B "Type B" C "Type C" (str "No Match: " x)))
This works, but was trying to figure out other ways to do matching (defn eval-cond [x] (cond = [(type x) x] [A x] (str "A " x) [B x] (str "B " x) [C x] (str "C " x))) (eval-cond (A.)) (eval-cond (B. 100)) (eval-cond (->C 100 200))
this still returns No Match (defn eval-match [x] (case (type x) test.match.A "Type A" B "Type B" C "Type C" (str "No Match: " x))) (eval-match (A.)) '
I don't understand how to match on the type or a record as this also returns "No Match" (let [x (type (A.))] (case x A "A" test.match.A "test.match.A" "No Match"))
boot.user=> (case boot.user.A boot.user.A "a") java.lang.IllegalArgumentException: No matching clause: class boot.user.A boot.user=> (case 'boot.user.A boot.user.A "a") "a"
@sundarj the quote is interesting, but not sure how to quote the type of a function argument. I think you're right condp is the best option. I was just trying to understand case and cond better. Thanks for the help!
@sundarj this works (let [x (type (B. 1))] (condp #(= %1 %2) x A "A" B "B" "No Match"))
@sundarj right, I was building up to this, in which case I need the lambda. thanks. (defn type-to-string [x] (condp #(= %1 (type %2)) x A "A" B (str "B : " (:x x)) "No Match")) (type-to-string (A.)) (type-to-string (B. 100))
@sundarj omg! yes! thank you, that's it. (defn type-to-string [x] (condp = (type x) A "A" B (str "B : " (:x x)) "No Match")) (type-to-string (A.)) (type-to-string (B. 100))
@genec for completeness, here's the multimethod version:
boot.user=> (defrecord A ) boot.user.A boot.user=> (defrecord B [x]) boot.user.B boot.user=> (defmulti type->string type) #'boot.user/type->string boot.user=> (defmethod type->string A [x] "A") #object[clojure.lang.MultiFn 0x4ccb03cd "[email protected]"] boot.user=> (defmethod type->string B [x] (str "B : " (:x x))) #object[clojure.lang.MultiFn 0x4ccb03cd "[email protected]"] boot.user=> (type->string (A.)) "A" boot.user=> (type->string (B. 42)) "B : 42"
oh right and the default:
boot.user=> (defmethod type->string :default [x] "No Match") #object[clojure.lang.MultiFn 0x4ccb03cd "[email protected]"] boot.user=> (type->string 2) "No Match"
anyone using vscode with visual:closure? i am getting exceptions in the repl when trying to evaluate stuff in the editor
Do you mean the clojureVSCode extension? I tried both of the vs code Clojure extensions as I really like vs code, but ended up using Atom with proto-repl as I had trouble getting the vs code / Clojure setup working.
@ashnur For vs code the Clojure nRepl extension by Andrey Lisin is the most popular and the latest version starts / connects to nRepl when you open an project now. There's also Atom with proto-repl that's pretty popular and also lighttable if you want something that just works out of the box for playing around with Clojure.
i ignored the mention of atom earlier, and thanks for suggesting, but will ignore it for a while, because sadly my machine doesn't bare the specs required for running atom with all the things that i need. vscode feels more lightweight, certainly more snappy
as i mentioned previously, next time i will have some time for learning, will try a different extension, actually, already installed the version Lisin authored
sounds good. I just updated and tested the extension from Andrey and it works fine, takes a few seconds to connect to the nRepl. ctrl + shift + e evaluates the file. Whereas the proto-repl lets you evaluate blocks of code so it's more interactive (if that makes sense)
certainly we are fortunate that we are allowed to create freely and give it away for corporations
Just realized that if you select a block of code and ctrl + shift + e then it evaluates just the selected block, if nothings selected then it evaluates the file. cool!
Hey friends, silly convention question. I’ve got a function that will either return a byte-array or nil. Whats the best convention for handling the optional return value of this function, from the callers perspecive?
I am a Clojure noob. I want to build a desktop app using seesaw. However, I have a problem with the choice of the build tool. On one hand, if you google for leiningen vs boot you will get lots of hits praising superiority of boot, but on the other hand, I have big troubles making the basic examples work. To what extent I should trust Google preferring boot. From a noob perspective, is it better to ignore boot and stick to leiningen?
@ruby.object most things will assume lein familiarity, even boot related stuff often does
the reason there are a bunch of blog posts about 'boot is better than lein' is because lein is the defacto standard and it's what most people are familiar with
One thing I do like about boot as a beginner is the repl experience. When you work in a directory from boot repl, boot automatically creates a file called
.nrepl_history which contains the repl expressions that you’ve executed. So, if i’m firing up a repl to do some quick experimenting I reach for
Gorilla REPL is also a fun way to record repl history: http://gorilla-repl.org/index.html
On my system, I only get the nrepl history file with leiningen if I have a project.clj file in the present working directory, whereas with boot I get the history file regardless.
also, nothing beats clojure.jar for quick repl experiments (if you don’t need other deps)
@genec i definitely will have a look, now i need to find how to integrate it with a desktop application
@genec quil+lein is amazing, I did lein new quil hello quil, opened the core.clj file, started repl and selected menu Load all project files