digitalmars.D.learn - precedence of cast
- Fawzi Mohamed (6/6) Aug 27 2008 I was wondering about the precedence of the cast operator.
- Manfred_Nowak (9/10) Aug 27 2008 If a table is needed, it suggests itself to not rely on yourself and
- Fawzi Mohamed (9/18) Aug 27 2008 I agree that in general it is a good advice, but if you have an
- Denis Koroskin (3/19) Aug 27 2008 That's generally a good idea to have such a table, to reduce number of
- bearophile (8/10) Aug 27 2008 Having a reference table is positive, but even better is to design a lan...
- Jarrett Billingsley (3/21) Aug 27 2008 OT: is there anything about D that you _are_ satisfied with?
- bearophile (23/24) Aug 28 2008 There are many things I like of it, but finding and listing them all may...
- BCS (3/6) Aug 27 2008 If you know how to read it, the spec is peppered with BNF and that is th...
- torhu (3/7) Aug 28 2008 I just use a C operator precedence table, D follows that:
- Fawzi Mohamed (4/13) Aug 29 2008 thanks, I wasn't sure about cast, but it seems that also that follows
- Ary Borenszweig (4/12) Aug 28 2008 If you downloaded DMD, you can take a look at src\dmd\expression.c
I was wondering about the precedence of the cast operator. By experimenting I found that it is less than . and more than +, but I was wondering if there isn't a place where this is exactly explained. A table with the precedence of all operators would be welcome :) thanks Fawzi
Aug 27 2008
Fawzi Mohamed wrote:A table with the precedence of all operators would be welcomeIf a table is needed, it suggests itself to not rely on yourself and others to know the contents of that table. Use parens and everyone sees the intention. -manfred -- Maybe some knowledge of some types of disagreeing and their relation can turn out to be useful: http://blog.createdebate.com/2008/04/07/writing-strong-arguments/
Aug 27 2008
On 2008-08-27 18:14:40 +0200, "Manfred_Nowak" <svv1999 hotmail.com> said:Fawzi Mohamed wrote:I agree that in general it is a good advice, but if you have an expression that you need to use often, some optimization is in order, because (being it common in your code) excessive parens just weight it down and, whoever looks at your code will have to understand it once, to then apply it in all cases. And anyhow, just for the sake of knowing it I would like someplace where I can look at it. :) FawziA table with the precedence of all operators would be welcomeIf a table is needed, it suggests itself to not rely on yourself and others to know the contents of that table. Use parens and everyone sees the intention.-manfred
Aug 27 2008
On Wed, 27 Aug 2008 20:32:57 +0400, Fawzi Mohamed <fmohamed mac.com> wrote:On 2008-08-27 18:14:40 +0200, "Manfred_Nowak" <svv1999 hotmail.com> said:That's generally a good idea to have such a table, to reduce number of trial and error, for example.Fawzi Mohamed wrote:I agree that in general it is a good advice, but if you have an expression that you need to use often, some optimization is in order, because (being it common in your code) excessive parens just weight it down and, whoever looks at your code will have to understand it once, to then apply it in all cases. And anyhow, just for the sake of knowing it I would like someplace where I can look at it. :) FawziA table with the precedence of all operators would be welcomeIf a table is needed, it suggests itself to not rely on yourself and others to know the contents of that table. Use parens and everyone sees the intention.-manfred
Aug 27 2008
Denis Koroskin:That's generally a good idea to have such a table, to reduce number of trial and error, for example.Having a reference table is positive, but even better is to design a language & programs (D) that usually don't need the programmer (or the person that reads the code) to read such table to understand what the code does. D follows the design of the C language in many things. C has lots of precedence rules, while a language like Ada has chosen to have much less Operator Precedence Levels, to simplify the work of the programmer, see point 4F here: http://www.adahome.com/History/Steelman/steeltab.htm This means that D may eventually choose to decrease its number of precedence levels to simplify it. On the other hand Python has something like 17 precedence levels: http://books.google.it/books?id=nEJ-jcYF2fMC&pg=PA97&lpg=PA97&dq=python+operator+precedence+rules&source=web&ots=3_tES429hg&sig=WiLW5C5JyNXTg1HyJssbM-pe1Ns&hl=en&sa=X&oi=book_result&resnum=1&ct=result#PPA96,M1 Bye, bearophile
Aug 27 2008
"bearophile" <bearophileHUGS lycoc.com> wrote in message news:g94oul$2mi5$1 digitalmars.com...Denis Koroskin:OT: is there anything about D that you _are_ satisfied with?That's generally a good idea to have such a table, to reduce number of trial and error, for example.Having a reference table is positive, but even better is to design a language & programs (D) that usually don't need the programmer (or the person that reads the code) to read such table to understand what the code does. D follows the design of the C language in many things. C has lots of precedence rules, while a language like Ada has chosen to have much less Operator Precedence Levels, to simplify the work of the programmer, see point 4F here: http://www.adahome.com/History/Steelman/steeltab.htm This means that D may eventually choose to decrease its number of precedence levels to simplify it. On the other hand Python has something like 17 precedence levels: http://books.google.it/books?id=nEJ-jcYF2fMC&pg=PA97&lpg=PA97&dq=python+operator+precedence+rules&source=web&ots=3_tES429hg&sig=WiLW5C5JyNXTg1HyJssbM-pe1Ns&hl=en&sa=X&oi=book_result&resnum=1&ct=result#PPA96,M1 Bye, bearophile
Aug 27 2008
Jarrett Billingsley:OT: is there anything about D that you _are_ satisfied with?There are many things I like of it, but finding and listing them all may require too much time, few of the most important things I like of it: - the people of D community, because with few exceptions, most people seem intelligent, helpful, gentle, etc. - the idea of putting program correctness first, avoiding several mistakes commonly done in C programs - its templates - for having a built-in GC. And I like other things too: - the idea of having built-in AAs and dynamic arrays - its slicing syntax, partially - how numbers can be written, 0b_0000_0000, 1_000_000, etc. - nestable functions - out/ref parameters - Array bounds checking - aliases - the idea of being module-based - static ifs, static asserts - for having a bit of type inference, instead none at all - the idea of having Contract Programming and built-in unit testing - the idea of having built-in ddoc comments That's why I use D when I can, instead of C++ or Cython. But no language is perfect :-) Bye, bearophile
Aug 28 2008
Reply to Fawzi,And anyhow, just for the sake of knowing it I would like someplace where I can look at it. :)If you know how to read it, the spec is peppered with BNF and that is the authoritative source
Aug 27 2008
Fawzi Mohamed wrote:I was wondering about the precedence of the cast operator. By experimenting I found that it is less than . and more than +, but I was wondering if there isn't a place where this is exactly explained. A table with the precedence of all operators would be welcome :)I just use a C operator precedence table, D follows that: http://www.difranco.net/cop2220/op-prec.htm
Aug 28 2008
On 2008-08-28 18:32:48 +0200, torhu <no spam.invalid> said:Fawzi Mohamed wrote:thanks, I wasn't sure about cast, but it seems that also that follows the C conversion (even with a different syntax). FawziI was wondering about the precedence of the cast operator. By experimenting I found that it is less than . and more than +, but I was wondering if there isn't a place where this is exactly explained. A table with the precedence of all operators would be welcome :)I just use a C operator precedence table, D follows that: http://www.difranco.net/cop2220/op-prec.htm
Aug 29 2008
Fawzi Mohamed wrote:I was wondering about the precedence of the cast operator. By experimenting I found that it is less than . and more than +, but I was wondering if there isn't a place where this is exactly explained. A table with the precedence of all operators would be welcome :) thanks FawziIf you downloaded DMD, you can take a look at src\dmd\expression.c initPrecedences(). I don't paste it here because I don't know if I'm allowed to do so.
Aug 28 2008