Likan Zhan
Likan Zhan

Reputation: 1076

What does this syntax mean: `function (YOLO) ....`

What does the code mean, and how to invoke it?

function (YOLO)
    YOLO + 1
end

Quoted from here.

Thanks

Upvotes: 1

Views: 62

Answers (1)

Sundar R
Sundar R

Reputation: 14705

It's an Anonymous function.

The usual way to use them is to either assign it to a variable, which would become the function's name:

julia> y = function (YOLO)
           YOLO + 1
       end
#43 (generic function with 1 method)

julia> y(4)
5

or pass the function itself directly as an argument to a different function (though for that, the shorter YOLO -> YOLO + 1 or the do ... end syntaxes are usually used).

Another way to invoke it is to just immediately call it:

julia> (function (YOLO)
           YOLO + 1
       end)(43)
44

Upvotes: 3

Related Questions