This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-02-29
Channels
- # admin-announcements (6)
- # announcements (1)
- # beginners (1)
- # boot (104)
- # braid-chat (5)
- # cbus (1)
- # cider (2)
- # clojure (147)
- # clojure-japan (1)
- # clojure-poland (1)
- # clojure-russia (31)
- # clojurescript (16)
- # core-async (4)
- # css (2)
- # cursive (14)
- # datomic (40)
- # devcards (5)
- # dirac (100)
- # emacs (5)
- # funcool (1)
- # immutant (52)
- # juxt (4)
- # ldnclj (128)
- # lein-figwheel (12)
- # leiningen (26)
- # luminus (3)
- # mount (22)
- # off-topic (11)
- # om (144)
- # onyx (2)
- # parinfer (1)
- # proton (7)
- # re-frame (55)
- # reagent (16)
- # slack-help (5)
- # yada (1)
During the previous Conj, @cfleming gave a talk about using grammars to improve error messages. At one point he mentions that there's a way to use his (install-goodness)
stuff from regular clojure code, (rather than using the wonderful Cursive IDE) but I can't find a library for it
http://fulldisclojure.blogspot.com/2009/12/how-to-write-clojure-reader-macro.html but read disclaimer carefully
@escherize: There are tagged literals: http://clojure.org/reference/reader#_tagged_literals
hi guys I have something like this #{:c :b :d :a}
and this map [{:type :c} {:type :d} {:type :b}]
. How do I sort the second map with the custom order in the first set. The result should be [{:type :c} {:type :b} {:type :d}]
Would this be a good solution (having a vec instead of a set for the order)? (sort-by #(.indexOf order (:type %)) mymap)
@doddenino: good one, that will do. thanks 😄
I have a solution in mind to add weight to the map and sort on those, but it would be a bit clumsy
@escherize: I’m planning to OSS that lib but haven’t done so yet, I’ve been pretty swamped after releasing Cursive
Has anyone seen this issue before? the date above should be parsed as 1st Apr... but the clojure REPL seems to be printing it in a different locale/timezone ↗️
If I use the same SimpleDateFormat to print it then it works as expected - I just don't know quite what the REPL is doing
It's probably being parsed in your local timezone. Hence the reason the SimpleDateFormat will print it in the right timezone.
I don't think its the parsing - I think it's clojure's printing that might be wrong
ok...
which looks correct for me
user=> (.parse (java.text.SimpleDateFormat. "yyyy MMM") "2012 Apr")
#inst "2012-03-31T23:00:00.000-00:00"
user=> (.parse (java.text.SimpleDateFormat. "yyyy MMM zzz") "2012 Apr GMT")
#inst "2012-04-01T00:00:00.000-00:00"
ok thanks... (.parse (doto (java.text.SimpleDateFormat. "yyyy MMM") (.setTimeZone (java.util.TimeZone/getTimeZone "GMT"))) "2012 Apr")
Hi folks, hoping for a bit of advice - I'm adding some schema validation to the system library, (eg. validate parameters when you create a new component) and I think it'd be an idea to validate by default but allow the client to turn it off.
I'm using https://github.com/plumatic/schema and it supports controlling validation with the (with-fn-validation) form and ^:always-validate metadata but it doesn't look like there's a straightforward way to have validation on by default for a function but let the client opt to disable it... am I missing something or misthinking the problem?
@brabster - there's some 'hidden' documentation here regarding when validation is on/off: https://github.com/plumatic/schema/blob/master/src/clj/schema/macros.clj#L180
I was writing a test for a function generated by a macro and, before I remembered fn?
I tried using resolve
. From the REPL it worked but from the test it didn’t (where fn?
worked as expected). Is there something odd about resolve… it seemed straightforward from the docs
(e.g. (expect (resolve ‘position-cmp))
failed where (expect (fn? position-cmp))
succeeded
@sandbags: resolve does not work on locals
not that I know this is your problem, but it's a potential issue here
@sandbags: let and fn and loop create locals - bindings only visible inside their block
resolve only works on vars that are interned in namespaces
okay i wanted to be clear since this isn’t in the context of a let or fn, but a defn
well defn is just fn inside def, do you mean in the context as in inside the body using a binding created inside that body?
you can use let in a repl
(let [x 1] (resolve 'x)) - you will not find x
@sandbags: never mind then, you have a separate problem
sorry for the miscommunication
I was pointing out a common pitfall in resolve / eval (that they don't see locals)
not assuming that was your problem yet, but mentioning just in case
anyway, back to resolve, if called at a time when the var exists, it should see the var and return it
yeah, which it does at the REPL but not from the test… i mean, fn? works and is actually what i want so it’s no bother… just puzzling
an alternate test would be to look up the symbol as a key in (ns-interns 'this-ns)
replacing this-ns with your actual ns symbol of course
clojure's ability to introspect on namespaces is actually quite extensive and pretty straightforward to use (once you understand the structure of namespaces at least)
hmmm… anyone know how to get lein install (with :aot :all) to not include *.clj source files in the artifact?
hi there, I'm getting started with compojure but I can't find info about how to start a repl with leinigen, any idea?
hey @cpmcdaniel: see the :omit-source option in the leiningen sample project: https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L385
@spacepluk lein repl should do it
you don't need to run your app to get a repl
if you run lein repl, it's equivalent to getting dropped into your app before startup
if you want to be able to repl into your app after it has been deployed, that takes a different approach
You can start a repl with lein repl
, and if there's a main function which starts your server, you can run that from the repl.
yeah. do you know about workflows like Stuart Sierra's reloaded? http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded
sure- techniques like that using tools like Component https://github.com/stuartsierra/component or System https://github.com/danielsz/system or Mount https://github.com/tolitius/mount can help streamline the incremental development process
I saw that if I run lein ring server-headless
it starts the server and it reloads the files automatically but I'd still like to have a repl to inspect the state
I know in general you shouldn't have state but this is a very simple "script" I'm hacking together to solve a problem temporarily
sure. so with lein ring server-headless, you can give that an :nrepl parameter which will open a port allowing you to repl into the running server
to do that, run lein ring server-headless in one terminal, and use lein repl :connect xxxx to open a repl into the server in another terminal
when you just run lein repl without the :connect option, it handles the machinery of running an instance of your application, with an nrepl port open, behind the scenes
heh, choices, choices. lots of them in the clojure world.
"system" is built upon "component"
@stuartsierra good to know, thanks
Question: Is setting a transient vector value as fast as setting an array value in java? (I need fast datastructures for chess programming) or just fast enough?
on average, it is not as fast
it also depends what you mean by "setting"
"setting" implies to me not expanding the data structure but changing a value at an existing position (for example via assoc
or assoc!
), so I'm assuming that's your intent
i mean change. But any alternative if I dont want to leave clojure emtirely (for C++ or D)?
use java arrays - they work fine for stuff like this
see aset, aget, to-array, etc
depending what you want to store in them (primitives vs objects) there are more things to know as well
if you're storing primitives, some extra care is needed to avoid accidentally boxing the primitives when you work on them
http://clojure.org/reference/java_interop#primitives and http://clojure.org/reference/java_interop#optimization are useful starting points
I recommend buying 10-15 at a time
they are a handsome addition to any home library
Is there a simple way to rename a Java interface method when reifying, i.e. no external library needed? Example: someJavaMethod -> some-java-method I seem to remember something but can't find the old code where I did it. I might have just written something myself with a macro, but it's been awhile.
@stuartsierra: Thanks. I'll try to find whatever I did in my old code if I really need it. no big deal, just someone was asking for a fix on the names in a particular API and I didn't think it was worth the time
Don't fear the Java
no fear, I've been developing on it since the days I had a spark and an sgi machine on my desk, just a user/consumer of an api with a feature request
http://stable.melpa.org down for any Emacs users? (package-refresh-contents)
(remove #{1 2 3} #{1 2 4 5})
gives (4 5)
. I don’t understand how. is the set being used as a predicate or this is accidental?
this is interesting. never seen a set constructor used like this in another language. thanks
so for a set, it returns the element it finds. for a map, it returns the value for the key. for a vector, it indexes into the vector.
is there a good writeup somewhere about how lists are so fundamental to other Lisps but not Clojure (i.e. the reasons pro and con in the respective languages)?
@echristopherson: Data structures are fundamental to Clojure. Not exactly 100% what you are asking, but for some arguments both ways, see some discussion here: https://www.reddit.com/r/Clojure/comments/195349/why_are_clojure_function_arguments_vectors_rather/ https://www.reddit.com/r/Clojure/comments/195349/why_are_clojure_function_arguments_vectors_rather/c8l9fbc
You might be interested in https://jafingerhut.github.io/clojure-info/clojure-for-lispers-transcript.txt "Clojure has more first class data structures"
can anyone help me figure out how to list dependencies in my project.clj that aren’t provided when another project requires this one?
the gist is I have a project I want to use in two different ways — as a library, and as a standalone program. when required as a lib it doesn’t need some of the (big) deps that it needs when run as a program.