Bill Allombert on Tue, 5 Dec 2000 16:53:24 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: inequalities |
On Tue, Dec 05, 2000 at 09:41:33AM +0100, Karim BELABAS wrote: > [Fernando Rodriguez Villegas:] > > We were fooled by the following > > > > ? 2<4<3 > > %108 = 1 > > ? 2<1<0 > > %109 = 0 > > ? 1<2<3 > > %110 = 1 > > ? -1<2<3 > > %111 = 1 > > ? -2<-1<0 > > %112 = 0 > > > > We should write these with &&'s but shouldn't we have been warned by > > the GP parser? > > the main interpreter, and only used to check scripts) able to detect such > pitfalls, e.g: > > a < b < c > Warning: dubious associativity, you probably want to use && > > if (a = 1, .... > Warning: assignment used as truth value > > a+1; b ... > Warning: statement with no effect > > As a matter of fact, Bill Allombert has written a GP --> C converter [soon to > be announced...], and gcc -Wall might be able to do just that, at least for > _some_ potential problems. He might be willing to complicate the grammar of > his parser to catch some of the other things, which are valid given the > current GP grammar, but really shouldn't be allowed in a "clean" programming > language. Of course, the whole point is to issue Warnings upon user's > request, not to disallow existing "obfuscated" constructs. Thanks for this pre-announce. I use a typed intermediate language that can catch such things. However, I do not consider that a<b<c should trigger a warning. GCC does not, and in some sense it is a normal C construct. For example, (a<b) == (c<d) should be read as " a<b iff c<d ". Yes, I know, C is not a model. I will try to add this check to the compiler. I want to advertise the "local" keyword in gp script: The old PARI style for functions was { function(x1,x2,x3, /*local*/ a,b,c)= a=x1*x2;b=x2*x3;c=x3*x1; return [a-b,b-c,c-a]; } The new style is to be prefered function(x1,x2,x3)= { local(a,b,c); a=x1*x2;b=x2*x3;c=x3*x1; return [a-b,b-c,c-a]; } as it will allow the compiler to distinguish between local variable and arguments.