Because Java’s if does not return a value, you cannot say: return if (x This would have been a nice place to make an analogy to the question mark operator, since a java programmer would probably be familiar with it and it allows you to write: return if (x as return x
I am a horse in the land of booleans
71–80 of 89 posts
Re: I am a horse in the land of booleans
#72Earlier quoted context omitted.
In 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.
If 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.
(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.
Re: I am a horse in the land of booleans
#73Earlier quoted context omitted.
Question 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 bas…
"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 no…
We are in agreement here. It seems to me, though, that it is an easy case to make that a question mark makes sense if you know English. Surely this is a convention less dependent upon specific knowledge.
Either way, Clojure is its own language and is not beholden to the tradition of any other language. What is most important is that it chooses a convention and implements it consistently. It is not meant to be Common Lisp nor is it meant to be Scheme, nor Dylan, nor Shen, nor Femtolisp, nor any other implementation. It is meant to be Clojure and what that means is defined by Rich Hickey.
Regarding`first`, `rest`, `head`, and `tail`, I don't think the argument based on English usage is the strongest. `head` and `tail` are established in some other programming languages, almost always as operations upon a link list. Those two words in English refer to body parts on some animals, hardly an obvious analog to generic collections. `first` and `rest` are not unheard of in other programming languages and in English do have a natural connection with the idea of a collection. Again, Clojure is meant only to be what Rich Hickey designed it to be, not a faithful reproduction of any other programming language.
Re: I am a horse in the land of booleans
#74Earlier quoted context omitted.
>>java programmer would probably be familiar with it And also C, C++, and Objective-C programmers. I'm sure there are more languages that use that operator that I have not mentioned here.
I have not touched PHP in the last 10 years but if memory serves it also has the ternary operator. Ok, lets try it: $ php -a Interactive mode enabled php > echo 1 == 1 ? "foo" : "bar"; foo php > echo 1 == 2 ? "foo" : "bar"; bar Looks like javascript has it too: 1 == 1 ? "foo" : "bar" "foo" 1 == 2 ? "foo" : "bar" "bar"
The use of parenthesis is highly encouraged...
Re: I am a horse in the land of booleans
#75Earlier quoted context omitted.
Question 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 bas…
"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 no…
(if (closed handle) ...)
(when (static widget) ...)
The p or -p or ? should only be used in situations when we can't avoid naming the predicate after a noun, like stringp for "is it a string".Re: I am a horse in the land of booleans
#76Earlier quoted context omitted.
"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 no…
> "p" makes sense if you know that it stands for "predicate". It's not nearly as arcane as car and cdr. We are in agreement here. It seems to me, though, that it is an easy case to make that a question mark makes sense if you know English. Surely this is a convention less dependent upon specific knowledge. Either way, Clojure is its own language and is not beholden to the tradition of any other language. What is most…
Like Common Lisp, which has `first`...`tenth` and `rest`.
Re: I am a horse in the land of booleans
#77Earlier quoted context omitted.
0 being falsy makes no sense outside of the C family of programming languages. But there 0 is overloaded both as a number and pointer (it's a bit more complicated though, as the value of the null pointer doesn't need to be zero but assigning 0 to a pointer will assign the null pointer). In languages with more elaborate type systems, you usually have the pointer and number representation separated. 0 has no special me…
>But making zero elements evaluate to falsy is problematic. "" would be falsy as well then. In Python 0, [], and "" are all falsy. In my experience it's only been useful - why do you consider it problematic?
I think this is one of the symptoms of the changing priority of simplicity in Python language design, at some point the design decision about 0/1 for simplicity became dated enough to change it despite being a big change and requiring backwards compatibility hacks with 0/1.
Re: I am a horse in the land of booleans
#78Because Java’s if does not return a value, you cannot say: return if (x This would have been a nice place to make an analogy to the question mark operator, since a java programmer would probably be familiar with it and it allows you to write: return if (x as return x
>>java programmer would probably be familiar with it And also C, C++, and Objective-C programmers. I'm sure there are more languages that use that operator that I have not mentioned here.
Re: I am a horse in the land of booleans
#79Because Java’s if does not return a value, you cannot say: return if (x This would have been a nice place to make an analogy to the question mark operator, since a java programmer would probably be familiar with it and it allows you to write: return if (x as return x
It's called 'ternary operator' because it's `?` and `:` and takes three operands.
Sometimes it's called the "conditional operator" but my experience has been that "question mark operator" is what the most people will understand.
Re: I am a horse in the land of booleans
#80Earlier quoted context omitted.
Question 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 bas…
"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 no…