Defining functions

A function is an object that gets a number of arguments (the argument list, arglist) as the input, then does something with these values in the function body, and returns none, one, or more value(s). Multiple arguments are separated by commas (,) in an arglist (in fact, they form a tuple, as do the return values; refer to the Tuples section of Chapter 5, Collection Types). The arguments are also optionally typed, and the type(s) can be user-defined. The general syntax is as follows:

function fname(arglist) 
    # function body... 
    return value(s) 
end

A function's argument list can also be empty; in this case, it is written as fname().

The following is a simple example:

# code in functions101.jl function mult(x, y) println("x ...

Get Julia 1.0 Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.