Julia: error with one-liner long-form function definition returning a tuple litteral

Created on 12 Apr 2019  路  2Comments  路  Source: JuliaLang/julia

It seems this should work:

julia> function f(x, y) (x, y) end
ERROR: syntax: space before "(" not allowed in "f(x, y) ("

Of course, removing the space is not the solution here!

julia> function f(x, y)(x, y) end
ERROR: syntax: invalid function name "f(x, y)"

The same happens with array litterals too.

bug parser

Most helpful comment

I think this error is ok for now, because function f(x)(y) is actually sensible syntax for defining a curried function, i.e. f(x)(y) = 0 means f(x) = y -> 0. We could make that work instead.

All 2 comments

I think this error is ok for now, because function f(x)(y) is actually sensible syntax for defining a curried function, i.e. f(x)(y) = 0 means f(x) = y -> 0. We could make that work instead.

It definitely is not urgent to fix this. But even with a new curried function definition syntax, this is still distinct from the reported error here, which involves a space. I think I prefer two close syntaxes (with/without space) meaning different things than a special case (preventing a parenthesised expression as the body of a function defined like in the OP).

Was this page helpful?
0 / 5 - 0 ratings