This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-30
Channels
- # bangalore-clj (1)
- # beginners (104)
- # boot (207)
- # cider (173)
- # cljs-dev (157)
- # cljsjs (1)
- # cljsrn (51)
- # clojure (196)
- # clojure-berlin (1)
- # clojure-chicago (1)
- # clojure-italy (4)
- # clojure-new-zealand (1)
- # clojure-nl (1)
- # clojure-russia (28)
- # clojure-spec (17)
- # clojure-uk (73)
- # clojured (13)
- # clojurescript (110)
- # core-async (4)
- # datascript (25)
- # datomic (92)
- # editors (1)
- # emacs (157)
- # events (4)
- # hoplon (16)
- # klipse (74)
- # lein-figwheel (10)
- # leiningen (2)
- # lumo (13)
- # off-topic (78)
- # om (3)
- # om-next (3)
- # onyx (14)
- # protorepl (1)
- # re-frame (17)
- # reagent (23)
- # remote-jobs (1)
- # ring-swagger (33)
- # schema (2)
- # slack-help (3)
- # spacemacs (7)
- # testing (1)
- # yada (7)
stupid question (quick search did’t get me anything) how to I access to all function arguments from within the function? Basically looking for an equivalent of arguments
object in javascript
@ag I think most likely reading this might help out : http://theburningmonk.com/2013/09/clojure-multi-arity-and-variadic-functions/
It's like doing argument destructuring in ES6, basically
Or this perhaps, http://clojure-doc.org/articles/language/functions.html#variadic-functions
@ag -- the vars are bound and without macros, you can't really do that. however, this may give you some direction: http://stackoverflow.com/questions/18797856/get-clojure-argument-list
Also there are no stupid questions ¯\(ツ)/¯
I have a question though. Functionally the following are the same, afaict, to get a value within a multi-level hashmap. Is either better, either idiomatically, functionally or performance-wise?
(-> msg :author :username)
(get-in msg [:author :username])
idiomatically, no. both are common.
functionally, I’d say basically no
boot.user=> (def m {:a {:b 34 :c {:d 42}}})
#'boot.user/m
boot.user=> (time (dotimes [_ 10000000] (-> m :a :c :d)))
"Elapsed time: 300.658938 msecs"
nil
boot.user=> (time (dotimes [_ 10000000] (get-in m [:a :c :d])))
"Elapsed time: 632.927241 msecs"
nil
I think there are two reasons for that - get-in
reduces over the keys, invoking get on each key where as ->
is compiled (via macroexpansion) into the direct series of lookups (:username (:author msg))
Thank you both for the thorough answer!
I shall be using ->
from now on ^_^
@eslachance I think they both have a place 🙂
and the second reason is that the ->
will use (:author msg)
vs (get msg :author)
which is ever so slightly faster
agreed - get-in
is great when you have some code that creates the lookup vector
Ah yes, doing it programmatically would need the vector
That's a good point
@ag you need a macro for this. when you call (my-func foo)
, foo
is evaluated before being given to the function. the answer here should show you how to do it, in case you want to go this route. http://stackoverflow.com/questions/41482431/return-concatenated-params-in-clojure/41490018#41490018
@beppu awesome, I was looking at the generated API: http://clj-time.github.io/clj-time/doc/index.html and it does not have that method. Its a bit of a pity. Anyway, thats what I need, thanks
how can i remove all keys from a nested map? i.e. i want to strip away all keys == :db/id. I was thinking about postwalk, but have problem with coming up with how to tell it to remove the keys...
user=> (def x {:foo 1 :bar 2 :baz {:foo 1 :bar {:foo 2}}})
#'user/x
user=> (w/postwalk (fn [x] (if (:foo x) (dissoc x :foo) x)) x)
{:bar 2, :baz {:bar {}}}
@moxaj Thank you very much!!
Watching @plexus's latest episode on defrecords (https://lambdaisland.com/episodes/defrecord_defprotocol), it struck me that I've seen reader literals for defrecords used only rarely - in fact I forgot about their existence.
I mean something like this (from the transcript)
#ep24defrecord.core.Book{:title "Iain M. Banks"
:author "Consider Phlebas"
:year 1987}
What are those reader literals useful for?
ah because the records are automatically printed as literals
so basically you can easily serialize those literals to EDN or transit?
as a side node this works in a Clojure repl but not in lumo
(do (defrecord Foo [name age]) (cljs.reader/read-string (pr-str (->Foo "Joe" 92))))
Error: Could not find tag parser for cljs.user.Foo in ("inst" "uuid" "queue" "js")
@anmonteiro's self-hosted clojurescript repl
so "type read literal" is the concept I was missing
if anyone's following along, here's the relevant section in the docs: https://clojure.org/reference/reader#_deftype_defrecord_and_constructor_calls_version_1_3_and_later
>>> Calls to Java class, deftype, and defrecord constructors can be called using their fully qualified class name preceded by # and followed by a vector
so this sounds as if this would work with regular Java classes too
#java.util.Date[0]
#inst "1970-01-01T00:00:00.000-00:00"
hmm... not seen the lambda island before.... is it worth it?
@pesterhazy it does, it's just that record use that as their default printer while other instances use #<Klass [email protected]>
#java.util.Random[]
#object[java.util.Random 0x73600add "[email protected]"]
so it's `#object[Klass hash "[email protected]"] ?
#object
can't be read though (No reader function for tag object)
what's readable as opposed to "can be read"?
if you define a tagged reader for object then supposedly you can make something useful out of it
ah I get the distinction
it's readable in the sense of potentiality, not an actuality
it's kinda cool what you can uncover
@theblackbox to your question, I can wholeheartedly recommend lambda island, I've been a subscriber from the beginning
I've subscribed since the beginning and it's some of the best information you can find, for beginners to intermediates (with some advanced stuff sprinkled in). Disclaimer: I'm a friend so potentially biased
cool, good to know... I'll have a look see
Speaking of which, can anyone recommend a great book on Java?
Java is a pretty big topic, what are you looking into
I'd love to learn about advanced topics
intermediate to advanced I guess
memory model, concurrency, performance, GC
This is pretty much the final word on concurrency (and memory to some extent): https://www.amazon.com/Java-Concurrency-Practice-Brian-Goetz/dp/0321349601
Also any Java books on here would probably be good: https://www.amazon.com/gp/richpub/listmania/fullview/R3LG3ZBZS4GCTH
@tbaldridge good stuff, thanks
"The Java™ Virtual Machine Specification" ... not sure if I'm prepared to go there yet...
pesterhazy I found this book extremely helpful in my early days of programming: https://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683/
@schmee looks good
got all of the above. Used books are so affordable 🙂
hello guys, I'm struggling to pick my way through the various concurrency methods in an attempt to debug my code. I believe I'm in a race condition whereby a process is kicking off before a doseq has finished initialising various stuff and things so I would like to block until I know initialisation is complete. Where should I be looking? Futures look most likely?
so I'm using Clojure to implement Kafka Streams using interOp =/
I have my "topology" built by one process and my thinking is that the error I am currently getting means that I am calling "start()" before the topology has been initialised
using "thread first"
sorry this is literally my first week with Clojure so I may not be using any of the words correctly 😉
@theblackbox Is it possible to post the relevant code portion?
so I'm trying to break out the "process" method so that I can throw as many predicates at it as I need and it should implement a stream for each
then it should start but I just get the error: "Exception in thread "StreamThread-1" java.lang.IllegalStateException: Consumer is not subscribed to any topics or assigned any partitions"
which is exactly what the process method should be doing
Got it. Admittedly, I'm not well versed in Kafka. But I'll take a look and see if anything is glaringly off.
cheers =D
from what i can tell, (doseq [predicate model/all] process)
.. is not doing what you think it should be doing.
more than likely
as in when I use a single predicate - it works
me too
so yeah, if it is implemented like that using the single predicate, it works as anticipated
(doseq [predicate model/all] process)
… evaluates to nothing useful. you’re not calling process
like you seem to want to do. try the above.
@joshjones that seems to get me further, cheers
@theblackbox might want to use the ..
macro instead of ->
sorry what's the advantage there? or is it rtfm?
cool, I'll look into it
From the doc: (.. System (getProperties) (get "os.name")) expands to: (. (. System (getProperties)) (get "os.name")) but is easier to write, read, and understand.
hello guys. can someone enlighten me how to implement pretty standard pattern “worker pool with bounded task queue” in clojure?
i’ve already got ztellman/manifold
in my project and it will be pretty cool if it will fit.
that's pretty much exactly what core.async was designed to do
Trying to figure out why a test is failing, looks like things are running in parallel when we don't want them to.
not sure
try adding println at the beginning and end of tests to see if your hypothesis is right 🙂
lein test doesn't run in parallel by default
I also suspect it's not lein test
but that doesn't mean that your code's not running in the background because one of your tests kicked off some background process by accident
which is really easy to do if the code your testing has a lot of future
or core.async
code in it
If anyone is interested, I am trying initialize an open source project that facilitates building campaigns for public office in a transparent and less costly manner. There are more details in the #political-canvas channel
howdy, I’m trying to get single-writer, multi-reader broadcast working in core.async; I tried using mult
and tap
, but that seems to turn the write side into a dropping buffer
don't think so, but the mult does't remember past values, so it's best to setup your taps/mult and then start putting in values
if you post some code, we can probably give you better advice
My writer code is almost literally (alt! [[ch value]] :sent (timeout to) :timeout)
, and right now the read side is (alt! ch ([v] v) (timeout to) :timeout)
what I was after is having multiple readers receive a value when sent, and to have the writer time out if no-one is reading
@csm pub/sub is basically mult/tap but with topics. So you can dispatch to only certain channels based on the "topic" of each message
here 🙂
Awesome. So here’s a problem I’m having. Running this:
(jdbc/query db [”SELECT my_table.* FROM my_table WHERE my_table.id = ?” id])
Results in:
[{:id “someid”}]
By default clojure.java.jdbc will “uniquefy” column names by appending “_N” to it, but I need to be able to prepend the table name to the column name
usually best not use *
at all
can't you use my_table.id AS my_table.id
?
then use another character and replace? 🙂
it's hard to advise without knowing the use case
this may be to do with the JDBC driver as well, not clojure.java.jdbc per se
@leov, yeah I don't see why not
Usage: (query db sql-params)
(query db sql-params opts)
Given a database connection and a vector containing SQL and optional parameters,
perform a simple database query. The options specify how to construct the result
set (and are also passed to prepare-statement as needed):
:as-arrays? - return the results as a set of arrays, default false.
:identifiers - applied to each column name in the result set, default lower-case
:qualifier - optionally provides the namespace qualifier for identifiers
:result-set-fn - applied to the entire result set, default doall / vec
if :as-arrays? true, :result-set-fn will default to vec
if :as-arrays? false, :result-set-fn will default to doall
:row-fn - applied to each row as the result set is constructed, default identity
The second argument is a vector containing a SQL string or PreparedStatement, followed
by any parameters it needs.
See also prepare-statement for additional options.
(jdbc/query db ["SELECT my_table.* FROM my_table WHERE my_table.id = ?" id])
is his example, so prepend the known table name?
I’m trying to write a function that takes any result set and transforms it into a normalized map structure in memory
I’m just surprised you can’t hook into the mapping of ResultSet
-> seq of maps translation the way I want to
indirectly, through the ResultSetMetaData https://docs.oracle.com/javase/7/docs/api/java/sql/ResultSetMetaData.html#getTableName(int)
but like @dpsutton said -- you already know the table name a priori
so you might as well use it
Hey all, so I have an array of objects, and they are a subset of the overall data, so I want to assign them their proper ids (shift by some offset). So, I assume the best way is to convert it into a map right? If so, I cannot seem to figure out how to convert an object from an array to a map.