r/ProgrammingLanguages • • Apr 10 '26

Borrow-checking surprises

https://www.scattered-thoughts.net/writing/borrow-checking-surprises
52 Upvotes

27 comments sorted by

View all comments

Show parent comment

3

u/ExplodingStrawHat Apr 11 '26

Why does it break? Wouldn't the chained methods desugar to baz(bar(foo, a()), b())? If arguments are evaluated from right to left then this would evaluate b() first, then a(), then foo, then bar(...), then baz(...). Is this not what one would expect?

1

u/Uncaffeinated 1subml, polysubml, cubiml Apr 12 '26

I think most people would expect foo.bar(a()) to be evaluated before b(). And they would certainly expect a() to be evaluated before b().

1

u/ExplodingStrawHat Apr 12 '26

If given no additional information, then sure. All I'm saying is that this could be a consistent way to design a language, with method chaining not really contradicting anything. I don't think it would be super surprising as long as the language's learning material was to explain this early on. I mean heck, most of the Haskell code I write evaluates from right to left.