Page 1 of 1

div, mod, and mul as unary operators?

Posted: Sat Oct 30, 2010 9:33 am
by TedWalther
mul and div do what I expect when used as unary operators.

(div 10) => 0.1 (10 becomes 1/10)
(mul 10) => 10 (10 becomes 10*1)

But mod... mod does nothing.

Could mod be made so it behaves the following way?

(mod 10) => 0 (10 becomes 10%1)
(mod 10.5) => 0.5

This would let mod act as the builtin "frac" for getting the fractional part of a number; right now we have round, floor, and ciel that already give us the integer part of a number. And yes, I can do (mod %number% 1). But in keeping with the unariness of the other operators, I request this change.

Then I could do (constant (global 'frac) mod) in my .init.lsp

Ted