This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-01
Channels
- # aleph (2)
- # beginners (137)
- # boot (4)
- # cider (10)
- # clara (29)
- # cljs-dev (71)
- # cljsrn (7)
- # clojure (105)
- # clojure-bangladesh (1)
- # clojure-france (2)
- # clojure-italy (4)
- # clojure-nl (3)
- # clojure-russia (1)
- # clojure-spec (30)
- # clojure-sweden (5)
- # clojure-uk (71)
- # clojurescript (217)
- # cursive (36)
- # data-science (1)
- # datomic (11)
- # duct (53)
- # fulcro (2)
- # garden (3)
- # jobs (1)
- # lein-figwheel (23)
- # luminus (3)
- # lumo (7)
- # mount (13)
- # off-topic (88)
- # pedestal (3)
- # re-frame (63)
- # reagent (85)
- # remote-jobs (1)
- # ring-swagger (3)
- # shadow-cljs (81)
- # spacemacs (5)
- # tools-deps (16)
- # yada (2)
What does the :deprecated "1.2"
metadata in ring.middleware.file-info
means? Means it will be remove in future? on now it is already deprecated when version is newer than 1.2? I check it out in the source code file in "ring/ring-code/1.5.1/file_info.clj". But have not found other new implemented function.
sometimes a function or namespace is deprecated without having a viable replacement
Deprecated just means "it's recommended you don't use this function any more" and the version indicates the release in which it was marked deprecated. Sometimes a better option is provided, sometimes you're expected to go find a different solution elsewhere.
I see. Thanks @noisesmith @seancorfield
According to the documentation for ring.middleware.file-info
: "Prefer the ring.middleware.content-type and ring.middleware.not-modified middleware instead."
The namespace docstring says that https://github.com/ring-clojure/ring/blob/1.6.1/ring-core/src/ring/middleware/file_info.clj#L4
Got it.
I'm using compojure backend with re-frame front end. I need to listen to changes on backend. Right now I poll periodically. What's the best way to employ here? Websockets? Which libraries should I use?
Polling is not so bad - it keeps your backend stateless.
I'm calling a REST service and I'm trying to understand if I should check for and return an error value in the map I would normally return, or should I throw some sort of exception.
@scott.archer I can tell you what we do at work: we have an exception handling middleware that catches any exceptions from our handler, logs it, possibly sends an email to engineering (for unique exceptions), and hands back a 400-series status with some neutral information about the failed request (we put a unique ID in every request that goes in the logs with the exception and is reported back to the client so we can correlate if they ever ask about a specific failure).
I googled it and found a blog where they wrote a macro and started talking monads, I'm not there yet 🙂
@scott.archer Sorry, I didn't read "calling"... So, yeah, on the client side, you'll want to treat non-200 responses as errors as well as failures to get a response (server times out, returns 500 Server Error, etc).
Although bear in mind REST APIs will return non-200 responses for "valid" calls that could not be satisfied: 404 usually means "the requested resource was not found" so your program might "expect" that.
403 (Forbidden) might be "expected" too, possibly some others, depending on how sophisticated the API is.
Right, I'll add code to handle http response codes, for now I'm just handling error returned by the REST API itself.
The REST API returns errors with a 200 OK status?
I just wanted to understand if it was best practice to return those errors in a map vs thrrow some kind of error.
Well, "it depends". Exceptions are the right choice for "this is unexpected" 🙂
Oh, XML... Ugh! Sorry...
org.clojure/data.xml
?
(into (hash-map) (map (fn [x] {(:tag x) (first (:content x))}) (:content (first data))))))
Yeah, there really are no shortcuts with XML -- every solution is ugly 😞
Can't you request responses in a different format, like JSON?
No, unfortunately, only XML. I've written this same type client in C#, Java, Ruby, just using it to learn Clojure.
@seancorfield thanks for being so responsive and helpful on here. As someone who has wanted to learn clojure for years, this slack has really helped me stick with it. I think I've bought 6 books on clojure, but always got stuck when it came to applying the language to a real-world problem.
Happy to help! When I got started (2010), there was really only the mailing list and any conferences/user groups I could attend -- I want the experience to be better for beginners now 🙂
@scott.archer We first started using Clojure at work in 2011 for very small things: little command-line utilities, small cron jobs, a few small library tasks (called from our legacy code)...
That's cool. I don't have any opportunity to use Clojure at work. I think it would be great if I could. I'm in management now though, so I don't do much actual development work anymore 😞
...now we have almost 80k lines of Clojure at work and all our new dating sites run on top of it, as well as almost all of our backend infrastructure...
Clojure build/config 47 files 2510 total loc
Clojure source 259 files 60080 total loc,
3259 fns, 703 of which are private,
377 vars, 41 macros, 56 atoms,
458 specs, 19 function specs.
Clojure tests 147 files 18986 total loc,
23 specs, 1 function specs.
Ah, it's a hard switch from management back to (junior) coding if you dramatically change languages.
But maybe you could find a management role at a Clojure shop that had options for being more hands on? Who knows...
Yeah, we're really try to reduce the number of atoms. Mutable state is bad!
I may go back into development at some point in the future. We'll see how the manager thing goes.
I've done my time as a manager... I liked it in England, I don't much like it in America.
I have a good team, so from that perspective it's really nice, but I still really like problem solving and writing code.
My style is a bit too... brutal... for U.S. sensibilities 🙂
My favorite role has always been (senior) Software Architect for about the last two decades.
Big, complex puzzles, but still hands on.
@duminda No, if you try that, you'll find it doesn't work.
You'll likely get either Can't refer to qualified var that doesn't exist
or Can't create defs outside of current ns
Clojure namespaces don't allow cyclic references across them so you'll need to do some refactoring to break that cycle.
@chester.heng I have a template that covers your usecase exactly. It also provides basic login / logout facilities. Re-frame (which sits on top of reagent) on frontend for SPA and a clojure backend. Its all in the template and should get you going. The only downside is, I was not able yet to document it: https://github.com/sveri/closp If you want to give it a shot and need help you can come to #closp or ask here. I check this slack several times a day.
Hey! What is the default way(not terrible performance) to concat vectors and get vector back?
more than two: (reduce into [...])
or: (into [] cat vs)
Is it ok to alias namespaces to existing symbol names? E.g. [clojure.string :as str]
yes, in fact it's very common to use that alias (`str`) for clojure.string
Hey, all: I’m trying to run this example file from Getting Clojure, after having run lein new app blottsbooks: `(ns blottsbooks.core (:gen-class)) (defn say-welcome [what] (println “Welcome to” what “!”)) (defn -main [] (say-welcome “Blotts Books”))` and getting this error: copied from CIDER: `1. Caused by java.lang.RuntimeException Unable to resolve symbol: defn in this context Util.java: 221 clojure.lang.Util/runtimeException Compiler.java: 7164 clojure.lang.Compiler/resolveIn Compiler.java: 7108 clojure.lang.Compiler/resolve Compiler.java: 7069 clojure.lang.Compiler/analyzeSymbol Compiler.java: 6648 clojure.lang.Compiler/analyze Compiler.java: 6625 clojure.lang.Compiler/analyze Compiler.java: 3766 clojure.lang.Compiler$InvokeExpr/parse Compiler.java: 6870 clojure.lang.Compiler/analyzeSeq Compiler.java: 6669 clojure.lang.Compiler/analyze Compiler.java: 6625 clojure.lang.Compiler/analyze Compiler.java: 6001 clojure.lang.Compiler$BodyExpr$Parser/parse Compiler.java: 5380 clojure.lang.Compiler$FnMethod/parse Compiler.java: 3972 clojure.lang.Compiler$FnExpr/parse Compiler.java: 6866 clojure.lang.Compiler/analyzeSeq Compiler.java: 6669 clojure.lang.Compiler/analyze Compiler.java: 6924 clojure.lang.Compiler/eval Compiler.java: 6890 clojure.lang.Compiler/eval core.clj: 3105 clojure.core/eval core.clj: 3101 clojure.core/eval main.clj: 240 clojure.main/repl/read-eval-print/fn main.clj: 240 clojure.main/repl/read-eval-print main.clj: 258 clojure.main/repl/fn main.clj: 258 clojure.main/repl main.clj: 174 clojure.main/repl RestFn.java: 1523 clojure.lang.RestFn/invoke interruptible_eval.clj: 87 clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn AFn.java: 152 clojure.lang.AFn/applyToHelper AFn.java: 144 clojure.lang.AFn/applyTo core.clj: 646 clojure.core/apply core.clj: 1881 clojure.core/with-bindings* core.clj: 1881 clojure.core/with-bindings* RestFn.java: 425 clojure.lang.RestFn/invoke interruptible_eval.clj: 85 clojure.tools.nrepl.middleware.interruptible-eval/evaluate interruptible_eval.clj: 55 clojure.tools.nrepl.middleware.interruptible-eval/evaluate interruptible_eval.clj: 222 clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn interruptible_eval.clj: 190 clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn AFn.java: 22 clojure.lang.AFn/run ThreadPoolExecutor.java: 1142 java.util.concurrent.ThreadPoolExecutor/runWorker ThreadPoolExecutor.java: 617 java.util.concurrent.ThreadPoolExecutor$Worker/run Thread.java: 745 java.lang.Thread/run` I’m using Leiningen 2.8.1. I’ve seen other people have this problem lacking a ns statement at the top of the source file, but this isn’t the case here. Any ideas?
Sorry for the lack of formatting. I wrote the question in Emacs and pasted it in; I should have done the formatting there. Apologies.
btw. you can edit your message and wrap relevant code with triple backticks ` at the beginning and the end of your code block.
Possibly the ` right before the ns is the problem?
Actually, that was my trying to format the text as code.
Doesn’t appear in the actual code.
It looks a lot like clojure itself is not properly loaded.
What could be causing that? This happens both in CIDER and running lein run
from the command line
So did you copy the code out of ebook? When I just did that I get all sorts of strange control characters in the source.
So for what it's worth I just copied the code out of the pdf, cleaned up all of the nasty characters and ran it with lein run w/o a problem.
I had cleaned some stuff out after pasting, but didn’t realize there were other chars
You're certainly welcome. Glad the book is working for you. The code is avail online -- The url is there in the book -- but my advice is to type the code in yourself anyway. It really helps with the learning process. And besides 40% of it is just ( and ) anyway 😉
Ha, I'm also working through Getting Clojure right now. So far so good. Thanks Russ!
Glad to hear it! If you have questions you know where to find me.
Hi guys any resources (free) for making your own web app from scratch that is up to date?? I used luminus thus far and have been very pleased but i'd like to get basics and just looking at the code won't cut it i know i'd like to use mount that is only requirement ?
You may want to look at https://purelyfunctional.tv/learning-paths/web-programming/
I am not getting when to quote and when not to quote lists and vectors. (into () '(1 2 3)) works, (into () (1 2 3)) throws an error. Same for require; sometimes I see it like (require '[ and sometimes (require [ - totally confused.
the syntax for a function/macro application and the syntax for a literal list are the same, but by default it treats (x y z)
as a function/macro. thus if you want a literal list you have to quote it (quoting a collection also quotes everything inside the collection, recursively)
require
is a function, and a function's arguments are evaluated before the function is called. the default evaluation strategy for a symbol like clojure.core
is to look for a Java class. that's not what we want with require
, we want to pass a literal symbol - thus the quote
[clojure.core]
is a vector containing a symbol, that when evaluated will look for a Java class called clojure.core
.
(quote [clojure.core])
is a vector containing a literal (quoted) symbol clojure.core
, that will be evaluated as itself
=> clojure.core
java.lang.ClassNotFoundException: clojure.core
clojure.lang.Compiler$CompilerException: java.lang.ClassNotFoundException: clojure.core, compiling:(null:64:1)
=> (quote clojure.core)
clojure.core
=> (type (quote clojure.core))
clojure.lang.Symbol
=> [(inc 1)]
[2]
=> (quote [(inc 1)])
[(inc 1)]
=> (type (first [(inc 1)]))
java.lang.Long
=> (type (first (quote [(inc 1)])))
clojure.lang.PersistentList
i hope that makes sense. basically quoting is a way to leave the code as unevaluated data, which is handy when you want to avoid evaluation
If I understand correctly, whenever require is called with a vector, the vector must be quoted all the time. Is that right?
it's really the symbols inside the vector that have to be quoted, but quoting the vector does that
=> (require ['clojure.string :as 'string])
nil
=> (string/upper-case "hello")
"HELLO"
normally you want the default evaluation for symbols (`require` is a symbol that evaluates to the function you want), but in the case of require
, you want literal symbols
here's a case where you wouldn't want to quote them:
=> (let [nmsp 'clojure.set, alias 'set] (require [nmsp :as alias]))
nil
=> (set/difference #{1 2 3} #{3})
#{1 2}
right. ns
is a macro, and macros do not evaluate their arguments, so you don't need to quote anything
Many times I see myself doing much data transformations like this
(into () (into #{} (remove s/blank? f)))
just after doing a
(map #(get % 0) (map #(s/split % #“([\/]*[\/].*)“) l))
The split gives me something like ([“string”] [“string”] [“string”]) then I get 0
to just stay (“string” “string” “string”)
@scott.archer I see, what about require '[,
it's a bracket
I'm also a beginner, but I found this - https://stackoverflow.com/questions/33578444/why-do-we-need-in-require-with-clojure
@scott.archer see my replies to @somedude314's previous message
You could mapcat them. When you go into a set and then back into a list are you just trying to get distinct values?
Hi all, anyone know which folders in window store all downloaded clojure packages?
usually, anything that uses Maven stores them in the .m2/repository directory under your home directory
Thanks @alexmiller Found it.
What is the difference between and @? The article here https://8thlight.com/blog/colin-jones/2012/05/22/quoting-without-confusion.html says "The splicing unquote is similar to unquote, except that it allows multiple forms to be inserted in the place of a single unquote-splicing form" but I still don't understand what the author means.
=> `(str ~[1 2 3])
(clojure.core/str [1 2 3])
=> `(str ~@[1 2 3])
(clojure.core/str 1 2 3)