Re: Properties in Methodica
- Posted by Mike Nelson <mikestar13 at sbcglobal.net> Sep 29, 2006
- 578 views
Reposting after a premature send. Derek Parnell wrote: > I take it that the 'value' parameter for the setter method is a reserved word > in that context and is a Euphoria object datatype. That would mean that the > setter could receive a sequence and deal with as required. Not quite what I had in mind, but a good idea: value is indeed as reseveved word in context, but I had assumed that it would have the type of the property. How about this variant: property height public integer get return this.h public any set if not value.is(integer) then value=value.to_integer() -- Will throw an exception if value can't be converted. end if if value<0 then throw Type_Error.new("Height must not be negative.") else this.h=value end if end property foo.height = "23" My original syntax would still be available for the ususal case where both the getter and the setter are using the same type. Logically it should aso be legal to put the access specifier after "property" when the same access is desired for both get and set. lines 1, 2, and 4 could be written as
property public height integer get any set
The type "any" is Methodica's top level generic type, for compatibility with Eu, object is the supertype of atom, sequence, and thier subtypes. Methodica types may be value types: object, atom, sequence, string, integer, etc. or reference types (classes): Entity, Exception, etc. By convention value types start with a lowercase letter while reference types start with an uppercased letter. (The compiler will not enforce this.) "any" is the lone type which may hold a reference or a value.