[Gambas-user] [SPAM] Re: Ambiguous expression?
Dag Jarle Johansen
dag.jarle.johansen at ...2312...
Thu Mar 11 02:36:00 CET 2010
Sorry
this i mathe
if you have been on a highschool or a college, you would know: it's easy
multiplication and diviation goes for addition and subtsraction.
Gambas works like this, if you are unsure, use parantesis ()
regards,
Dag-Jarle Johansen
Am Mittwoch, den 10.03.2010, 20:20 +0100 schrieb Doriano Blengino:
> Benoît Minisini ha scritto:
> >> Alessandro Rinaldi ha scritto:
> >>
> >>> I really think yes.
> >>> Standard symbol for fractions is /, why should you use \?
> >>>
> >> Backslash is "integer division", and should yeld an integer result.
> >> Slash is "float" division, and yelds a float number (this is "Basic"
> >> syntax; other languages use different methods).
> >>
> >> The expression "1\2*3" is not really ambiguous, it is only for Gambas
> >> (don't ask me why); it should be seen as "take an integer number,
> >> integer-divide it for another integer number, and multiply the result
> >> for another integer number, giving an integer result".
> >>
> >>
> > I noticed that operator evaluation order differ between languages, even if
> > they agree on most parts.
> >
> > So I decided to raise an error when the compiler encounters different
> > operators having the same evaluation order weight, and when I thought that the
> > interpreter may not do what the user thinks.
> >
> > By compelling the user to add brackets, I make the source code less ambiguous
> > for another reader, so this is a good thing.
> >
> > But the test is not perfect, and I don't remember why I do not raise the error
> > for 1/2*3 and I raise it for 1\2*3.
> >
> > Maybe because that mixing "*" and "/" is usual in mathematics, but mixing an
> > integer division with a normal multiplication not, and I wanted to force the
> > use of brackets.
> >
> Perhaps this is because C has "/" and "*", and both have a double
> meaning (integer and float);
> pascal has two separated "/" and "DIV", and only one "*". So gambas is
> similar to pascal.
> When an operator is the same on different types (integer and floats),
> the compiler checks the arguments of the operator to decide whether
> promote one of the two (and the result).
> In this very case, all the arguments are integer, so all the operators
> are integer too, and there should be no doubt.
> Anyway, division and multiplication have the same precedence and
> (probably?) same associativity.
>
> But I agree with you: by combining precedence and associativity it is
> easy to make up a mess, and sometimes a solution like yours is better.
> The C language has something like 15 or more rules, so who remembers the
> exact result of "*pointer-- >> 3+1"?
> > Morever, that error is actually just a warning. I can suppress it, and Gambas
> > will just apply its operator evaluation order without telling anything. But I
> > don't think I will do it!
> >
> >
> Uhm... *it is* an error if the compiler refuses to compile... it would
> be possible to turn it in a warning (does gambas have warnings?), if
> only one is very sure about promoting. But gambas uses a typing scheme
> different from C and pascal, and automatic type conversions, so you are
> probably right in keeping your way.
>
> Regards,
> Doriano
>
>
> ------------------------------------------------------------------------------
> Download Intel® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
More information about the User
mailing list