Allowing the object.method(args...) syntax as an alias for method(object, args ...)

Yes, of course, clarity is relative, not only to people, but also to conventions of programming languages. In pretty much any language that accepts the syntax x.f(y), it means taking a field f from object x and applying it to y. In Python, this field is also called method, which is a function in which x is curried as its first argument, but that is detail. E.g.:

# python3
Python 3.9.5 (default, May 11 2021, 08:20:37) 
>>> func = "abcdefghij".replace
>>> func('a', '1')
'1bcdefghij'

So, the syntax the OP is proposing would be confusing to Julian users and to newcomers. Because, in Julia, methods are not fields and Strings don’t have a field called replace.

Now, the syntax x⤷f(y) is not confusing and it could be made clear and consistent. However, you need to remember the shortcut for ‘⤷’, which requires more than one char. Another problem is it’s not flexible - if you want to apply map and friends to collections, you would need to specify that the incoming object is the second or third argument of your method, so you would need some marker to specify in which place the object is curried - like _.

In the end of the day, vec⤷map(sqrt, _) and vec |> map(sqrt, _) requires that you type around the same number of chars, but the latter contains only one new syntax to understand - and that new syntax is useful in much more contexts than chaining.

12 Likes