braveandtrue 2018-12-19

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

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

I do need help with this, because I can't seem to find a way out of it. Even with your reduce tip.

The source for comp uses something called reduce1 when the arity of the function is 3 or more, and it also uses list*, which I believe is to "flatten" a list (but I've never used or studied flattening, only read people mentioning about it). You mean using reduce like that?

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

Ah yes, youโ€™re right!

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.

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

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

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

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

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

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 ๐Ÿ™‚

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

@cdimara has joined the channel