Re: a thought about sequences
- Posted by Derek Parnell <ddparnell at bigpond.com> Aug 18, 2003
- 450 views
On Sun, 17 Aug 2003 23:03:11 +0000 (08/18/03 09:03:11) , Andreas Rumpf <pfropfen at gmx.net> wrote: > > > A sequence can be everything: a tree, a table, a stack, a string, a > structure, an array of structures, etc, etc. Hmmmm... Actually this turns out not to be the case. A sequence is exactly one thing only - a list of zero or more objects. How the coder chooses to interpret or use a sequence can lead to tree, table, stack, string, structure, etc... being implemented. But the same sequence that is used to implement a stack can also be seen, simultaneously, as a table. In other words, the sequence is not a stack, is not a table, is not a whatever ... except in the sense of how you wish to interpret its values. <off-topic> And remember in Euphoria, an object is a data construct that can contain a sequence, atom or integer. An object never changes into a sequence, but is can contain a sequence. An atom never changes into an integer but can contain an integer. If an object changed into the datatype of its contents, then it would mean that once assigned it could only hold values of the current datatype - but we know that's not true. object x x = 1.2 -- now contains an atom but x is NOT an atom x = "derek" -- now contains a sequence but x is NOT a sequence x = 3 -- now contains an integer but x is NOT an integer This is why the OpenEu group thought that a sequence of 'x' would be useful because it means that the compiler/interpreter is free to make some optimisations knowing the (static) datatype of its elements. In the parlance of OpenEu, the Euphoria sequence is really a shorthand way of saying 'sequence of object'. </off-topic> > While this is great, it has (like everything in life) a drawback: Look at > your source code, how often do you read 'sequence'? The word becomes > meaningless after some time. It is like in real languages: A word that > does mean everything is meaningless. I think, that's one reason (among > others) why other languages don't have a "one-does-it-all" type. I look at C code and see 'int' and 'char' all over the place too and these have yet to become meaningless. If this is your problem then use the 'type' method of creating aliases for sequence. global type elementlist (sequence x) return 1 end type elementlist myStack -- cheers, Derek Parnell