Re: Discussion concerning [POLL] Sequences of types
- Posted by Pete Lomax <petelomax at blueyo?d?r.co.uk> Aug 24, 2007
- 673 views
Derek Parnell wrote: > > object names -- Can be assigned with anything. > sequence names -- Can only be assigned with a sequence. > sequence of sequence names -- Can only contain sequences. > sequence of sequence of object names -- same as above. > sequence of sequence of atom names -- Can only contain sequences, which > -- can only contain atoms > sequence of sequence of integer names -- Can only contain sequences, which > -- can only contain integers > > If this is too much for some people to grok then maybe a simplified 'type' > alias > might be useful. > > type word_list (sequence of sequence of integer) > end type > In the name of code readability, I expected you to favour the latter. Both could work, I guess, this may be more a matter of personal preference. Suppose we have a chess program:
sequence of sequence of sequence of integer backtrack_list sequence of sequence of integer init,best,curr,scratch
vs.
type row(sequence of integer r) end type type board(sequence of row b) end type type boards(sequence of board sb) end type board init,best,curr,scratch boards backtrack_list
Now you may or may not not need a Phd in the effect of the spice girls on the global multimedia economy to figure either out, not the point. A possibly important advantage here is that the innermost bit is now quite clearly a row not a column. Another example is:
sequence of sequence of sequence of integer filetable
vs.
type char(integer c) end type type line(sequence of char l) end type type file(sequence of line f) end type type texts(sequence of file sf) end type texts filetable
The clincher for me though is this, for the chess example:
function f(object o) row r if board(o) then r=o[1] ... elsif row(o) then ... end function
How would you test for board or row without a named udt? More subtly, what type do you give r? Yes, you can (easily) figure out from the sequence of sequence of sequence of integer thing that it needs to be a sequence of integer, but you are probably just going to give it type object and then the compiler cannot optimise away any type-checking. Regards, Pete