Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

precedence of logical operators #39

Closed
dram opened this issue Oct 27, 2015 · 6 comments
Closed

precedence of logical operators #39

dram opened this issue Oct 27, 2015 · 6 comments

Comments

@dram
Copy link
Contributor

dram commented Oct 27, 2015

In DRM, & and | have same precedence. Open Dylan is confirm to DRM, but in Mindy & has higher precedence, as specified in compiler/info.c.

For example, Open Dylan and Mindy show different result for following code:

format-out("('a' | 'b') & 'c' => %s\n", ('a' | 'b') & 'c');
format-out("'a' | ('b' & 'c') => %s\n", 'a' | ('b' & 'c'));
format-out("'a' | 'b' & 'c' => %s\n", 'a' | 'b' & 'c');

Mindy:

('a' | 'b') & 'c' => c
'a' | ('b' & 'c') => a
'a' | 'b' & 'c' => a

Open Dylan:

('a' | 'b') & 'c' => c
'a' | ('b' & 'c') => a
'a' | 'b' & 'c' => c

Curious that why Dylan is designed to have same precedence for & and |, which is different to many other languages.

@waywardmonkeys
Copy link
Member

I wonder if any Dylan code contained within Mindy relies upon this.

@wvdschel
Copy link
Contributor

One way to find out?

On 29 October 2015 15:07:40 CET, Bruce Mitchener notifications@github.com wrote:

I wonder if any Dylan code contained within Mindy relies upon this.


Reply to this email directly or view it on GitHub:
#39 (comment)

Sent from my Android device with K-9 Mail. Please excuse my brevity.

@waywardmonkeys
Copy link
Member

@dram Have you tried fixing this and seeing what happens?

@dram
Copy link
Contributor Author

dram commented Oct 31, 2015

I'm a bit busy recently, do not have time to inspect whole Mindy codebase for usages of logical operators. If someone can help out, please go ahead.

@waywardmonkeys
Copy link
Member

A quick grep finds:

libraries/regular-expressions/interface.dylan:      if (~substring-start | (count & (count <= string-number)))
libraries/string-extensions/character-type.dylan:  (c >= 'a' & c <= 'z')  |  (c >= 'A' & c <= 'Z');
libraries/string-extensions/character-type.dylan:  (c >= 'a' & c <= 'z')  |  (c >= 'A' & c <= 'Z')  |  (c >= '0' & c <= '9');
libraries/string-extensions/character-type.dylan:  (c >= '0' & c <= '9')  |  (c >= 'a' & c <= 'f')  |  (c >= 'A' & c <= 'F');
mindy/dbmc/header.dylan:                  | ('A' <= char & char <= 'Z')
mindy/dbmc/header.dylan:                  | ('0' <= char & char <= '9')
mindy/dbmc/header.dylan:              | ('A' <= char & char <= 'Z'))
mindy/dbmc/lexer.dylan:          elseif ((char == '\n' | char == '\r') & posn > lexer.line-start)
mindy/dbmc/lexer.dylan:          elseif ((char == '\n' | char == '\r') & posn > lexer.line-start)
mindy/dbmc/lexer.dylan:          elseif ((char == '\n' | char == '\r') & posn > lexer.line-start)
mindy/dbmc/lexer.dylan:          if ((char == '\n' | char == '\r') & posn > lexer.line-start)
tests/dylan-test.dylan:  (#t & #t)                        | signal("#t & #t is not true!\n");
tests/dylan-test.dylan:  (#f | #f)                        & signal("#f | #f is not false!\n");
to-be-migrated/common-dylan/format.dylan:            | (str[start] = '0' & str[start + 1] = 'x')))
to-be-migrated/file-system/helpers.dylan:  size(ans) > 0 & (ans[0] = 'Y' | ans[0] = 'y')
to-be-migrated/locators/locators.dylan:            | (base & base ~== $unsupplied)
to-be-migrated/locators/locators.dylan:            | (extension & extension ~== $unsupplied))
to-be-migrated/tests/streams.dylan:                  & (~test-function-direction | test-function-direction == #"input");
to-be-migrated/tests/streams.dylan:                  & (~test-function-direction | test-function-direction == #"output");
tools/melange/c-decl.dylan:  decl.map-type | (~explicit-only? & decl.type-name);
tools/melange/c-decl.dylan:      | (~explicit-only? & decl.type-name);
tools/melange/c-decl.dylan:    decl.map-type | (~explicit-only? & decl.type-name);
tools/melange/c-decl.dylan:    | (~explicit-only? & decl.type-name);
tools/melange/c-decl.dylan:  decl.map-type | decl.type.map-type | (~explicit-only? & decl.type-name);
tools/melange/c-decl.dylan:    | (~explicit-only? & decl.type-name);
tools/melange/c-lexer-cpp.dylan:          & (empty?(rest) | head(rest) == #"accept"))
tools/melange/c-lexer-cpp.dylan:          & (empty?(rest) | head(rest) == #"accept")
tools/melange/c-lexer.dylan:             | ~(whitespace?(contents[i]) & contents[i] ~== '\n')))
tools/melange/c-lexer.dylan:    if (pos = contents.size | (cpp-line & contents[pos] == '\n'))

I think that it is safe to fix this bug.

dram added a commit to dram/mindy that referenced this issue Nov 1, 2015
* mindy/compiler/info.c
  (init_info): According to DRM, `$` and `|` have same precedence
  and both are left-associative. Fixes dylan-hackers#39.
@dram
Copy link
Contributor Author

dram commented Nov 1, 2015

Just find that actually both precedence and association are incorrect. This bug is quite anonying, hope that no code rely on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants