div, mod, and mul as unary operators?

Q&A's, tips, howto's
Locked
TedWalther
Posts: 608
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC
Contact:

div, mod, and mul as unary operators?

Post 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
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.

Locked