Hacker News new | ask | show | jobs
by Paul-Craft 1115 days ago
Yeah, I'm not seeing what's so special either. Maybe it's that you do have to specify that initial value, so your return types are never something you don't expect?
1 comments

The numeric tower in Common Lisp may surprise us with simple things as addition:

  (+ #c(10 -1) #c(20 1))
the result of adding these two complex numbers is the integer 30.
Huh. I did not know that. I am surprised that it actually coerces the result to an integer, although that's certainly an artificial type edge case.

    SBCL is free software, provided as is, with absolutely no warranty.
    It is mostly in the public domain; some portions are provided under
    BSD-style licenses.  See the CREDITS and COPYING files in the
    distribution for more information.
    * (+ #c(10 -1) #c(20 1))
    30
    * (type-of (+ #c(10 -1) #c(20 1)))
    (INTEGER 0 4611686018427387903)
For example, if you do this, you do get a complex number.

    * (type-of (+ #c(10 -1) #c(20 1.0))) 
    (COMPLEX (SINGLE-FLOAT 0.0 30.0))