Re: Stupid Newbie-sounding question.
- Posted by "Patrick Barnes" <mistertrik at hotmail.com> May 31, 2004
- 549 views
My approach to this problem: We need a new keyword; "of". Usage: type char ( integer c ) -- return 1 valid character, 0 otherwise end type --myStr is a string sequence of char myStr It is an extension to the type checking system on sequences, and is applied whenever an element of the sequence is changed. The existing type checks are slow because they have applied to the whole sequence whenever a single element is changed. This "of" typing would only check the elements that are changed in the sequence. If you have a complex data structure list, you could have: type myDataStructure( sequence s) --return 1 if valid myDataStructure, 0 otherwise end type --master_list is a 1-dimensional array of myDataStructures sequence of myDataStructure master_list This would not break any existing code, as "sequence" without an 'of' would mean no restrictions. Multi-dimensional arrays are also possible: --2d array of integers sequence of sequence of integer 2d_array type textpict_line( sequence s) if length(s) = 80 then return 1 else return 0 end if end type --2d array where the length of each line is fixed, and consists of characters sequence of textpict_line of char text_picture Rules: -------- 1. Only types that have sequence as a base can be listed before the last type. So: sequence of sequence of char is ok. and: sequence of char of sequence is NOT okay. 2. Whenever an element of a type is changed, the type that the element should be is checked. The rest of the variable was not affected, don't check it. 3. If using a custom type as the base, eg: textpict_line of char text_line, the textpict_line type checking will only be invoked when the length of the sequence changes. (If the of keyword is not used, it will be invoked as normal) 4. If casting between types: ie - generic sequence to sequence of char, then a full type check will be performed: The base type will be checked first, then the element type will be checked against each element. Suggestion #2: Allow some simple type defines, a la c/c++. This could be done without adding extra code, perhaps like so: type rgb (sequence of integer c) return length(c) = 3 end type type rgb_map ( sequence of sequence of rgb x) return 1 end type If no extra checking has to be done, then the type just returns 1. That's my take on the situation. I can't see any problems with this right now, and Rob, I'd like to hear your thoughts on this. Cheers. MrTrick >From: Juergen Luethje <j.lue at gmx.de> >Reply-To: EUforum at topica.com >To: EUforum at topica.com >Subject: Re: Stupid Newbie-sounding question. >Date: Mon, 31 May 2004 11:35:27 +0200 > > >Pete wrote: > > >> Juergen Luethje wrote: > > <snip> > >>> At the first glance, it might look as if an additional data type would > >>> make Euphoria more complicated, > > > > Adding a string type takes the number of cases for the "&" operator > > from 8 to 19, without considering unicode strings. Just so you know. I > > agree that string types might be nice, but they are far from trivial. > >I think you are describing the point of view of the developer of the >language, right? That's interesting. I didn't know that, but I truely >believe that implementing a string datatype will mean considerable work. >Well, I am willing to pay some extra $ for such an enhancement. > > >From the point of view of the user of the language, in most (if not all) >cases the "&" operator should work with a built-in string type, like it >currently works with our user-defined string types. > >[snipped in agreement] > >Regards, > Juergen > > > >