Hacker News new | ask | show | jobs
by baconmania 3794 days ago
The fact that Clojure "hides the magic" behind less-verbose syntax can be a feature or a bug, depending on your opinion.

What's certain is that it's disingenuous to say that you have to explain those concepts in other languages, but not in Clojure. You might even say that you can guess what `zipped` and `sum` do, but the Clojure example really gives you no information about what's happening behind the scenes.

4 comments

I would say that map being variadic on the set-of-things-being-mapped, and + being variadic on the set-of-things-to-add, is more of a "semantic axiom of the language" than plain-old DSL-esque "magic." It's like backtracking in Prolog: an extra thing you can assume everything in the language supports, that lets you code differently.

Learning "about" the variadicity of what are, in other languages, binary infix operations, is certainly a thing to learn, but it's a different kind of thing to learn than learning about "zipped" or "map". It's more of a "changing the way you think" kind of thing than a "knowing what tool to use" kind of thing. Like learning about destructuring pattern-matching, or actor-modelled crash-only software.

The fact that you have to use the sentence :

"I would say that map being variadic on the set-of-things-being-mapped, and + being variadic on the set-of-things-to-add, is more of a "semantic axiom of the language" than plain-old DSL-esque "magic."

When you debate about any LISP based language is usually my clue.

> Clojure example really gives you no information what's happening behind the scenes.

I respectfully disagree. Map is almost a universal function and IMO, anyone who knows about map will instantly grok what the Clojure version does. The reason this looks so simple in Clojure is due to the fact that the map function is variadic (as our most other functions in Clj) but that is clearly not magic for any experienced programmer.

I respectfully disagree. I know map, of course, yet clojure (or LISPs in general) is the only language where it is variadic. I definitely did not instantly grok what the Clojure version does - in fact, I know all the languages in the example and each of them was more clear than clojure to me
> I know map, of course, yet clojure (or LISPs in general) is the only language where it is variadic.

According to Wikipedia `map` is also variadic in in D, in J, in Mathematica, in Prolog (and logtalk), in Python and in R (to an extent, `lapply` is not variadic but `mapply` can take 2+ sequences).

Variadic map is by no means limited to lisps.

Sorry, but isn't that the point? Why do I need to know what `sum` does behind the scenes? Same with `map`, `reduce`, etc. Those functions exist to avoid a `for` loop or other forms of imperative iteration for common uses.

Either way, I seem to remember that Clojure does have a REPL function to show you the source code for any function. You can use that to know what's going on behind the scenes.

Magic is bad when it makes it hard to understand the true behavior of the code. I've never seen a situation where I couldn't figure out what map was doing.