Return (; a, b )

This is the last line of a function. What does the ; mean here? I know

return (a,b)

is to return a tuple. But what does

return (; a,b)


1 Like

It returns a NamedTuple. The syntax is sugar for return (; a=a, b=b).


As ever, the help is your friend:

elp?> ;
search: ;


  ; has a similar role in Julia as in many C-like languages, and is used to delimit the end of the previous statement.

  ; is not necessary at the end of a line, but can be used to separate statements on a single line or to join statements into a single expression.

  Adding ; at the end of a line in the REPL will suppress printing the result of that expression.

  In function declarations, and optionally in calls, ; separates regular arguments from keywords.

  In array literals, arguments separated by semicolons have their contents concatenated together. A separator made of a single ; concatenates vertically (i.e. along the first dimension), ;; concatenates horizontally (second dimension),
  ;;; concatenates along the third dimension, etc. Such a separator can also be used in last position in the square brackets to add trailing dimensions of length 1.

  A ; in first position inside of parentheses can be used to construct a named tuple. The same (; ...) syntax on the left side of an assignment allows for property destructuring.

  In the standard REPL, typing ; on an empty line will switch to shell mode.

(second to last paragraph)


(You are apparently running Julia in London? Why can’t the English learn to speak?)


I’ve clearly been here for too long (I actually do live in an area that traditionally would have been considered to be within earshot of the Bow Bells so my children are technically cockneys and do drop letters!)