Re: Type - Start Again
- Posted by Pete Lomax <petelomax at b?ueyonder.c?.uk> Aug 21, 2007
- 500 views
Peter Robinson wrote: > > Case 1: Fixed heterogeneous sequences > > Salix assumed that my example like:- > > type customer( sequence x ) > integer x[1] id > sequence x[2] name > sequence x[3] address > end type > > implied length(x) = 3. It's a reasonable asumption, but I actually didn't > intend > it one way or the other. Fair enough. If you wanted to enforce a customer record only ever had 3 fields then use the obvious if length(x)!=3 then return 0, otherwise elements 4..$ can exist and are untyped. > > Discussion between Pete and CChris, including aliasing, suggested that the > x[num] > part is superfluous, since the index is implied by ordering. I have no particular bias for [1],[2] or fields .. end fields notation. > Case 2: Homogenous sequences > > -- 1-dimensional sequence, all integers i.e. sequence of integer > type list( sequence x ) > integer x[] > end type I was thinking of using
type list(sequence of integer x) end type
> -- which suggests > type semi_loose_entity( sequence x ) > integer x[1] > sequence x[2..$] > end type Hmmm, not sure about that. After sle[idx]=x, if idx is a fixed literal integer constant (such as a field name) then the compiler will be able to limit type checking to the single modified element, but if idx is a var then the compiler cannot do the same level of optimisation, needing either extra code somewhere (key point being, where would that code be, exactly?) or it may be easier and quicker just to type-check the whole thing. > -- > 2-dimensions - highlighting visual hierarchy idea > type matrix( sequence x ) > sequence x[] -- 1st dimension all sequences > integer x[][] -- 2nd dimension all integers > end type > Seems to me this, and the previous example, would be better coded as:
type vector(sequence of sequence ss) end type type speeds(sequence of integer si) end type type matrix(sequence x) vector x[1] v speeds x[2] s end type
To me this has a clear advantage that when modifying the elements of a type matrix var, the work vars you need have a read-made named type, which in turn means the compiler can omit type checking completely:
procedure swap(matrix m, integer a, integer b) vector v v=m[v][a] m[v][a]=matrix[v][b] m[v][b]=v end procedure
Which is a pretty neat trick, considering you would still have full type-safety on user defined types. (First person to say C++ already does this gets a kick) > Since I started all this, I'm happy to do any documentation of any outcome > or assist otherwise if I can, but I can't devote time to studying the > interpreter code in depth. On may travels the other day (looking for something else entirely), I came across this by Derek Parnell: http://www.openeuphoria.org/cgi-bin/esearch.exu?thread=1&fromMonth=8&fromYear=8&toMonth=A&toYear=8&keywords=%22Last+Element+Reference%22 Same deal for the next stage: Articulate and concise, irrefutable and conclusive would probably work best. Also plenty of concrete examples - if they're not right, and convincing, it won't fly. Regards, Pete