[Prev][Next][Index][Thread]

Re: Complex/Imaginary numbers



dauclair@hotmail.com writes:

> How do I get Dylan to accept i as a postfix numeric modifier to create
> an <imaginary> instance.  I really don't want use operations such as

I'm afraid you'd have to modify the parser to do that, the macro
facilities are not designed to do this.

I'm willing to negotiate about doing exactly this for Gwydion
Dylan. We already have support for bignum literals:

let really-large-number = #e12345678901234567890;

and for ratio literals:

let some-ratio = 2/3 * 4/5;

so supporting the notation for complex literals would be natural. If
anybody has objections, please raise them now ;).

> As a side node, I've got the above implemented as pairs (so, 2 + 2.2i
> is #(2 . 2.2), and I've added arithmetic operations for pairs to the
> generic functions).

That is a bad idea. The right spot for complex numbers is already
defined in the Dylan numeric class hierarchy:

define open abstract class <number> (<object>) end;
define abstract class <complex> (<number>) end;
define abstract class <real> (<complex>) end;
define abstract class <rational> (<real>) end;
define abstract class <general-integer> (<rational>) end;
define abstract class <float> (<real>) end;

So you should inherit from <complex>. Using pairs might be the natural
thing to do in Lisp, in Dylan you should use real objects.

Also, an explicit <imaginary> type doesn't make sense to me.

The <rational> class should also give hints on how to implement
certain aspects, since it is also a composite number type.

Andreas

-- 
"We should be willing to look at the source code we produce not as the
end product of a more interesting process, but as an artifact in its
own right. It should look good stuck up on the wall."
 -- http://www.ftech.net/~honeyg/progstone/progstone.html



Follow-Ups: References: