Ez: Types
- Posted by Christian.CUVIER at agriculture.gouv.fr Oct 14, 2003
- 428 views
> From: Don Phillips <EuNexus at yahoo.com> > Subject: Types > > > Just my personal opinion of something I would like to see come down the > pipe some time in the near future hint hint =) > > My current beef is with custom types... > [snip] > [What I] would like to propose is more control and flexibility over the final > outcome of a variables value. > > ===== > Example: > > type hour(integer x) > while x < 0 do > x += 24 > end while > > while x > 23 do > x -= 24 > end while > > return x -- assigned back to variable > end type > > hour h1, h2 > > h1 = 10 -- ok > h2 = 25 -- ok, h2 is actually assigned the value of 1 > ===== > > While I do agree that the above case is rather striking in its > appearance and effects, and if misused could seriously create hard to > track down bugs, but I also think this kind of addition would create > clearer code in most cases. > > In addition, it also paves the way for some very interesting > possibilities like default parameters and other such things... > > ===== > type args(object params) > -- {required,def=1,def=2} > if atom(params) > return( {params,1,2} ) > else > if length(params) = 1 then > return( params & 1 & 2 ) > elsif length(params) = 2 > return( params & 2 ) > end if > end if > return( params[1..3] ) > end type > ===== > > Heh, aww nevermind me... im just blabbing... > I would never actually expect anything like this to actually make it > into production as it violates too many of Euphorias principles. > > IMO though it would be nice to have ,) > You'll have this in OpenEuphoria. It's called reftype, and it can act on the value as well as the var getting assigned. CChris