Squeak archeology - quo vs. //

Dan Ingalls Dan at SqueakLand.org
Tue Apr 6 21:15:24 UTC 2004


Hi, Lex -

>I'm pretty sure that in ANSI C the behavior is implementation defined.
>So don't count on it doing one way or the other.

Whoa.  I'd take a bad definition over that!

>The reason other languages round to negative infinity -- not that I'm
>saying whether this is a good idea :) -- is to make // and \\ work
>nicely together.  That is, \\ can now give a proper remainder even with
>negative arguments:
>
>	self should: [ a  =  ((a // b) * b  +  (a \\ b)) ]
>
>The other way to make // and \\ consistent is to give back negative
>answers for \\ sometimes.  IMHO that would be even more weird than
>having // round towards negative infinity, but indeed that's how quo:
>and remainder: manage to work so nicely together.
>
>	self should: [ a  =  ((a quo: b) * b  +  (a remainder: b)) ]

Yes, but I don't consider it weird at all.  If I have a debt of -17 cents, then I do
	debt quo: 5
to find out my debt in nickels, and
	debt rem: 5
to find out the remaining debt in pennies.

Now try to explain that word problem using // and \\.

Both //-\\ and quo-rem play well together in Smalltalk, and it's just a question of which pair should have been given the convenient (infix) name, and thus become part of the "kernel" arithmetic.  I thought it was a lot easier to explain our current quo-rem to most users, so I wanted them to be infix operators.

Next time around...

	- Dan



More information about the Squeak-dev mailing list