braveandtrue

https://www.braveclojure.com/
felipebarros 2018-12-19T06:00:07.071500Z

Is it just me or asking the following at the fifth chapter is a bit too much? I definitely failed at that, and looking at the source for Clojure's comp, I believe (or want to believe) that I may not be alone there. > [..] try reimplementing Clojureโ€™s comp function so you can compose any number of functions.

felipebarros 2018-12-19T06:00:12.071700Z

๐Ÿ˜•

felipebarros 2018-12-19T06:02:21.072600Z

The return value being a function, the arguments being functions, the order of the arguments is inverse to first and rest, etc.

2018-12-19T07:18:05.075500Z

I just looked up my solution and realized I implemented it more like a pipe function where it goes from first to last. ๐Ÿ˜ž I know itโ€™s not covered by the book but you could reverse it with http://clojuredocs.org/clojure.core/butlast and http://clojuredocs.org/clojure.core/last

felipebarros 2018-12-20T01:54:18.081800Z

I'm curious to see your solution ๐Ÿ™‚ what is a pipe function? And its the first time I see butlast, thanks!

felipebarros 2018-12-20T01:55:32.082Z

I mean, I have used | and others in the shell, but in Clojure I'm not sure what you mean by it.

2018-12-20T02:28:58.087200Z

In functional programming a common alternative to comp is pipe where functions are applied top to bottom. Itโ€™s very much the same principle with the Unix pipe you mentioned. Hypothetically in Clojure it would be like (pipe :a :b) instead of (comp :b :a). However Clojure has thread macros which are way better.

๐Ÿ’ฏ 1
2018-12-20T02:32:00.088100Z

https://github.com/jayzawrotny/clojure-noob/blob/679955cbb11b689bba1f869ef500c5a3c8d8ec81/src/clojure_noob/chapter_5.clj#L188 itโ€™s incorrect but not terribly far off

๐Ÿ˜ฒ 1
felipebarros 2018-12-20T04:58:55.088500Z

Wow, how come I haven't thought of just evaluating one function at a time and building a result? Instead I just assumed I had to return a function that was composed of other functions like loop itself haha nice one ๐Ÿ™‚

felipebarros 2018-12-20T05:00:55.088700Z

And I never thought of thread macros as something similar to pipes... since English isn't my main language, I take a lot of time to associate different names to the same concept I guess. But yes, I've learned about Clojure's thread macros a while back and always end up using them. ๐Ÿ˜„

๐Ÿ‘ 1
2018-12-19T11:54:34.077400Z

Chapter 5 is definitely one of the steeper parts of the learning curve. Chapter 4 is about using functions to process data, which is fine, thatโ€™s what youโ€™d expect functions to do. But in Chapter 5 he starts talking about using functions to process functions, and thatโ€™s just weird ๐Ÿ˜›

๐Ÿ˜… 1
2018-12-19T11:57:20.078200Z

@anantpaatra I can help you with figuring out that bit if you want.

2018-12-19T12:18:50.079600Z

@jayzawrotny There is a way to implement my-comp using recursion, that will naturally give you the last-to-first order without reverse. ๐Ÿ˜‰

2018-12-19T15:00:15.080100Z

Ah yes, youโ€™re right!