This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-10-14
Channels
- # aleph (14)
- # bangalore-clj (2)
- # beginners (39)
- # boot (18)
- # carry (7)
- # cider (37)
- # cljs-dev (1)
- # cljsrn (4)
- # clojure (74)
- # clojure-austin (12)
- # clojure-canada (6)
- # clojure-conj (15)
- # clojure-dev (3)
- # clojure-greece (14)
- # clojure-italy (1)
- # clojure-korea (1)
- # clojure-poland (3)
- # clojure-russia (5)
- # clojure-spec (22)
- # clojure-uk (13)
- # clojurebridge (9)
- # clojurescript (231)
- # cursive (2)
- # datascript (9)
- # datomic (12)
- # devcards (2)
- # emacs (2)
- # events (4)
- # hoplon (28)
- # off-topic (35)
- # om (61)
- # onyx (8)
- # parinfer (8)
- # proton (1)
- # re-frame (53)
- # reagent (10)
- # ring-swagger (8)
- # specter (11)
- # untangled (3)
- # vim (4)
Hi, I am using Clojure to process a time serial data file to find out all the lines whose minute(timestamp) is the same as the next line. What’s the idiomatic way to do that?With line-seq I need to kinda store the “state” (which is the current line), which seems to be bad.
(defn remove-dups [[head & tail]]
(cons head
(when (seq tail)
(lazy-seq (remove-dups (drop-while (partial = head) tail))))))
@hans is your code the answer to my question?
I am really new to clojure
@pythonruby Not directly, but almost - You'll have to replace the =
with your appropriate equality predicate
Thanks @hans , let me “digest” your code.
@pythonruby What is does is close over the last element returned (head) so that duplicates are removed before the next one is returned. That is achieved by lazy-seq
.
@abarylko that would remove the overall order and be less efficient because it would realize the whole sequence as map.
#pythonruby #hans code is likely better but I'll give you a my newbie suggestion: one standard idiom for processing a sequence "2 at a time" (e.g., to send to map) is: (partition 2 1 [:a 😛 :c :d :e]) => ((:a :b) (:b :c) (:c :d) (:d :e))
@herbm that seems neat. Thanks for the idea.
I have a situation where I'm issuing an http request that includes an asynchronous callback, but the callback is optional. In case the user doesn't provide a callback, I still have to provide a callback to the library I'm using to issue the http request. What is the most idiomatic way to say "function that does nothing"?
Here are some things I've considered, but I don't know which would seem most idiomatic:
identity
is normally the "function that does nothing"
What am I supposed to do if my repl is giving me an error Error Occured: java.lang.IllegalArgumentException: Key must be integer
but doesn't tell me what line it is, or any stack at all for that matter? :thinking_face:
Oh my... I figured it out. instead of returning a list I was returning [listname]
, so it made an array. Well then.
@pythonruby As it stands it is not, but it can be made lazy like my version.
@pythonruby Basically, it is doing the same thing without being lazy and also less efficient 🙂
@hans: yeah, I see
Hi. Has anybody ever had any problems with shutting down an embedded Jetty which was started with ring.adapter.jetty/start-jetty
? In my app, (.stop @jetty-server)
does not return for reasons I do not understand.
@ska: from repl or compiled jar?
about styling: if one defines a constant ^:const
, these values are supposed not to have a special styling. However, to me, it makes a lot of sense to know that these values are actually compiled into the resulting code. So, when clojure programmers use const
, do they use any special syntax (like, e.g. capitalized names)?
@pythonruby compiled JAR
Any chance it's called from "do"?
I don't understand, @pythonruby
I made a mistake before that I called my function from within the "do", which in compiled jar it's by default not realized.
The lazy part in "do" is not realized.
I had to use doall per the instruction from some pro from here.
Just FYI
Your case may be different
No, this is not the case here. I have a pretty straight forward fn in my main namespace which I'll post in a second. There, the call to .stop
never returns.
more likely the deref that never completes because you didn't start the server with :join? false
?
https://github.com/ring-clojure/ring/blob/master/ring-jetty-adapter/src/ring/adapter/jetty.clj#L120
Hm, interesting... I start the Jetty server last thing in my main with join? false
. In my generic Thread/setDefaultUncaughtExceptionHandler
I stop Jetty and everything else and want to restart it again. But now, the JVM exits, when I stop Jetty. Oh, and stopping Jetty works now. I had a swap!
on an atom that I had already deref
ed in the current scope. Not a good idea.
some issues and prs on clojures jira are pretty old. is it because there are not enough people to check that stuff?
hi.. i have heard that being a lazy language and on jvm, we add a lot of garbage.. for faster garbage collection
of intermediate collections we give some hints to GC in bytecode
.. Can i get some reference
to how it is done ? any help appreciated..
@pvinis The reasons for that vary widely so it's hard to say one reason. Most patches are not good enough to apply and require additional work. In general, a lot of stuff is also gated by Rich's available time and attention.
@ashishnegi: the compiler aggressively clears local references to make more objects available for GC
That is, creates bytecode that clears references - a lot of that is done via the Util.ret calls
One of the semi hidden hints is the ^:once hint which is leveraged in lazy-seqs for example
@alexmiller thanks for this useful information.. I looked in the code.. Is ^:once is being used here ?https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L5046
so for writing a simple web app like a Facebook bot, should I use compojure-api? what are people here using?
ring+jetty may be the most common substrate. If you need routing, bidi is pretty good.
Lots of people do like compojure-api. Myself, I dislike how it encourages routes to be expressed as vars.
@donaldball as vars? You can do mostly the same stuff as with compojure.
I really love bidi, because it's just data. Disclaimer: I work for JUXT, but I'd recommend it either way
data > functions > macros!
Hmm, I’m confused about a namespace issue. If i
(defprotocol IFoo (my-func [this])
(extend-type string IFoo (my-func [x] (do something x)))
(in namespace A).
From namespace B how do I invoke (my-func some-x)
? is it the protocol I need to require into namespace B? Or is it the symbol my-func
somehow?lwhorton, what happens when you try use it like it’s a normal function?
and if you alias the ns and call alias/my-func?
aha, that works! I suppose that means I don’t understand at all how protocols are binding vars to a namespace
I would’ve thought by extending a base type string
with my-func
I could just invoke that fn on any string willy-nilly, but it seems the compiler still needs to know where the original symbol is defined
my-func is a var in namespace A and you should invoke it and/or refer just like any other function
You do need to make sure you have loaded any namespace that extends the protocol prior to invoking a protocol function on an instance of that type too
Ya, that's what it is, since if I do: (str (* 2 (bigdec Double/MAX_VALUE))) I see the actual number
If you are using lein repl and you are working with a project with a project.clj file check this as a reference on which value could be affecting your repl https://github.com/technomancy/leiningen/blob/master/sample.project.clj