Tuesday, September 07, 2021

why clojure trips me up


this ^ is the documentation for Clojure's sort-by

however ,  you can also sort by the values in the  map, if you pass a map as input to the function.

this is given as an example further down


This throws me off.  What is val 
Apparently it's another function in the Clojure canon/pantheon
How would I know ? 
it's given in the example
How would I know to search in the documentation again ?
..... some familiarity is needed

The keyfn also  supports a whole lot of behaviour such as juxtaposing key1,key2 pairs, sorting by key , sorting by count and a whole lot of others which aren't really part of the documentation of the function itself.
You need to know the rest of the documentation to -get- these.
These seem par for the course, and are probably what fluent programmers would use. Except it's a recursive way to get there.

I came to see the function usage, like a dumb java developer, and got plonked with a short story on sort-by usage patterns. 
That's a learning curve too steep for someone who came expecting some constants or keywords to plugin to my function and get some documented behaviour variation. 

Problem is in Clojure, opening each blackbox is just as much effort as it is to turn a page, but then your mind has to load that function definition too,  and it becomes too much.

I am still struggling with the paradigm shift, ie, constants/keywords etc are just functions and vice versa.
Java typically does dispatch on constants or enum keywords - aka an if -else clause.
Clojure (and functional programs) use functions to decide dispatch..  a function is a constant and a  thing, as opposed to a machine's maw like I imagine in Java

I expect these complaints will disappear linearly with lines-of-code written, and I'll not be confused by seq anymore

Video notes:

Clojure is a data processing language.

The language mirrors the structure of data

(being a homoiconic language, it feels like the data is executable)

(Lisp is ListProcessing is the closest to a Turing machine )

(homoiconic - Freddie Mercury)

Can we do a whole web app with just clj-http, clj-sql etc ?


References:

https://clojuredocs.org/clojure.core/sort-by

https://www.youtube.com/watch?v=C-kF25fWTO8&t=1364s


0 Comments:

Post a Comment

<< Home