Subtraction was broken


I caught a very silly bug recently! In Lisp languages, you write

a - b

as

(- a b)

which seems ridiculous when you first learn it, but then you learn you can write

a - b - c

as

(- a b c)

which is marginally less keystrokes per operand. Totally cool huh?

So subtraction is supposed to start with the first number given and keep subtracting as many numbers as you want until you add the close-parenthesis. There is one exception, which is that

(- a)

simply returns the opposite of a (a times -1). If this were to follow the pattern, you'd expect (- a) to return a without changing it, but for Super Important ReasonsTM in most Lisps you can't just write

-a

because symbols can only start with letters.

Anyway, I'm currently on my 3rd attempt at implementing my own Lisp language to use for gamedev. In the first 2 attempts, I was diligent and remembered to implement and test the special case for subtraction with 1 argument. I guess on my 3rd attempt--which is the best one by far--it must have slipped my mind! Because I was trying to position sprites offscreen by using

(- coordinate)

and they were appearing on-screen at the positive coordinate value. D'oh! Wild to think that something as basic as subtraction was broken in the language I've been building for 3 years.

Get FLIES FLIES FLIES

Buy Now$5.99 USD or more

Leave a comment

Log in with itch.io to leave a comment.