[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Overloading of primitive operators
- To: Nat Ballou <email@example.com>
- Subject: Re: Overloading of primitive operators
- From: kanderso@DINO.BBN.COM
- Date: Fri, 16 Mar 90 09:41:51 -0500
- Cc: CommonLoops.pa@Xerox.COM
- In-reply-to: Your message of Thu, 15 Mar 90 17:33:00 -0600. <19900315233311.3.BALLOU@LILITH.ACA.MCC.COM>
- Redistributed: CommonLoops.pa
But if I do this, for any package to use my package's definition of +, it too
must shadow the +. Such a package better shadow such symbols before using
the LISP package, and heavens forbid if some package other than mine also
pulls the same trick on the operator +...
At least i the LISP i'm using, this works fine:
;;; Make a package the way you like it:
(make-package 'nat-lisp :use '(pcl lisp))
(shadow '(lisp:+ lisp:-) 'nat-lisp)
(export '(nat:+ nat:-) 'nat-lisp)
;;; Define the functions you want ...
;;; Define a package for users to use:
(make-package 'nat-lisp-user :use '(nat-lisp pcl lisp))
... now users can use your generic lisp ...
The idea of using shadowed symbols is not a real solution since one has
really introduced a new symbol (i.e., the symbols have the same name, but
are two different symbols). In C++, the user of an overloaded primitive
operator does not need to do anything special.
Perhaps, but you get what you want for about 5 lines of software. Not
only do you get the behavior you want in nat:+, but you also get the
implementor's lisp:+ to build it in terms of. This gives you
something to use while you write a truely object oriented LISP from
scratch, and get X3J13 to accept it as a standard.
BTW, C++ does place restrictions on operators that can be overloaded
[at least in 1984]. For example, you can't change the syntax of an
operator, and you can't add new ones like "**" for exponentiation.
These issues don't even come up in LISP. To be fare, perhaps you
should start a discussion about this on some C++ group.