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

AoC: Surprising interpretation of a^b .f vs f a^b. #4556

Open
fridis opened this issue Dec 27, 2024 · 0 comments
Open

AoC: Surprising interpretation of a^b .f vs f a^b. #4556

fridis opened this issue Dec 27, 2024 · 0 comments
Labels
enhancement New feature or request front end related to the front end until .fum file is created: call and type resolution, type checking, etc. Fuzion language related to the language, syntax, etc

Comments

@fridis
Copy link
Member

fridis commented Dec 27, 2024

Stumbled over this during one of the Advent-Of-Code puzzles, but did not have time to create an issue immediately:

See this example

test_calltail is

  a := "a"
  b := "b"

  Any.f      => "({Any.this}.f)"
  Any.f(a)   => "({Any.this}.f $a)"
  f(x)       => "(f $x)"
  f(x,y)     => "(f $x $y)"

  String.prefix ^ => "(^{String.this})"
  String.infix ^(b String) => "({String.this}^$b)"

  say " 1. a^b.f   : {a^b.f}"
  say " 2. a^b .f  : {a^b .f}"
  say " 3. a ^ b.f : {a ^ b.f}"
  say " 4. a ^ b .f: {a ^ b .f}"
  say " 5. (a^b).f : {(a^b).f}"
  say " 6. (a^b) .f: {(a^b) .f}"
  say " 7. a.f^b   : {a.f^b}"
  say " 8. a.f ^ b : {a.f ^ b}"
  say " 9. a.f ^b  : {a.f ^b}"
  say "10. f a^b   : {f a^b}"
  say "11. f a ^ b : {f a ^ b}"
  say "12. f a ^b  : {f a ^b}"

Which produces quite intuitive evaluation order for most cases:

 > ./build/bin/fz test_calltail.fz
 1. a^b.f   : (a^(b.f))
 2. a^b .f  : (a^(b.f))
 3. a ^ b.f : (a^(b.f))
 4. a ^ b .f: (a^(b.f))
 5. (a^b).f : ((a^b).f)
 6. (a^b) .f: ((a^b).f)
 7. a.f^b   : ((a.f)^b)
 8. a.f ^ b : ((a.f)^b)
 9. a.f ^b  : (a.f (^b))
10. f a^b   : (f (a^b))
11. f a ^ b : ((f a)^b)
12. f a ^b  : (f a (^b))

The case that I found surprising is number 2., especially when compared to number 10. I think we should change the parser to parse a^b .f as (a^b).f.

Related to this, we might produce an error for code like 1+2 * 3 where the spacing disagrees with the operator precedence.

@fridis fridis added enhancement New feature or request Fuzion language related to the language, syntax, etc front end related to the front end until .fum file is created: call and type resolution, type checking, etc. labels Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request front end related to the front end until .fum file is created: call and type resolution, type checking, etc. Fuzion language related to the language, syntax, etc
Projects
None yet
Development

No branches or pull requests

1 participant