Re: Sequence of Suggestion (was Re: The Title Should At Least Mention Strings (
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Jun 02, 2004
- 491 views
On Wed, 02 Jun 2004 08:03:46 +1000, Patrick Barnes <mistertrik at hotmail.com> wrote: >But this is what euphoria has to do ALL THE TIME currently. In fact, it's >even worse >than in this example, because at least with this example you only have to >check text_picture[3], not the entire text_picture. Waaay ahead of you there. I once had a program with a huge and complicated fieldlist table at the centre, which practically every other line in the whole program updated. Adding type checking to it dropped the load time from about 2 seconds to around 80! Here is a contrived example: atom t0 t0=time() type table(sequence t) for i=1 to length(t) do if not integer(t[i]) or t[i]<-100 or t[1]>100 then return 0 end if end for return 1 end type --table t sequence t t=repeat(0,10000) for i=1 to 10000 do t[i]=5 end for printf(1,"%3.2f\n",time()-t0) if getc(0) then end if Replacing sequence t with table t drops the time from between 0.00 and 0.01 seconds to over 100 seconds, which is some slowdown! Of course I understand precisely why, and we definitely need some better way. What amuses me is Rob sounds a little surprised and hurt that no-one uses user defined types much) <snip> >>type textpict_line( sequence s) >> if length(s) != 80 then return 0 end if >> return 1 >>end type >>sequence of textpict_line of char text_picture >>textpict_line somevar >> somevar=repeat({0,0},80) -- OK >> text_picture[3]=somevar -- Erm... >> >>Here we assign a textpict_line to a textpict_line, so we don't need to >>do any type checking right? Wrong, of course. > >Uh, why wrong? There would need to be type checking when repeat() is >assigned to somevar, but not when somevar is assigned to text_picture. somevar is just a sequence of length 80, so the repeat assignment is fine. text_picture[3] should be a sequence of char, of length 80. <snip> >type textpict_line( sequence of char s) <snip> >Would the above solve other problems too? Yes, because you have much more naturally associated the 'of char' with the textpict_line type. > >Perhaps once a program has been sufficiently tested, type checking could be >turned off for better performance. That's precisely what without type_check does. Pete