Fork me on GitHub

@vincent.cantin A link at the end of each part pointing to the next part would be helpful.

👍 4
Vincent Cantin00:05:01

You are right. I am also thinking about adding a TOC with a link to all the parts at the beginning of each part.

👍 4
Vincent Cantin00:05:30

How about the content?


I found the jump from stateless to stateful a little confusing. It's not clear why there is an extra layer there. A fn returning a fn is easy to understand, but why do we then go to a fn returning a fn that returns a fn? I don't need an answer here, just commenting that I found that bit confusing and it might be worth clarifying.

Vincent Cantin00:05:16

Ok. I will do more thinking tonight from home and maybe add something to explain more.

Vincent Cantin00:05:40

Thank you for your feedback 🙂

Vincent Cantin12:05:39

I made some adjustments so that the transducers are always presented the same way.

Vincent Cantin12:05:53

Does it feel better now?


And the pic in part 1 is a pretty good demonstration but it's not obvious unless you know the game. Maybe it would work better as a gif?

Vincent Cantin00:05:39

Good suggestion. I will add that tonight.

Vincent Cantin00:05:50

I made the change you mentioned about the link at the end.


Cool, good article 👍


@vincent.cantin Great article! A question and a suggestion...

Vincent Cantin01:05:26

Let's move the conversation in a thread.


In part 5, you test reduced? and then call deref on the value -- which may be confusing since you only talked about unreduced in part 4 without explaining that a reduced value can be deref'd. Not sure whether it's better to use unreduced in part 5 or explain exactly what unreduced does in part 4.

Vincent Cantin01:05:42

You are right. I probably rushed too much toward the end without explaining. I will add more info there.


In part 4, you mention ensure-reduced but because you give the source, readers might assume they need to type that in. Might be better to either just describe what the function does or make it clear that you are showing the source of a built-in function.

😲 4
Vincent Cantin01:05:20

Oh, that's true.


So, that was actually two suggestions 🙂 Here's the question: did you actually find a use case -- or even any reasonable documentation -- for the 0-arity transducer?

Vincent Cantin01:05:49

I opened a stackoverflow question about that. I should link it in the post for people who wonder.


Cool. I'll have to go and "follow" that since I've never seen a good explanation for it...

Vincent Cantin16:05:43

I made the changes in the blog.


Not sure if this is the right forum to raise nREPL issues. I am getting the following error while trying to load a buffer to my (remote) REPL: Exception in thread "nREPL-worker-0" java.lang.IllegalArgumentException: No implementation of method: :send of protocol: #' found for class:$wrap_load_file$fn$reify__668 Complete stack trace: My profiles.clj:

{:repl {:plugins [[cider/cider-nrepl "0.17.0-SNAPSHOT"]
                    [refactor-nrepl "2.4.0-SNAPSHOT"]]
          :dependencies [[org.clojure/tools.nrepl "0.2.12"]]
Effectively none of my required namespaces are getting loaded. Any help/pointers would be helpful. TIA.


@rahulr92 Well there are #nrepl and #cider channels that might be better placed to help you with something this specific. It sounds like a version mismatch between your client (in Emacs?) and your server dependencies... As I recall, cider-jack-in has been adding dependencies automatically for a while so specifying them in a :repl profile doesn't sound necessary... but, on the other hand, I stopped using Emacs/CIDER a year or two ago so I'm no authority (I switched to Atom/ProtoREPL).


@seancorfield Thanks. I am using cider-connect to connect to a remote REPL from my local Emacs (Spacemacs). The profiles.clj mentioned is of the remote host where I am running a headless lein repl. I will try reaching out to the channels mentioned.


Would it be hard to learn clojure for java dev who can write in haskell or scala?


In general the more languages you know, the easier it's to learn a new one. It probably takes some time to get used to lisp, and to get most out of it being a dynamic language. Having worked, and still working with Java, I still not make optimal use of the repl.


A big part of the learning curve for Clojure is understanding basic functional programming concepts, so if you’ve already got that via haskell/scala then you’re ahead of the curve.


Hi, I am new to clojure. I have some information I want to store in a map, but the “unique identifiers” of that information is composed of different fields, so what would be a way ti generate a key for this map? join the different fields together in a string or keyword? having nested maps? Any other solution? Assuming that having maps as keys might not be a good idea! Thanks!


@bertofer having maps as keys is perfectly fine in Clojure since they are immutable. As long as you don’t store mutable Java objects as keys or values it is the preferred approach


oh, nice. In that case, it is fine too to have maps as topic in pub/sub core.async or dispatch value in multimethods?


yes, in Clojure maps are values, just like ints or Strings in Java 🙂


@bertofer maps are ok for that kind of thing; vectors too


Vectors might be preferable as dispatch values for design reasons - it's often the nature of maps to get more keys added to them, and if you ever forget a select-keys then it won't dispatch correctly. You can build a vector from map inputs in your multimethod dispatch function with juxt


Thanks, that was clarifying 🙂


Using Clojure, If someone gave you a string like ( "peaches" & "creme") | "oatmeal" that is, logical AND "peaches", "creme", logical OR "oatmeal" how would you go about testing it against a string like "blueberry oatmeal" or "tasty peaches and creme" ?


(I'm working on a challenge problem) 🙂


Could “compile” the input string to a regex


@michael.gaare right? i am looking at using Lucene for the search indexing part, but i'm also thinking I can roll my own finite state machine. it's all very cool & groovy, starting out it's tricky since i feel like i have no grip at all on how to make an FSM i could "walk" against query expressions like: "how do you like them " & ("apples" | "limes")


you could also build a parser


okay i have a question about that because i was looking at instaparse and ...


deriving a syntax tree from a query expression is pretty straightforward once i say "hey you can be delimited by a pipe | or an ampersand & etc" ... that is, specifying the grammar in instaparse, but i'm not sure how i can use a new syntax tree to test against stuff in the db. i'm stuck on the bit where you can "eval" a syntax tree like: ("beaver" & "hugs") against the stuff in the db, say we have a db containing: "beaver hugs squirrel" ... getting a syntax tree is great and i know i can use (insta/transform transform-mappings ...) to replace symbols and then evaluate the expression... (there are some examples where they replace all the symbols that read ":add" with plus signs, and then this sums up all the numbers...) How would i test my new parsed-out logic-expression (such as 'beavers' & 'hugs') on an arbitrary input string / db entity? (i think i need to see more instaparse examples using transform)


I would probably try to turn the parse tree into a regex, for this particular case


Come over to #instaparse :)


the cavalry has arrived


It helps when you have "instaparse" as a highlight word in slack


Noob lein question please, how can I choose the version of a dependency dynamically? EG

(defproject abc/bar (System/getenv "VERSION")
    :dependencies [[abc/foo (System/getenv "VERSION")]])


it looks like the defproject macro doesn't evaluate that position


yeah tried that, works in that position but not in :dependencies 😛


ah well got it now - needed to unquote (~)


the answer is that project.clj is just code


Hey everyone, I’m working on a project in cljs using the New Relic node module. It’s a bit of a tricky module though because it must be loaded first. I have it as the first node/require in my code but I continue to get errors saying, “New Relic must be loaded first.” Anyone know how I can go about forcing this module to load before anything else?


not up to snuff on my transducers. is there some transducer i can use after the map range here to concat the results? or is it best done outside the transduction ? (into [] (comp (map #(range %))) (range 1 4)) ;=> [(0) (0 1) (0 1 2)]


and want [0 0 1 0 1 2]


or just use mapcat


yeah i need an index in the real thing so i was hoping i could map-index and then cat without mapcatting over the values bundles with range


cat is perfect. thanks!


then cat is your animal


also of course #(range %) could be range in the example (not relevant to the question or your actual code of course)

👍 4
Alex Miller (Clojure team)21:05:49

note that cat is a transducer, not a function that returns one (like map, etc)


yeah just quickly created an "essence" and was thinking it would make some infinite ones ha


it's time for me to really dive into these

Alex Miller (Clojure team)21:05:53

you can’t use range in a transducer map btw - transducers realize intermediate steps fully

Alex Miller (Clojure team)21:05:17

I guess these are finite as written

Alex Miller (Clojure team)21:05:28

but something to be aware of


thanks alex. i'm gonna read your chapter on them tonight during the basketball game

🏀 4

(assuming there's one in programming clojure

Alex Miller (Clojure team)21:05:04

not really - just a short intro there. but more in Clojure Applied


does someone has a sense of what are the most used clojure wrappers?


@lockdown- The most used Clojure wrappers for what? Or just in general? (The latter is probably too broad a question to get a sensible answer?).