peter@ficc.ferranti.com (Peter da Silva) (02/27/91)
In article <3439.27ca4e40@iccgcc.decnet.ab.com> herrickd@iccgcc.decnet.ab.com (daniel lance herrick) writes: > when what I want is > (q, r) = dividend divided by divisor Than you need a different programming language. Wasn't there a stack oriented language called "POP-2" or something that would allow this with this sort of syntax? Or you could always use Forth: dividend divisor /MOD q ! r ! (I may have got the order of the results mixed up) (followups to comp.lang.misc) -- Peter da Silva. `-_-' peter@ferranti.com +1 713 274 5180. 'U` "Have you hugged your wolf today?"
guido@cwi.nl (Guido van Rossum) (03/04/91)
peter@ficc.ferranti.com (Peter da Silva) quotes and replies: >> when what I want is >> (q, r) = dividend divided by divisor > >Than you need a different programming language. In Python you can write: (q, r) = divmod(dividend, divisor) or even: q, r = divmod(dividend, divisor) And Python isn't even stack-oriented! --Guido van Rossum, CWI, Amsterdam <guido@cwi.nl> "Oh Bevis! And I thought you were so rugged!"
tchrist@convex.COM (Tom Christiansen) (03/04/91)
From the keyboard of peter@ficc.ferranti.com (Peter da Silva):
:In article <3439.27ca4e40@iccgcc.decnet.ab.com> herrickd@iccgcc.decnet.ab.com (daniel lance herrick) writes:
:> when what I want is
:> (q, r) = dividend divided by divisor
:
:Than you need a different programming language.
Pretty easy in perl: functions can return scalars or lists. It's
quite common to say:
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks)
= stat($filename);
Which is nice -- I like the named variables. Others just stick it in
one array, convenient if you're doing stats on various files:
@statb = stat($filename);
For your division and remainder problem, you could just define a trivial
subroutine as follows:
sub divrem { ($_[0] / $_[1], $_[0] % $_[1]); }
and then say stuff like:
($q, $r) = &divrem(7,2);
--tom