1. Some sort of OO
- Posted by jemima Sep 12, 2009
- 1185 views
I would like to gather some ideas about a specific part of this - dynamic lookup.
I suppose a related topic is how some other languages implement s["fred"] in a reasonably efficient manner.
So we want to implement O.print(), but there are dozens of print() methods this statement could be referring to - some builtin, some defined in classes, and all the inheritence handling you might expect.
Doubtless there are several ways, but which is the most efficient?
2. Re: Some sort of OO
- Posted by raseu Sep 12, 2009
- 1069 views
- Last edited Sep 13, 2009
if you use the preprocessor dot.ex (see docs in v4 release)
you can use the following pseudo OO constructs with namespace qualifiers
--// tom.de namespace tom --// Ubuntu --// $ uuidgen -r constant CLASS_TOM_ID = "d811f80f-f50c-43c9-a327-ce48381801fe" enum classtype, name, sizeof_tom type CLASS_TOM(sequence self) return equal(self.classtype, CLASS_TOM_ID) end type public function new(sequence _name="") sequence self = repeat(0, sizeof_tom) self.classtype = CLASS_TOM_ID self.name = _name return self end function public procedure print(CLASS_TOM self) printf(1, "my name is %s\n", { self.name }) end procedure --// harry.de namespace harry --// Ubuntu --// $ uuidgen -r constant CLASS_HARRY_ID = "567efd8f-090a-42e4-ba21-739f5baa0bd9" enum classtype, name, sizeof_harry type CLASS_HARRY(sequence self) return equal(self.classtype, CLASS_HARRY_ID) end type public function new(sequence _name="") sequence self = repeat(0, sizeof_harry) self.classtype = CLASS_HARRY_ID self.name = _name return self end function public procedure print(CLASS_HARRY self) printf(1, "my name is %s\n", { self.name }) end procedure --// include these with namespace qualifiers include tom.e as tom include harry.e as harry sequence t = tom:new("TOM") sequence h = harry:new("HARRY") --// calling specific namespace functions/procedure t.tom:print() h.harry:print() --// fails h.tom:print() Using the class/test files 1) Generate the class files (your syntax may vary, see dot.ex documentation) $ eui dot.ex tom.de $ eui dot.ex harry.de $ eui dot.ex test.dex 2) Run $ eui test.ex my name is TOM my name is HARRY
3. Re: Some sort of OO
- Posted by jeremy (admin) Sep 12, 2009
- 1127 views
- Last edited Sep 13, 2009
Using the class/test files
1) Generate the class files (your syntax may vary, see dot.ex documentation)
$ eui dot.ex tom.de $ eui dot.ex harry.de $ eui dot.ex test.dex
2) Run
$ eui test.ex my name is TOM my name is HARRY
</eucode>
With the new pre-processor in 4.0, it's easier than that. You can run the .de/.dex files directly.
$ eui -p de,dex:dot4.ex test.dex
That's all that's needed. Further, if you put -p de,dex:dot4.ex in your euphoria/bin/eu.cfg file, you don't have to type that even. It's as simple as:
$ eui test.dex -- or even $ euc test.dex
Jeremy
4. Re: Some sort of OO
- Posted by Critic Sep 13, 2009
- 1135 views
I would like to gather some ideas about a specific part of this - dynamic lookup.
I suppose a related topic is how some other languages implement s["fred"] in a reasonably efficient manner.
Many use hash tables for this.
So we want to implement O.print(), but there are dozens of print() methods this statement could be referring to - some builtin, some defined in classes, and all the inheritence handling you might expect.
Doubtless there are several ways, but which is the most efficient?
Probably doing global program analysis and implementing it with a table lookup (similar to a switch statement) or a decision tree.