Story 1- and 1+
I recently went to # lisp on freenode and someone mentioned the existence of '1-' and1+
. Knowing about these functions, I wondered why they exist. Were they created for reasons such as related to --
and ++
C / C ++, or was there some other reason? Does anyone know the history of how these features became standard?
(If this question is more appropriate for another site (eg Programmers), please move it there. Thanks.)
source to share
I don't think there is a reason for performance in Common Lisp, although C, for example, n++
might be faster than n = n + 1
). There is a note at the bottom of the link:
(1+ number) == (+ number 1) (1- number) == (- number 1)
So, you can usually use +
or 1+
with the same result. I believe the real reason for these features is convenience. I personally find myself adding 1 more often than any other number.
Increment and decrement lessons can be found in almost every programming language (as far as I can tell), so it makes sense that Common Lisp has some.
PS I doubt this is really related and that my answer is helpful, so this is a community wiki; -)
source to share