Types
- Posted by Don Phillips <EuNexus at yahoo.com> Oct 14, 2003
- 634 views
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... ===== Example: type hour(integer x) return x >= 0 and x <= 23 end type hour h1, h2 h1 = 10 -- ok h2 = 25 -- error! program aborts with a message ===== Easy to understand yes, but most (actually just about all) of the regular types in other languages just dont behave this way. 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 ,)