Fork me on GitHub
#beginners
<
2018-05-22
>
soulflyer00:05:08

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

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.

Vincent Cantin00:05:30

How about the content?

soulflyer00:05:01

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?

soulflyer00:05:34

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.

soulflyer00:05:48

Cool, good article :+1:

seancorfield01:05:06

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

Vincent Cantin01:05:26

Let's move the conversation in a thread.

seancorfield01:05:58

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.

seancorfield01:05:02

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.

Vincent Cantin01:05:20

Oh, that's true.

seancorfield01:05:56

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.

seancorfield01:05:22

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.

rahulr9205:05:23

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: #'clojure.tools.nrepl.transport/Transport found for class: clojure.tools.nrepl.middleware.load_file$wrap_load_file$fn$reify__668 Complete stack trace: https://pastebin.com/fafec0AV 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.

seancorfield06:05:07

@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).

rahulr9206:05:58

@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.

Yneth07:05:36

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

gklijs08:05:12

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.

manutter5112:05:16

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.

bertofer08:05:48

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!

schmee09:05:37

@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

bertofer09:05:52

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

bertofer09:05:01

Thanks @schmee

schmee11:05:03

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

mg12:05:58

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

mg12:05:34

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

bertofer12:05:33

Thanks, that was clarifying 🙂

SoV413:05:22

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" ?

SoV413:05:47

(I'm working on a challenge problem) 🙂

mg14:05:27

Could “compile” the input string to a regex

SoV414:05:18

@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")

mg14:05:20

you could also build a parser

SoV414:05:52

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

SoV414:05:30

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)

mg14:05:39

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

aengelberg14:05:56

Come over to #instaparse :)

mg14:05:29

the cavalry has arrived

aengelberg14:05:01

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

lxsli16:05:27

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")]])

lxsli16:05:19

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

lxsli12:05:24

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

lxsli12:05:45

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

dpsutton16:05:23

the answer is that project.clj is just code

admay16:05:09

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?

dpsutton21:05:51

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)]

dpsutton21:05:59

and want [0 0 1 0 1 2]

noisesmith21:05:46

or just use mapcat

dpsutton21:05:12

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

dpsutton21:05:27

cat is perfect. thanks!

noisesmith21:05:28

then cat is your animal

noisesmith21:05:21

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

alexmiller21:05:49

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

dpsutton21:05:05

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

dpsutton21:05:31

it's time for me to really dive into these

alexmiller21:05:53

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

alexmiller21:05:03

infinite range that is

alexmiller21:05:17

I guess these are finite as written

alexmiller21:05:28

but something to be aware of

dpsutton21:05:44

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

dpsutton21:05:08

(assuming there's one in programming clojure

alexmiller21:05:04

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

Philip Hale22:05:03

@dpsutton I worked through http://elbenshira.com/blog/understanding-transducers/ recently, found it helpful

johnj22:05:25

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

seancorfield23:05:52

@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?).