programming-beginners

2018-03-11T23:47:22.000154Z

When would you use let vs an anonymous function?

joelsanchez 2018-03-11T23:47:47.000095Z

could you write an example comparison?

2018-03-11T23:48:55.000070Z

No...

sundarj 2018-03-11T23:49:22.000142Z

in Scheme, let expands to an anonymous function; they're equivalent for all intents and purposes

sundarj 2018-03-11T23:49:36.000084Z

let is just easier to read and write

sundarj 2018-03-11T23:49:58.000062Z

and i guess maybe faster in Clojure

2018-03-11T23:50:50.000092Z

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.

daveliepmann 2018-03-12T07:50:46.000200Z

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).

2018-03-12T09:37:43.000064Z

That’s really helpful, thank you!

1
2018-03-11T23:52:28.000087Z

Never preferable?

joelsanchez 2018-03-11T23:52:50.000109Z

given the choice...yes, never anonymous functions are useful for many more things than what let does

joelsanchez 2018-03-11T23:53:50.000054Z

a typical example is...passing them to filter, remove, map...

2018-03-11T23:55:36.000024Z

Thank you!