4 ms·
Clojure seems to have replaced the "p"[0] suffix in predicates with "?", the former being an old Lisp convention. Interesting choice, I'm mildly miffed they did
by zshrdlu 7y ago
Clojure seems to have replaced the "p"[0] suffix in predicates with "?", the former being an old Lisp convention. Interesting choice, I'm mildly miffed they didn't go with the old convention.
[0] http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/fun_zerop.html http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec...
- greggyb 7y agoQuestion mark is a Scheme tradition. Clojure is a new lisp, drawing inspiration from many sources. One of Rich Hickey's goals, stated in many ways and in many of his presentations, was to design a modern lisp not bound by design decisions in old ones. That's why Clojure is not built on or directly based on any specific lisp. He has made a big point about moving on from lisp-isms such as `car` and `cdr`, which are based on tradition and specific archaic hardware implementation, to modern and within-language-consistent things like `first` and `rest`, which are both self-descriptive and implemented for anything that conforms to the seq protocol, as opposed to `car` and `cdr`, which are tied to cons cells. I do not recall anything specific that he's said about about the choice of a question mark vs a "p", but I can imagine a similar argument that a question mark is more self-descriptive than "p". "p" only makes sense if you know lisp traditions. Edit: typo
- Smithalicious 7y ago"p" makes sense if you know that it stands for "predicate". It's not nearly as arcane as car and cdr. Also can we finally settle on a name for these things now? If car and cdr are too arcane we can do away with them (though I like being able to do caddadadr) but why do we need "first" and "rest" rather than the already established "head" and "tail"? I particularly dislike "rest" since it's a relative term, i.e. in normal speech saying that you're going to do something with "the rest" of the list means something different depending on how much of the list you already used.
- puredanger 7y agoIn Clojure, first and rest apply to sequences, which are a logical list abstraction. They apply to lists, but they can also be used on sequential views of indexed vectors, maps, sets, database result sets, files in a dir, lines in a file, and an open world of "things that can be seen in some order". head and tail I suspect are much more tied to linked lists and data structure than the more plain first and rest.
- namibj 7y agoI might add that breaking the naming away (from traditions) also helps breaking the mindset away (from "that's how we always did it"). This allows for unified abstract views on things normally distinguished from each other by words, syntax, conventions and mind. This allows stuff like pattern matching generic functional code like the mighty monad with it's transformer. Learning functional programming incl. higher kinded types (dependent types and such) isn't easy for someone used to e.g. Java,C,C++,Python,Go, and others I can't judge of the top of my head. If you ask yourself why said functional is beneficial, remember the popularity and typical confusion of the Monad posts/articles. You might not quite understand / "get" it, but they keep coming up and the authors seem intelligent. So you (might) just have a case of the Blub Paradox[0]. You need to understand it to grok it's usefulness/desirability. [0]: http://www.paulgraham.com/avg.html http://www.paulgraham.com/avg.html
- lonelappde 7y agoIf you are using first and rest, then you are treating whatever sequence you have as a linked list, so you've already lost the plot.
- greggyb 7y agoYou can treat any collection or data structure that implements the sequence protocol as a lazy sequence with (seq collection) But you don't have to. If you choose to, you're not tied to a representation of mutable cons cells. There are good reasons to want to iterate over values in a map or a set, while still wanting the lookup characteristics of those collections, rather than a linked list. This is hardly a controversial stance. Python, for example, supports iteration over many of its data structures and it is recommended to implement the dunder methods for iteration on any class that might reasonably be the basis of an iteration. All clojure does is agree that iteration over a lazy sequence is a valuable concept. It implements this as an abstract protocol, rather than as a concrete implementation on linked lists.
- deleted 7y ago[deleted]
- deleted 7y ago[deleted]
- joppy 7y agoThe question mark is the standard Scheme way of writing a predicate, for example see https://www-sop.inria.fr/indes/fp/Bigloo/doc/r5rs-9.html#Numerical-operations https://www-sop.inria.fr/indes/fp/Bigloo/doc/r5rs-9.html#Num...
- sedachv 7y agoMany people (myself included) use the ? suffix in Common Lisp as well. IMO it is a better convention.