Bug or Not a bug?

This came on slack raised by Ryan

 > ( _ * 4 + 1)  50
 > ( 50 * 4 + 1)
  • Bug
  • Not a bug

0 voters

1 Like

If you know how operator sections work then it’s obvious it isn’t a bug. Seems to me that a bit more studying solves this easily.

(_ * 4 + 1) is the same as \s -> s * (4 + 1) because operator sections are defined only for binary operators so (_ * 4 + 1) is just sugar for (_ * (4 + 1)).

I guess maybe there’s a point to be made that the language shouldn’t allow constructs like (_ * 4 + 1) so it isn’t confusing.


I voted for non-bug because the standard anonymous way of doing things, \x-> x*4+1, works as expected, and the ambiguous _ notation will show its limit, no matter how many rules are chosen to describe its behavior. Keep it for very simple sections, it will also ease the reading.

1 Like

I don’t think it’s obvious that it isn’t a bug, personally. I can see how this behaviour is arising and the behaviour is in line with the way this feature was originally intended to work, but at the same time I think it’s surprising enough that you can argue it’s a bug in the spec itself. Maybe the more interesting question is “what, if anything, should we do about it?”


I think it’s a bug. I would expect it to raise an error because + has lower precedence than *. Sections should only allow operators at the same or greater precedence level.


That’s a good point, I didn’t think about precedence rules. So that means that something like this examples shouldn’t in fact be allowed by the language right? And proper parenthesis should be used: (_ + (4 + 1)) otherwise error.


Well I think anonymous functions or operator section (not sure what their formal name is)
do look nice in a map operation
I would rather we fix the precedence rules, if at all possible
If for some technical reason or for backward compatibility we can not

Yes disallow it, compared to surprises or incidental complexity
disallowing it sound better

We already have the error message for it

An anonymous function argument appears in an invalid context.

Got it from

(2 + 3 + _) 2
Error found:
at :0:0 - 0:0 (line 0, column 0 - line 0, column 0)

  An anonymous function argument appears in an invalid context.
1 Like

I didn’t even think that was valid syntax. What are the rules that distinguish between (_ * 4 + 1) (okay) and (2 + 3 + _) (error)?


I think the rule is that after rebracketing (applying precedence rules), an operator section is only valid if the _ is an immediate operand on the left or right hand side (but not both).