1. RE: Sequence of Suggestion (was Re: The Title Should At Least Mention Strings

>From: Pete Lomax <petelomax at blueyonder.co.uk>
>Subject: Sequence of Suggestion (was Re: The Title Should At Least Mention 
>Strings (was R
>
> >So, what are we assigning to text_picture[3] ?
>An expression. Think of what you might do with a text_picture. You
>might invert all the characters for a blink effect, or slice and dice
>to rotate, pan, or zoom the image. You might, for example, code
>text_picture[3]=upper(text_picture[3]), or you might code
>text_picture[3]=text_picture[3][2..80]&text_picture[3][1]
>
>In both those cases, what is actually assigned is a function result
>(upper() and concat()), which could be an object of any type, as far
>as any non-sentient interpreter is concerned.

I understand what you're saying...
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.


> > If it's being assigned to
> >something that has the type textpict_line already, then we don't need to
> >type check the element, because it has already been type checked when it 
>was
> >last changed.
>That is very important, however allowing "<udt> of" ruins it:
>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.

>
> >I really think this would make Euphoria more flexible...
>Oh, I'm not arguing against this, I think it would be good. Just
>trying to nail down the details & quieten the grumbles in the back of
>my head. I cannot prove it, but my gut feeling is that allowing a
>second (or third..) "of" spanners it.

Okay, I agree with you here. The spec is still a bit nebulous. Okay, better 
definition:

Only one "of" is allowed in each type. However, types can be nested.
Updated example:

type char ( integer s)
    -- return 1 if valid char
end type
type textpict_line( sequence of char s)
    if length(s) != 80 then return 0 end if
    return 1
end type
type text_picture( sequence of textpict_line s)
   return 1
end type

--example code
text_picture screen
screen = MyGetTextScreen(0)

(Now, type checking involved when the func is assigned to screen depends on 
the value of the return... If the returned sequence had a type of 
text_picture already, then it doesn't need to be type-checked again.)

>PS I am aware that defining somevar as a textpict_line of char will
>solve the immediate problem.

Would the above solve other problems too?



Perhaps once a program has been sufficiently tested, type checking could be 
turned off for better performance.
MrTrick

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu