overturetool / overture

The Overture Tool
http://overturetool.org
GNU General Public License v3.0
49 stars 25 forks source link

Operator precedence #702

Closed ivor-spence closed 4 years ago

ivor-spence commented 4 years ago

Description

Order of evaluation of multiple relations is right to left. I am not sure if this is deliberate - the language definition seems to ignore this possibility.

Steps to Reproduce

In the quick interpreter type

print 3 = 3 = true

Expected behavior: [What you expect to happen]

A response of "true"

Actual behavior: [What actually happens]

Error 3087: Left and right of '=' are incompatible types in 'DEFAULT' (console) at line 1:3

However print true = 3 = 3 gives "true". The right hand "=" is evaluated first.

Reproduces how often: [What percentage of the time does it reproduce?]

Every time

Versions

Version 2.5.4 on Windows

Additional Information

So A = B = C is treated as A = (B = C) whereas 4 - 2 - 2 is treated as (4 - 2) - 2

nickbattle commented 4 years ago

Interesting observation :) I would normally call this operator associativity, but the Language Ref Manual calls it "Grouping", and it is defined in section C.7.

The "=" operator is in the family "Relations" and C.7 states that there is "No grouping". In C.4 it says, "Typing dictates that there is no meaningful way of using them adjacently." Yet your example is clearly a meaningful way, when comparing booleans. Evidently the parser chooses right grouping in this case (it has to group somehow, but I'm not sure this is wrong).

The "-" operator (your other example) is in the family "Evaluators" and these are stated to have left grouping, which your example confirms.

I tried your two "=" examples in the VDMTools command line, but both of them give an error. VDMTools has left grouping for the "-" operator.

So I'm not sure whether this is a problem or not. Any other views on this?

ivor-spence commented 4 years ago

Nick,

Thanks for your response, it’s clearly not a major issue. As you say the problem is really that there is no stated grouping for relations, in fact there is a statement that none is needed, where clearly there is a need. I suppose I thought it would have been more consistent for it to group to the left.

I am using the software to teach some discrete maths to first year students and am trying to emphasise that there are clear rules which need to be followed as instinct can lead us astray. My favourite example is

false and false = false and false

which (correctly but counter-intuitively) evaluates to false.

So as long as I them that relations group to the right I suppose that’s ok.

Another thing missing in the language definition I think is that exponentiation () is not listed in any operator family although I would expect it to be an Evaluator. It groups to the right in Overture, which is the standard mathematical interpretation. E.g. 223 = 2(2**3).

Sorry for reporting this as a bug but I was trying to be sure that I understood what was happening.

Best wishes,

Ivor

From: Nick Battle notifications@github.com Sent: 02 October 2019 14:53 To: overturetool/overture overture@noreply.github.com Cc: Ivor Spence I.Spence@qub.ac.uk; Author author@noreply.github.com Subject: Re: [overturetool/overture] Operator precedence (#702)

Interesting observation :) I would normally call this operator associativity, but the Language Ref Manual calls it "Grouping", and it is defined in section C.7.

The "=" operator is in the family "Relations" and C.7 states that there is "No grouping". In C.4 it says, "Typing dictates that there is no meaningful way of using them adjacently." Yet your example is clearly a meaningful way, when comparing booleans. Evidently the parser chooses right grouping in this case (it has to group somehow, but I'm not sure this is wrong).

The "-" operator (your other example) is in the family "Evaluators" and these are stated to have left grouping, which your example confirms.

I tried your two "=" examples in the VDMTools command line, but both of them give an error. VDMTools has left grouping for the "-" operator.

So I'm not sure whether this is a problem or not. Any other views on this?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/overturetool/overture/issues/702?email_source=notifications&email_token=AI2B2YKZDIB3HKI4UZI6XVLQMSRSXA5CNFSM4I4WFI4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAE2FGQ#issuecomment-537502362, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AI2B2YM2W4MOZBPYTFPZCYLQMSRSXANCNFSM4I4WFI4A.

nickbattle commented 4 years ago

We're always perfectly happy to have problems reported, even if they really just need more clarification in the Language Ref Manual!

Exponentiation is curious, I agree: it's treated the same as the "iterator" operator for maps and functions, which is therefore in the Combinators family and has right-associativity. It would intuitively belong in the Evaluators (and so be left-associated), but ... it's not.

I'll raise both issues in the Language Board with a view to making things clearer in the LRM.

ivor-spence commented 4 years ago

Nick,

Raising it with the Language Board would be good but I would suggest that the current right-associativity for exponentiation is actually what it should be, even if this has been a happy accident in the language. I think the mathematical convention is

[cid:image001.png@01D579E2.34DDAB50]

From: Nick Battle notifications@github.com Sent: 02 October 2019 20:41 To: overturetool/overture overture@noreply.github.com Cc: Ivor Spence I.Spence@qub.ac.uk; Author author@noreply.github.com Subject: Re: [overturetool/overture] Operator precedence (#702)

We're always perfectly happy to have problems reported, even if they really just need more clarification in the Language Ref Manual!

Exponentiation is curious, I agree: it's treated the same as the "iterator" operator for maps and functions, which is therefore in the Combinators family and has right-associativity. It would intuitively belong in the Evaluators (and so be left-associated), but ... it's not.

I'll raise both issues in the Language Board with a view to making things clearer in the LRM.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/overturetool/overture/issues/702?email_source=notifications&email_token=AI2B2YLIHXU5GQYDCVGU3LDQMT2LPA5CNFSM4I4WFI4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAF5WJA#issuecomment-537647908, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AI2B2YKFGXOGCP67U3ADDADQMT2LPANCNFSM4I4WFI4A.

tomooda commented 4 years ago

Hi,

Just FYI. I checked VDMTools and ViennaTalk, and the both parse the ** operator right-associative likewise to VDMJ/Overture.

Best Regards,

tomo

2019年10月3日(木) 20:01 ivor-spence notifications@github.com:

Nick,

Raising it with the Language Board would be good but I would suggest that the current right-associativity for exponentiation is actually what it should be, even if this has been a happy accident in the language. I think the mathematical convention is

[cid:image001.png@01D579E2.34DDAB50]

From: Nick Battle notifications@github.com Sent: 02 October 2019 20:41 To: overturetool/overture overture@noreply.github.com Cc: Ivor Spence I.Spence@qub.ac.uk; Author author@noreply.github.com Subject: Re: [overturetool/overture] Operator precedence (#702)

We're always perfectly happy to have problems reported, even if they really just need more clarification in the Language Ref Manual!

Exponentiation is curious, I agree: it's treated the same as the "iterator" operator for maps and functions, which is therefore in the Combinators family and has right-associativity. It would intuitively belong in the Evaluators (and so be left-associated), but ... it's not.

I'll raise both issues in the Language Board with a view to making things clearer in the LRM.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub< https://github.com/overturetool/overture/issues/702?email_source=notifications&email_token=AI2B2YLIHXU5GQYDCVGU3LDQMT2LPA5CNFSM4I4WFI4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAF5WJA#issuecomment-537647908>, or mute the thread< https://github.com/notifications/unsubscribe-auth/AI2B2YKFGXOGCP67U3ADDADQMT2LPANCNFSM4I4WFI4A>.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/overturetool/overture/issues/702?email_source=notifications&email_token=AAGMFVCULLCZWBS6FTUDCV3QMXGITA5CNFSM4I4WFI4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAH2O6A#issuecomment-537896824, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGMFVHVCO3WJNXGVQ6VODDQMXGITANCNFSM4I4WFI4A .

nickbattle commented 4 years ago

The issue was raised at the LB meeting today and a suggestion has been made for additional explanation to add to section C.7 about grouping.

nickbattle commented 4 years ago

The LRM change has now been made, and will be included in the next release. Closing.