This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-18
Channels
- # alda (8)
- # aws (1)
- # bangalore-clj (1)
- # beginners (55)
- # boot (114)
- # capetown (2)
- # cljs-dev (51)
- # cljsjs (1)
- # cljsrn (14)
- # clojure (119)
- # clojure-belgium (6)
- # clojure-brasil (9)
- # clojure-conj (2)
- # clojure-greece (1)
- # clojure-korea (2)
- # clojure-poland (12)
- # clojure-russia (64)
- # clojure-spec (12)
- # clojure-uk (60)
- # clojurescript (159)
- # code-reviews (2)
- # component (4)
- # core-matrix (2)
- # cursive (79)
- # datascript (7)
- # datomic (2)
- # defnpodcast (4)
- # events (2)
- # hoplon (13)
- # jobs (2)
- # lein-figwheel (1)
- # off-topic (10)
- # om (42)
- # onyx (60)
- # pedestal (5)
- # perun (7)
- # rdf (4)
- # re-frame (4)
- # reagent (21)
- # ring-swagger (25)
- # schema (1)
- # spacemacs (52)
- # specter (1)
- # utah-clojurians (1)
- # yada (5)
I have a namespace with a gen-class
function in order to generate a single java class with a static method (something like this: https://gist.github.com/david-mcneil/435822#file-gen-class-ex-clj-L42-L47). I'm working on a library so I don't want to create an uberjar, but it appears that the only way to get this class in my jar is to add :aot
for the namespace in the project.clj
, which includes all of the dependencies and transitive dependencies as well. Is there any way to simply generate the one class? If not, is there a best practice for how to handle this?
you could just write it in Java
lein knows how to compile and include Java classes already
I have done almost all clojure koans. Can I better do a lot of 4clojure to practice more with clojure or can I try to make a small web app with for example luminus ?
At this point @roelofw I'd recommend doing the 4clojure problems to practice more before you try tackling something like Luminus...
@seancorfield thanks
I was thinking about porting a ruby app to clojure with json reponses and maybe some sort of caching
If you want a simple web app "framework", take a look at FW/1 which is what we use at work https://github.com/framework-one/fw1-clj (it's a small, convention-based wrapper for Ring, Compojure, and Selmer).
@seancorfield so first the 4clojure problems and then luminus ?
@seancorfield looks nice, First I have to find out how boot can be installed. Till now I only have worked with leiningen
Boot is definitely worth learning.
Hmm, no idea. At work we switched from Leiningen to Boot about a year ago as we were finding Leiningen too limiting for the sort of build tasks we needed.
oke, I was thinking about a 2 page web app. where on the first page 10 paintings are seen and on the second page a detail page of a painting is seen
CIDER (and Emacs) has full support for Boot. I guess I'm a bit surprised other editors don't.
I gather Cursive is somewhat held back by needing to support Java 6 since that's what IntelliJ inflicts on it, at least on Mac?
Colin is pretty responsive and Cursive is an impressive piece of tech. I know he's frustrated by having to maintain that level of backward compatibility.
Still, if the only consideration is needing a project.clj
file, you could create a new FW/1 project via the template and then convert build.boot
to project.clj
and stay with that š
First trying to make the elementary and easy problems and then look for the web app . Sounds to me like a good plan
(but, yes, you would need the boot.sh
or boot
script installed -- it's easier to set up than Leiningen to be honest)
@seancorfield thanks a lot for sharing info and make your reccomendation
@roelofw I use Boot on Windows 10 (as well as Mac and Linux).
I'd forgotten it was a .exe file -- usage is pretty seamless across all three platforms.
Can you recommend a json library so I can parse the json response to a clojure object
Cheshire is the gold standard.
FW/1 uses Cheshire automatically (I should have included that with Ring, Compojure, and Selmer above).
@seancorfield thanks a lot for your time
@seancorfield there is no tutorial where a page is made with FW/1 ?
Hi, I am trying to create a macro to declare a dynamic var. I am losing the ^:dynamic information and and I donāt know why. Any ideas?
(defmacro declare-dyn [name]
`(declare ^:dynamic ~name))
(declare-dyn foo)
(binding [foo 42] foo)
CompilerException java.lang.IllegalStateException: Can't dynamically bind non-dynamic var: user/foo
@lboliveira try
(defmacro declare-dyn [name]
`(declare ~(vary-meta name assoc :dynamic true)))
@moxaj It worked! Thank you š
How should I go about making a spec for a joda time? (such as created with (clj-time.core/now)
)?
I guess... use satisfies?
and spec/with-gen
and build my own generator. But does one exist already?
@escherize you can use a large-integer* and use from-long: (fmap clj-time.coerce/from-long (large-integer* {:min start-epoch :max end-epoch}))
a minimal version would be (fmap clj-time.coerce/from-long large-integer)
, but you'll end up with some odd dates
Another option in 1.9 would be to extend the joda instant to the new Inst protocol. If you do that, then inst? will work and the s/inst-in spec will work
Date is covered this way and Java 8's Instant
Thanks @alexmiller (re: my post on aot last night), as soon as I walked away from my computer I figured I should just write it in java. Just curious, though, is the fact that all of the clojure dependencies of the aot namespace are compiled just an artifact of how lein chooses to handle it or is that an implicit requirement in how gen-class
works? Would it theoretically be possible to only compile the gen-class class?
That's how apt works
Does anyone know if Sublime Text or Atom can work with boot. So I can make a app with boot and do boot run without using a external terminal
Is there anything in Clojure resembling Akka and actors yet but more CSP-oriented (distributed, long-running graphs of CSP channels, heavy on queues, backpressure, etc.)? I am aware of Quasar and Pulsar, but at that point I would just use Akka for various reasons. I also know about and use Onyx, but it's not a fit for some of my use-cases. I currently have some form of scale-out via Kafka consumers/producers, but this is only a piece of a larger solution.
how would you convert a string value to a keyword in a nested JSON coming from a server? I'm trying to use clojure.spec, but I'm somewhat confused if I should use a custom conformer. In Prismatic's Schema coercion is kinda obvious, but is it an intended use for clojure.spec?
the general caveat is: be careful about your use of conformers, particularly in registered specs. You are making decisions for all future consumers of your specs and (like here) potentially throwing away information (there is no way to tell from the conformed value here whether you received a string or a keyword).
some boot expert here : when I do boot run I see this error message :
boot run
clojure.lang.ExceptionInfo: No such task (run)
data: {:file
"C:\\Users\\rwobb\\AppData\\Local\\Temp\\boot.user3125771616484661687.clj",
:line 7}
java.lang.IllegalArgumentException: No such task (run)
boot.core/construct-tasks core.clj: 905
...
clojure.core/apply core.clj: 630
boot.core/boot/fn core.clj: 949
clojure.core/binding-conveyor-fn/fn core.clj: 1916
...
My build.boot looks like this :
(def version "0.1.0-SNAPSHOT")
(task-options!
aot {:namespace #{'myfw1app.main}}
pom {:project 'myfw1app
:version version
:description "FIXME: write this!"}
jar {:main 'myfw1app.main
:file (str "myfw1app-" version "-standalone.jar")})
(set-env! :resource-paths #{"src" "resources"}
;; the org.clojure/clojure dependency here only affects
;; what is bundled in the uberjar via the build task so
;; be careful if it is different to the version you have
;; configured for Boot!
:dependencies '[[org.clojure/clojure "RELEASE"]
[framework-one "RELEASE"]
; comment this out if you don't want
; to use http-kit at all:
[http-kit "RELEASE"]])
(deftask build []
(comp (aot) (pom) (uber) (jar) (target :dir #{"target"})))
(deftask run
[p port PORT int "the port on which to run the application."
c config ARG=VAL {kw str} "the config map for the application."]
(require '[myfw1app.main :as app])
((resolve 'app/start) port config))
(defn- generate-lein-project-file!
[& {:keys [keep-project] :or {:keep-project true}}]
(let [pfile (io/file "project.clj")
pname (or (get-env :project) 'boot-project)
pvers (or (get-env :version) "0.1.0-SNAPSHOT")
prop #(when-let [x (get-env %2)] [%1 x])
head (list* 'defproject pname pvers
(concat
(prop :url :url)
(prop :license :license)
(prop :description :description)
alright, I've decided it's high time I learn how to use css. So my goal is to (1) use a css 'pocketbook' (2) work through all the tedious examples, and (3) do everything directly in clojure, instead of writing actual *.css file. On the cljs side, I'm using figwheel + devcards -- what clojure css library should I use to have everything work together nicely?
You could try garden - https://github.com/noprompt/garden
It allows you to write your tasks using clojure code instead of a DSL which is pretty cool. Task writing and composition is pretty easy with it.
is this one of those situations where "declarative is all nice and all that, but really doesn't match the problem domain" ?
worth pointing out though that you usually need to get to a pretty hefty level of complexity in your build process before lein falls down
as someone writing a forth based interpreter, clearly the solution is to embed a forth interpreter inside lein š
@seancorfield I have fw/1 with a standard template working
@alexmiller I see, thank you!
Iām having a misunderstanding about protocols and records when defining the entities for my system, and was hoping someone could clarify:
Suppose I have two entities A and B that share common traits such as - they have names, unique ids, and perhaps a āstatusā that might be some map such as {:last-known āā :current- āā}
. What I feel like doing (whether its idiomatic or not Iām sure) is defining a āstatusableā protocol, and having separate defrecord A and B that implement statusable.
But really that protocol isnāt much of a function, itās more like a flag demarking āhey I have this object representing a statusā.
Is there a better way to defrecord a field that is a map, or a field that points to a map?
but if they both use the same key for their status information you don't require the polymorphism
But also, don't shy away from maps. Using records is useful as a performance optimization or to implement existing protocols or Java Interfaces.
Okay, great .. thanks both @bfast @eraserhd. It seems Iām thinking about protocols on the wrong level where a map will just work. Do you have an example @eraserhd of a defrecord with a complex type as a field? I cant find one anywhere
Q: So, for like the fourth time recently, I've wanted something like defmulti/defmethod, except with multiple methods invoked for one multi invocation. I find it strange I've not heard of anyone doing this. Are there things?
@lwhorton Here's a thing from rewrite-clj
. "children" is a collection of other nodes. https://github.com/xsc/rewrite-clj/blob/master/src/rewrite_clj/node/forms.clj#L6
@eraserhd sounds sort of like observer pattern? I assume those methods are causing side-effects
In a previous case, I wanted to register transducers which could process things in any order.
mmmmm, I think the "deciding what to do with the results" bit fights against there being a general solution for that
I don't mind writing the dispatch/combining code, but how to write the registration?
Right now I kind of cheat and use a defmulti and manually call methods with (methods ...).
Which works, and I don't have to worry about implementation concerns about namespaces and loading, but it's kind of awkward to throw away the dispatch key and all.
I'm wondering about, for example, atoms or volatiles, or using a defrecord with fields, and what kind of things we have to worry about wrt concurrency at namespace load.
(def listeners {})
(defmacro defn-listener [name key args & body]
`(let [fn (defn ~name ~args ~@body)]
(alter-var-root #'listeners #(...))))
if you want to build this all up at compile time, and dispense with some boilerplate I think it seems reasonable. but I'm not going to make any claims to it being good practice ĀÆ\(ć)/ĀÆ
(fn [x] (if (vector? x) x (apply list x))) is there a builtin for this? "if a vector, in O(1) return itself; if a list, in O(n) create a vector"
@hwk Not sure how it behaves under the hood but might this work? http://clojuredocs.org/clojure.core/vec
@tom: here's the code: https://github.com/clojure/clojure/blob/clojure-1.8.0/src/clj/clojure/core.clj#L367 appears to operate as expcted
actually, any idea what triggers this line: https://github.com/clojure/clojure/blob/clojure-1.8.0/src/clj/clojure/core.clj#L376 ?
@roelofw: there's a mini address book example in the repo you can look at (FYI I'm on vacation thru Sunday so I may not be around to answer questions much)
Is there a more idiomatic way to implement this (sorta-cond) ? (defn pick-first [x lst] (loop [lst lst] (when (not-empty lst) (let [[k v] (first lst)] (if (k x) (v x) (recur (rest lst)))))))
https://www.youtube.com/watch?v=8wLwbpCxRf0 is an amazing talk