This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-02
Channels
- # admin-announcements (3)
- # architecture (5)
- # beginners (10)
- # boot (223)
- # cider (13)
- # cljsjs (2)
- # cljsrn (50)
- # clojure (208)
- # clojure-austin (16)
- # clojure-belgium (1)
- # clojure-india (1)
- # clojure-poland (13)
- # clojure-russia (130)
- # clojure-spec (27)
- # clojure-uk (144)
- # clojurescript (135)
- # css (2)
- # cursive (10)
- # datavis (1)
- # datomic (29)
- # dirac (9)
- # funcool (2)
- # hoplon (41)
- # jobs (3)
- # leiningen (6)
- # om (37)
- # onyx (20)
- # pedestal (1)
- # planck (1)
- # proton (4)
- # re-frame (45)
- # reagent (17)
- # rethinkdb (16)
- # ring-swagger (19)
- # schema (5)
- # specter (93)
- # sql (16)
- # test-check (33)
- # untangled (7)
(extend-protocol ...) seems to be very type oriented. is there a way to transform, say a column holding binary data in a specific table to something else (similar to @javax.persistence.Convert for the JPA folks) or do I have realize the results first and then transform?
@kaosko: The java.jdbc
uses of extend-protocol
are intended for transforms at the type level, correct. To just "fix" a specific column, use :row-fn
and provide a function that knows how to manipulate the row — (fn [row] (assoc row :converted-col (expand-data (:binary-col row))))
(I assume you’re working with clojure.java.jdbc
?)
yeah, java.jdbc. ah perfect, thanks @seancorfield
@cpuntodanielcc: You're asking if you can build a Clojure app / library and release it under a different license than EPL? The answer is "yes".
You can't re-license the Clojure code itself.
(but if you're producing software you expect others to use, be aware that you might be making their lives more complicated by having to deal with two licenses instead of just one)
When using namespaced keywords, is a good practice to define a namespace whose only purpose is to contain them? (Which you then require under an alias, to keep keywords short?)
By “defining a namespace”, do you mean like (ns a-namespace)
?
If that is the case, then AFAIK the “namespace” in namespaced keywords are not the same, and are arbitrarily defined.
in other words, you don’t have to (ns)
.
No problem 🙂 It’s a namespace collision, so it’s an understandable confusion.
But I guess then there's no way to refer to it with an alias if I don't define it with ns
?
For instance, if I (require '[clojure.string :as str])
, ::str/foo
is a handy shortcut for :clojure.string/foo
)
I do this often for namespaced keywords, so much that I ended up using a 2 line function that does both (ns-as 'foo.bar.baz 'baz) (prn ::baz/bar) => :foo.bar.baz/bar (see for more here: https://github.com/mpenet/ring-spec/blob/master/src/clj/qbits/ring_spec.clj)
If anyone from JUXT hangs around here… the two Swagger-related links at https://yada.juxt.pro/hello.html are returning 500.
A question related to clojure.pprint
: Is there a way to pretty print a string?
Let’s say I have a string that contains an expression and I want to pretty print it.
My problem is is that clojure.pprint/pprint
receives an object.
I tried to to (pprint (read-string s))
.
But there are some weird cases (pprint (read-string “a\n123”)); returns “a”
.
Any idea?
Although looking at the footer, that might be out of date. I expect the latest is https://juxt.pro/yada/manual/index.html
@mpenet: it doesn’t work. Look at this:
my.user=> (with-out-str (pprint (zipmap (range 14) (range 14))))
"{0 0,\n 7 7,\n 1 1,\n 4 4,\n 13 13,\n 6 6,\n 3 3,\n 12 12,\n 2 2,\n 11 11,\n 9 9,\n 5 5,\n 10 10,\n 8 8}\n"
my.user=> (with-out-str (pprint (str (zipmap (range 14) (range 14)))))
"\"{0 0, 7 7, 1 1, 4 4, 13 13, 6 6, 3 3, 12 12, 2 2, 11 11, 9 9, 5 5, 10 10, 8 8}\"\n"
When pprint
receives a string, it returns it as is, without doing any pretty formatting
Yeah, because in the first call, I’m passing an object. While in the second call I’m passing a string.
I know. But I’m looking for a generic way to do it. And read-string
reads only the first line. So (read-string "a\n123”)
returns “a"
This is the whole point of my question: how to pretty print a string that contains an expression?
ex: (with-out-str (pprint (read-string (str "(" (zipmap (range 14) (range 14)) ")"))))
And then removing the first and the last character from the result. right?
what do u mean by "you can use the reader directly”?
read the code sexp by sexp and apply pprint every exp, but dont bother, unless you're dealing with large files
is there a function in the reader that can read sexp by sexp?
or do I have to write my own?
there's read if you want to work with streams, check the doc of c.c/read or it's equivalent in the edn namespace
Since there are yada fans in here… The docs at https://juxt.pro/yada/manual/intro.html state that you can add yada to Immutant. yada requires aleph/http, though. Is aleph the only supported server?
The yada project itself has a reference to clj-http on the dev dependencies, “to compare with aleph”, but it isn’t used. Also the “introducing yada” post from a couple of months ago (https://juxt.pro/blog/posts/yada-1.html) states only Netty is supported. Conflicting docs. 🙂
I seem to remember @malcolmsparks mentioning it currently only worked with aleph... but I could be wrong
It's aleph only, I have some undertow integration on a branch, hence Immutant support wpn't be far off
@malcolmsparks @rickmoynihan Thanks for confirming.
There's a dedicated #C0702A7SB channel fwiw
halgari says one should use aleph, cause it uses potemkin (https://www.reddit.com/r/Clojure/comments/4uvcp4/just_got_my_first_clojure_job_any_tips_for/d5tmf80)..I don't use aleph but use potemkin with great success. don't know how I should feel about that.
I'm not sure the reasoning was entirely solid either. Potemkin is a few workarounds. But it's far from the devil.
Potemkin is just a library, not sure how it managed to aggravate the Reddit commenter that much...
You are unlikely to see the effects of Potemkin whilst using Aleph, except for one thing: import-vars.
in the same vein there's the "don't use java wrappers just use interop.", depends on the wrapper/task imho
Sometimes it's nice to have had someone flesh out the java interaction for you, come up with some ideas about handling the state.
imagine having to deal with jackson manually to parse json -_- or deal with a mutability mess with most of db drivers out there
I guess usually it's because of interaction with poorly written wrappers which do not add anything useful (which in reality is probably the most of them)
> Use Kinesis + Kafka when possible. Off-load your work. Write re-playable code. (CQRSish) I found this suggestion interesting. Especially as I am currently exploring CQRS/ES as a design pattern. Is it a pattern that's prevailent in Clojure programs, that I haven't seen yet?
@dm3: Sounds like you have some experience in the costs of CQRS/ES. Is there anything you could share to dig deeper? I only really see people talking about the benefits.
Replayable code is common in ES systems. You can take the events list, and "replay" them, through the system, to build up the same postgres database state.
I don't have any great tips for CQRS/ES systems, except that it incurs a significant cost
(one advice from Greg Young is to only implement ES for the most important/crucial parts of your domain-model - not for the entire application)
@gnejs: I found that advice strange. As I think there's a lot of value in reinterpreting the entire history of your application to do analytical data later. But maybe that's just me.
I think the pre-planning required for DDD is well encouraged within the Clojure community. So that may be less of a problem (although, naming is always hard!)
@dominicm: I think there’s an important distinction between application and domain model there.
@gnejs: Hmm, I'm struggling to understand application model here. Could you point me at some information about the differentiation between the two things?
The DDD-book is a good reference… and youtube videos by Greg Young. Also I think Vaugh Vernon have written stuff about it. IMO the domain-model is something that is central to the business itself and not scoped to a particular usage == application.
It’s all about layers 🙂 Although with all the microservice hype the traditional “enterprisey layering” have gone out of style a but I guess 🙂
@gnejs: I'll have to get the book. And look into Vaugh, as I've only seen Greg realy. Could you give an example of model which might be considered application-level?
actually - I think Martin Fowlers book http://martinfowler.com/eaaCatalog/ describes the difference a bit.
I'll admit that I find microservices less useful. I'm still discovering other old ideas! 😛
since people are talking about event sourcing, I want to mention I’m working on some refactoring/restructuring of the rill event sourcing tooling @ https://github.com/rill-event-sourcing/wheel
I guess there might be more layers than those two.. but IMO the application model might be about how users are defined, authorization, page-navigation (and to some extent: persistence, caching etc - but a better word might be ‘infrastructure’). While domain model would be about the core business concepts (shipping, trading, salary concepts etc.).
needs a lot of documentation and experimentation yet. some demo code with tests is at https://github.com/rill-event-sourcing/wheel/blob/master/test/rill/wheel/registration_flow_example_test.clj
@joost-diepenmaat: looks interesting… adding to Pocket for later 🙂
@joost-diepenmaat: I'll defin- ^^ that's what I was saying
If you have any questions or remarks don’t hesitate to let me know. We are experimenting with it at the moment trying to get the “feel” of the library correct so that implementations using it read “nice”.
@gnejs: For the most part, that example about the split is exactly how I was thinking of modelling it. In that context, Greg's advice makes a LOT more sense to me.
oh and all of this is aimed at the write side of CQRS. it defines nothing about the read side (the assumption is you’re doing that on your own based on some process that’s listening to all events)
I did want to experiment with storing other events (http requests for example) too though, but purely for analytical information. So that could be considered part of the domain, albeit in a different sense. I was struggling to decide where the boundaries were.
imo, one of the cool things about ES is that the event-store-side only really need to contain checks for invariants. The actual “data model” can be darn thin. If an update contains 20 fields it’s only necessary to persist those fields that are relevant for maintaining the integrity of the model. All 20 fields is propagated to the read-side though.
@dominicm: isn’t that something that ppl are using Kafka http://et.al for? I.e. it doesn’t have to be modelled as an "Event Sourced Domain Aggregate”.
@gnejs: I don't think Kafka is suited to persistent storage of those events. And I didn't really want to do anything with the information straight away, just create a big pile events to do something with some day.
@dominicm: true - I don’t think Kafka is a long-term storage alternative either. But it can be used as an ‘ordered channel’ to pipe the events to a more suitable store?
@gnejs: Ah, I think I misunderstood your question. Yes then. My comment was more about the blur of boundaries when you start making your application part of your domain (as I guess you do in analytics)
it’s a different domain perhaps.. the best chapter in the DDD book is the one about bounded contexts 🙂
http://martinfowler.com/bliki/BoundedContext.html — the ‘analytics’ domain could be squeezed in there as an adjecent ‘bounded context’ perhaps?
I'm gonna have to get this book! I've largely ignored DDD so far. That's clearly a mistake.
If you want a lighter read that covers most of the concepts: https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&cad=rja&uact=8&ved=0ahUKEwi78L_D86LOAhXGjCwKHTu3DRsQFggsMAI&url=https%3A%2F%2Fddd-cqrs-base-project.googlecode.com%2Ffiles%2FDomainDrivenDesignQuicklyOnline.pdf&usg=AFQjCNHE-wgrUTW2ndjpifxH6DO6mkp2Sg&sig2=3t_eqMuQYBHC6_p_yyYucQ
I'm destructuring a map argument to a function. Is there a way to error out if a key is passed that is not present in :keys? E.g. I'd like to throw an exception in the following case, because otherwise :c
is silently ignored: (let [{:keys [a b]} {:a "a" :b "b" :c "c"}] [a b])
This one’s better: https://www.infoq.com/minibooks/domain-driven-design-quickly
@dominicm: gah - would be fun, but I need to leave work in a couple of minutes.. will join it though!
@gnejs: yeah thanks that looks interesting
does anyone know how to get a parse a clojure.instant into a clj-time object? basically java.util.Date -> org.joda.time.time.DateTime
the string representation of the inst isn't one of the formatters listed for clj-time (f/show-formatters)
so the two don't seem to have an easy interoperability
@dpsutton: check out clj-time.coerce/from-date
Does anyone know if some kind of sort order can be assumed for: (file-seq (http://clojure.java.io/file "/some/path”))
Thanks, that was what I expected, but wanted to ask before I started to implement sorting.
hello there.. writing a compojure api, how I do describe a schema for a vector of vectors?
(defschema ... :coordinates [[Integer Integer]] results in "[java.lang.Integer java.lang.Integer] is not a valid sequence schema"
[[Integer]]
should work
or if you mean a vector of pairs of integers, then [[(s/one :x Integer) (s/one :y Integer)]]
or something like that
thanks, but [[Integer]] results in "errors": "(not (map? \"\"))" (obviously I don't want a map)
that sounds like it's related to something else
[[(s/one :x Integer) (s/one :y Integer)]] results in No implementation of method: :spec of protocol: #'schema.core/Schema found for class: clojure.lang.Keyword
I probably have the args to s/one
backwards for that one
switching the order I get the same "errors": "(not (map? \"\"))", so I suppose that works but the problem may be elsewhere, thanks
how can I define a function that takes a function f
and varags fns
and returns a function of some arg val
which first calls (f val)
followed by each successive fn
from fns
? let’s just say I wanted to chain side effects after a call
(defn wrap
[f g] (fn [arg] (do (f arg) (g arg)))
[f g & fs] ( ??? ))
I guess just loop?I was kind of hoping to somehow use threading or wrap each fn in a subsequent closure but I guess that would accomplish the same thing
@dg: so if I have [f g & fns]
I’d want to return (apply comp (conj (conj fns g) f))
… ?
To compose the values (feeding the return of each into the next), then (apply comp f g fs)
yeah, apply should flatten it out and return a function, which you'd then execute with arg
Hello all, a silly question, is there any way to use reduce not lazy in this
(reduce #(assoc %1 (keyword (str %2)) 0) {} (take 31 (iterate inc 1)))
?The result is
{:14 0, :27 0, :31 0, :18 0, :12 0, :11 0, :24 0, :10 0, :21 0, :23 0, :13 0, :30 0, :4 0, :26 0, :16 0, :7 0, :1 0, :8 0, :22 0, :25 0, :9 0, :20 0, :17 0, :28 0, :19 0, :2 0, :5 0, :15 0, :3 0, :6 0, :29 0}
, not ordered@fabrao: reduce is already not lazy -- what's your problem with that result?
maps aren't ordered
depends on what you want; it won't be a map after sorting
and if you want it to be the same order as it was when it went in, then why not use map
instead of reduce
?
because the result is like this ({:1 0} {:2 0} ... {:31 0}) not {:1 0, :2 0 ... ;31 0}
the question is how you're going to use the result
do you really need it to be ordered AND to be a map, or do you just need one of those things?
(map #(hash-map (keyword (str %)) 0) (range 31)) -> ({:0 0} {:1 0} ...) not {:0 0, :1 0 ...}
@fabrao: if you really need a sorted map with integer keywords... you could do this:
(apply sorted-map-by
#(< (Integer/parseInt (name %)) (Integer/parseInt (name %2)))
(interleave (map (comp keyword str) (range 32)) (repeat 0)))
but why do you want the map to be sorted?are you going to look up keys in the map? or just iterate over the entries?
at 31 entries, maybe you might as well just use a vector of length 31? forget using a map
are you going to look up keys?
you also might consider not using keyword keys
if you change them to integers you could just use a vector
you could convert it just before passing it
@chbm: The ones I'm aware of are either based on ring or pedestal. Any specific things you are wondering about?
i used ring for basic ws stuff a couple of years ago but i remember reading about new frameworks, was wondering what was the preferred middleware - router stack for webservices now
Also Yada is pretty new, but has some neat ideas