Re: New Language
- Posted by Mike Nelson <mikestar13 at sbcglobal.net> Sep 26, 2006
- 594 views
Pete Lomax wrote: > Do you have any specs/design/examples? In particular side-by-side > demos which extol the virtues, eg: > OO: > }}} <eucode> > return call_method(o,"length",{}) > </eucode> {{{ > procedural: > }}} <eucode> > if o[tag]=CAR then return o[CAR_LENGTH] > elsif o[tag]=BOAT then return o[BOAT_LENGTH] > ... > </eucode> {{{ > Though obviously a bit more involved. Possibly start with the very > first program you hope to get running and the coolest example you can > think of that will only start working sometime nearer the release date > perhaps with some example mods or bugfixes which are trivial in OO but > fiddly and all over the place in the equivalent procedural code? > > Not that I'm a particular fan of OO programming or anything... > > Regards, > Pete We already have:
return call_method(o,"length",{})
this is the correct Method Euphoria syntax. My new language will render it as the much more readable
return o.length()
There will still be support for the advantage of the former sytax: the method name might be a variable, allowing indirect calling:
string x="length" return System.call(o,x)
Here are two classes to whet the appetite while I'm working on the project:
class Container_Extension extends General_Container General_Container base method shared Container_Extension new(General_Container base) Container_Extension me if base=nothing then throw Null_Reference.new() end if me=super() me.base=base return me end method method Container_Extension clone() Container_Extension me me=super() me.base=this.base.clone() return me end method method boolean base_is(type t) if this.base.is(Container_Extension) then return this.base.base_is(t) else return this.base.is(t) end if end method method type base_type() if this.base.is(Container_Extension) then return this.base.base_type() else return this.base.type() end if end method method protected call_failed(Exception reason,string name,array parameters) if reason.is(Undefined_Method) then System.call(this.base,name,parameters) else throw(reason) end if end method end class class Locking_Container extends Container_Extension public integer locked method Locking_Container clone() Locking_Container me me=super() me.locked=false return me end method method integer insert(array parameters) if this.locked then throw Locked_Container.new() else return super(paramters) end if end method method any remove(array prameters) if this.locked then throw Locked_Container.new() else return super(parameters) end if end method method clear() if this.locked then throw Locked_Container.new() else return super() end if end method method lock() this.locked=true end method method unlock() this.locked=false end method end class
The Container_Extension class is a framework to facilitate the writing of wrapper classes to add functionality to containers. The Locking_Container class is a specific implementation--pass a Queue or a Map to its constructor and you add the capabilty to lock and unlock the container. Only the methods which are affected by locking are defined. Any other methods of the underlying container result in the call_failed method bieng invoked with a Undefined_Method exception. The call_failed method uses System.call to indirectly call the method on the underlying container. This allows a kind of multiple inhertience or runtime inheritence without all the problems of building it into the basic class structure.