When would you use let vs an anonymous function?
could you write an example comparison?
No...
in Scheme, let expands to an anonymous function; they're equivalent for all intents and purposes
let is just easier to read and write
and i guess maybe faster in Clojure
Thank you π I was just reading about anonymous functions and couldn't figure out when it would be preferable to use them. But maybe I should have played with them a bit more first, seen if they really do react the same.
It's counter-intuitive, but not naming things is often the clearer and simpler approach. Names mean that the programmer trying to understand the code later has to meet all those people, so to speak. Also, naming things right is hard and every name is an opportunity to mis-name something, and therefore introduce confusion between the name and what it actually does. (Intermediate reading on this: https://en.wikipedia.org/wiki/Tacit_programming ) So most Clojurists find that if a function only gets used in one place, then it's better not to name it or its arguments (which means using the #(foo %) syntax for anonymous functions). Sometimes the middle ground has the most clarity: leave the function anonymous but name its arguments (which means using the (fn [bar] (...)) anonymous function syntax).
Thatβs really helpful, thank you!
Never preferable?
given the choice...yes, never
anonymous functions are useful for many more things than what let does
a typical example is...passing them to filter, remove, map...
Thank you!
you might find looking up Lambda Calculus interesting; it shows you that all that is needed for a programming language is a notion of anonymous functions, and a notion of function application. with just those two things, you can write programs that do anything (though naturally it would take a much longer time than in bigger languages with more stuff provided for you, like arithmetic and variables)
e.g. https://www.youtube.com/watch?v=eis11j_iGMs and https://codurance.com/2017/11/09/lambda-calculus-for-mortal-developers/
(it is the original mathematical system that lisps like Clojure are inspired by... as well as many other languages besides)
This is an area I really struggle with... I haven't done ANY maths since I was 16, and that was a long time ago. Calculus in general is something I can't imagine being able to get my head around just yet. Thank you for the video though - hopefully it will make it feel a little more accessible!
oh! don't worry, it's just called 'lambda calculus' - nothing to do with the other calculus (which i also struggle with) π
mathematicians love to use the same words for completely different things
That's helpful...!! π Thanks for the heads up, much appreciated.