Fork me on GitHub
#beginners
<
2017-07-22
>
sundarj00:07:30

@gdeer81 could you elucidate further?

gdeer8100:07:01

creating an example right now

sundarj00:07:30

ah, thanks!

sundarj00:07:27

is there a way to do it without a conditional?

gdeer8100:07:39

I'm sure of it, one moment please

sundarj00:07:57

no rush 🙂

gdeer8101:07:08

@sundarj I updated the same gist

sundarj01:07:25

ah, multimethods, of course - very nice 😄

sundarj01:07:11

that's satisfying. thank you muchly :~)

gdeer8101:07:31

That's what we call thirst quenching code. Clojure, it's what editors crave

sundarj01:07:23

left a comment on your gist 🙂

schmee06:07:49

@sundarj with Specter:

user=> (def numbers (s/walker number?))
#'user/numbers
user=> (s/transform numbers inc [1 2 3])
[2 3 4]
user=> (s/transform numbers inc [[1 2] [3 4 5]])
[[2 3] [4 5 6]]
user=> (s/transform numbers inc [[1 2] [3 4 5] 6 [7]])
[[2 3] [4 5 6] 7 [8]]

sundarj23:07:14

i've been expecting you 😛

sundarj23:07:44

rather nice, thanks! i must admit i have my misgivings about Specter though

schmee00:07:02

haha! 😄

schmee00:07:09

re: misgivings: how so?

sundarj15:07:38

code like this (transform [MAP-VALS ALL MAP-VALS even?] inc data) or (setval [:a END] [4 5] data) seems to basically be a DSL rather than a simple function

sundarj15:07:22

seems to be something you'd need to treat separately to the rest of your code

sundarj15:07:51

if i wanted to use it first-class, and compose it with other functions and such, i think i'd need to write wrappers around Specter's stuff to hide the DSL

sundarj15:07:23

hopefully i'm wrong about this

schmee16:07:33

the capital letters stuff is called navigators, and it’s a completely open system and it’s easy to implement your own

schmee16:07:35

do you have a concrete example of where you want to use it first-class where it doesn’t work for you?

schmee16:07:46

that would be easier to discuss around 🙂

sundarj16:07:44

sorry, no concrete example, just an ignorant first impression 😛 good to know it's an open system, maybe i'll give it a try 🙂

schmee16:07:13

haha, you’re not alone! 😄

schmee16:07:14

for some reason the CAPITAL LETTERS freak people out, but I urge you to give it a shot!

schmee16:07:29

and to take a look at the examples in the readme to see when and how to use it

sundarj16:07:23

it's just the fact you have to buy into Specter-specific knowledge, unless Navigators can be used outside of Specter?

sundarj16:07:07

if that is true, then they should probably be two separate libraries imo

schmee16:07:48

AFAIK they can only be used in Specter, at least at the moment

schmee16:07:03

as for Specter-specfic knowledge, that is certainly true, as with every library/dependency you have to evaluate whether the increased complexity is worth the added benefit 🙂

schmee16:07:35

given how much easier a certain class of problems become with Specter, for me it is worth it most of the time

schmee16:07:58

but if I only use it in a few places, I might replace it with core clojure just to have less stuff

sundarj16:07:40

for me, i care vastly more about simplicity than ease. Specter seems to ask for a lot more upfront compared to, say, Hiccup or Garden

sundarj16:07:35

but if it is worth the cost as you say, then i should definitely give it a try

schmee16:07:15

agreed, it’s always best to see for yourself! 🙂

sundarj16:07:03

thanks for putting up with my silly questions 😅

ažyliuk09:07:30

Hi, folks, I try to run migrations on the server, I need to run function forest-community-blog.db/migrate but on server I have only server.jar which I start by running java -jar server.jar, is it possible somehow run function which is not main from the jar file? 🙂

ažyliuk09:07:28

On local env I run migrations through lein run -m forest-community-blog.db/migrate

ažyliuk09:07:55

I should install lein and upload sources for accomplishing this task? 🙂

curlyfry12:07:02

@crashtown I'd probably modify main to either run migrations automatically on run, or let it run the migration function when a certain command line flag is given

noisesmith12:07:01

@crashtown java -cp server.jar clojure.main forest-community.blog.db

noisesmith12:07:25

the key here is that forest-community.blog.db must have a -main function - but I'm sure you could arrange that

ažyliuk12:07:24

And I guess i should use :gen-class option for this module? 🙂

noisesmith12:07:34

clojure.main is sufficient

noisesmith12:07:40

avoid gen-class whenever possible

ažyliuk12:07:50

Ok, thank you very much 🙂

noisesmith12:07:13

also if you skip the last arg you get a bare bones repl where you can require any of your namespaces that are in the jar

ažyliuk12:07:02

Nice hint, ty 🙂

dpsutton14:07:44

@rorysmith reduce takes a function, a collection, and optionally a starting value

dpsutton14:07:23

so reduce will keep calling your function with values from a collection and passing the resulting value into the function you are reducing with

dpsutton14:07:25

so (reduce str ["a" "b" "c"]) will not see an initial value and it will use the first value of your collection, "a". So this will start the reduction with "a". And reduce will call your function, here str, with the value that's been accumulated and the next value of the coll

dpsutton14:07:57

so this will call (str "a" "b") which is the initial value of the collection and then the next value of the collection. This yields "ab" as str will just concatenate

dpsutton14:07:32

and then reduce passes this accumulated value to your function str along with the next value in the collection, "c"

dpsutton14:07:44

so it will call (str "ab" "c")

rorysmith14:07:53

it's the concatenation that got me

rorysmith14:07:14

but i remember that passing in multiple args to str will yield a concatenation

dpsutton14:07:18

i never know what level understanding there is so i didn't mean to explain things you already knew

rorysmith14:07:30

yeah that was really useful, thanks

dpsutton14:07:35

no problemo!

dpsutton14:07:42

have you used str with lazy seq's yet though?

dpsutton14:07:52

that's kinda a gotcha with it

rorysmith14:07:04

no, what is a lazy seq?

dpsutton14:07:42

clojure has some lazy datastructures, meaning it tries to only perform computatoins that you actually consume

rorysmith14:07:11

can you give an example?

dpsutton14:07:13

(range) returns an infinite list of the non-negative integers, which is obviously impossible without some kind of bound

dpsutton14:07:28

(map inc (range)) then would return (1 2 3 .....)

dpsutton14:07:55

and if you call str on one of these you'll get its string representation, which is something like #lazysez[] or something

dpsutton14:07:03

its usually a gotcha at the beginning. wanted to point it out to you

dpsutton14:07:46

for sure. happy coding!

rorysmith14:07:44

thanks, i'm going through some exercises on codewars and very much enjoying functional programming

noisesmith14:07:05

@rorysmith a nice aid to understanding reduce is another function called reductions - which is just like reduce except it returns a lazy sequence of every result (and the last one will be the same one reduce would return)

noisesmith14:07:34

(I would have used your example with the bot, but the bot breaks when you give it strings sadly)

dpsutton14:07:03

didn't know that. awesome

hmaurer15:07:35

@noisesmith @rorysmith I personally like the fold name sometimes used in place of reduce. It’s very visual

noisesmith15:07:23

also the name "reduce" implies you can't use it to create outputs with larger or more complex structures than the inputs, which tends to make people less likely to realize when it's useful

hmaurer15:07:59

Yeah. I am not sure about the reasons why some people prefer the word “reduce”, I am sure there are some very valid ones, but for a beginner “fold” is more visual imo

hmaurer15:07:10

and conveys the intent better

hmaurer15:07:13

as you said

noisesmith15:07:18

it's one of the "historical reasons" things - making clojure more like lisp

swizzard23:07:20

i’ve got a lein project; i’ve written some tests in test/mover.clj, but lein can’t find them

dominicm23:07:27

Do you have :test-paths set in project.clj @U090G4C05 ?

swizzard23:07:42

i tried lein test test.mover

swizzard23:07:20

do i need to put something in my project.clj?