Re: Eu improvements (Part 1)
- Posted by James W Hofmann <jhofmann at ucsc.edu> Jan 04, 2007
- 516 views
Jason Gade wrote: > > This looks interesting, but I would like to see a more substantive example. > > What would be the effect of without typecheck? Original source
type Point(sequence s) index x=s[1] index y=s[2] return length(s)=2 end type Point p sequence q p={0,0} -- initialize q={5,5} for nx=1 to 10 do p.x = nx ? p.x p.y = p.x+1 ? p.y end for -- output is 1,2,2,3,3,4,4,5,5,6,6,7,7... ? q:Point.x -- output is 5
Typecheck off makes it into this equivalent:
sequence p sequence q p={0,0} -- initialize q={5,5} for nx=1 to 10 do p[1] = nx ? p[1] p[2] = p[2]+1 ? p[2] end for ? q[1] -- output is 5
At least, I think that's how it would look. A simple replacement of name-notation with number-notation. > I kind of like the first example better but then use the colon notation as > kind > of a "cast". Maybe. Hmm. Both notations could work, because they do different things. Dot-only(simple-dot?) notation says "use the type that you declared the variable as." Colon-dot notation says "try to use this particular type on this variable." In the above example I used simple-dot because it felt natural to me after doing it so often to reference class variables in Python. But having the other seems like a reasonable idea for code needing greater structure. I don't really have a good feel for the potential downsides, though.