[DGD] New DGD user introducing himself...
Erwin Harte
harte at xs4all.nl
Fri Aug 31 21:01:35 CEST 2001
On Fri, Aug 31, 2001 at 08:34:02PM +0200, Troels Therkelsen wrote:
> Hey all,
>
> I apologise in advance if this e-mail is long and rambling, and if it
> appears twice on this list... I had forgotten which address I signed up
> with ;-)
>
[...]
>
> With all the strict typing going around, and the addition of LWOs, I have to
> say I'm curious why you can't type objects ala Java, eg.,
>
> void func(object /lib/lwo/sorter obj);
>
> Then func() would only accept objects either inheriting /lib/lwo/sorter or
> being that object themselves. Without this object typing, basically all
> your objects are 'mixed'. Especially with LWOs and passing them between
> functions, it would be very convenient to have the runtime system do the
> type checking for you.
Easy to do yourself (which is a common theme in DGD):
* Put a nomask function in /lib/lwo/sorter.c with a known name, for
instance like this:
nomask void __lib_lwo_sorter() {}
* Do a check for function_object(the-function-name, obj) to see if it
is indeed the one in /lib/lwo/sorter like this
object obj_fo;
obj_fo = function_object("__lib_lwo_sorter", obj);
if (!obj_fo || !object_name(obj_fo) != "/lib/lwo/sorter") {
error("Bad argument 1 to function func");
}
Of course you can wrap this stuff in some macros to make life easier.
> Maybe too Java-ish for LPC, I dunno. This certainly is a Java-ism:
>
> FACTORY:
> object sorter() {
> object ret = new_object {
> int compare(int a, int b) {
> return ((a == b) ? 0 : ((a > b) ? -1 : 1));
> }
> }
>
> return ret;
> }
>
> A:
> int *arr = ({ ... });
>
> arr = sort_array(arr, FACTORY->sorter());
And how is this different from having some utility functions in a
library object that you inherit and then use?
Quite possibly I missed the point of the example, though. *grin*
Welcome aboard and you can leave the ranting to me, you can do the
rambling if you want. ;-)
Erwin.
--
Erwin Harte <harte at xs4all.nl>
_________________________________________________________________
List config page: http://list.imaginary.com/mailman/listinfo/dgd
More information about the DGD
mailing list