3 ms·
I confess I have grown increasingly in favor of how common lisp does this. The basic `/` creates rationals. And "floor" is a multiple value return where the f
by taeric 3y ago
I confess I have grown increasingly in favor of how common lisp does this. The basic `/` creates rationals. And "floor" is a multiple value return where the first value is the floor and the second is the remainder.
Granted, getting used to multiple value calls takes getting used to. I think I like it, but I also think I emphatically did not like it initially.
- mik1998 3y agoIt's nice for general numerical methods but somewhat annoying for implementing integer-arithmetic algorithms.
- taeric 3y agoYeah, I think this is what I really didn't like about it at the start. Learning that you probably want `floor` if you want things to be integer took more time to learn than feels natural.
- lalaithion 3y agoTo be fair, Python's `/` creates floats, and this article is about a second operator `//`.
- taeric 3y agoContinuing in fairness, lisp is a bit more involved, here. If you do `(/ 1.0 3)`, you do not get a rational. Similarly, any division that is not integer/rational there will get treated mostly as expected. Basically, it seems as soon as you introduce a floating point number, it stays there. Which is roughly what I would expect.
- im3w1l 3y agoIn python 2, '/' creates integers, and the article was written in 2010 when python 2 was the most used by far.
- lalaithion 3y agofrom the link: > PS. Note that I am using // instead of / -- this is Python 3 syntax
- im3w1l 3y agoOh. Right.
- shawn_w 3y agoScheme in the form of R7RS does something similar, though since failure to capture all returned values is an error (unlike in Common Lisp), there's more functions involved. It also offers a choice between truncation and floor behavior, so there's `truncate-quotient`, `truncate-remainder`, `floor-` versions and for both values `truncate/` and `floor/`.