Should a ! function return anything?

Viewed 73

In the style guide it says that functions that modify their arguments should be marked with a !. However in the example given the function double! returns the modified argument a. Why return it if it has already been modified? Is it necessary?

1 Answers

It doesn't cost anything and enables you do things like:

b = double!(a)*x

or

double!(double!(a))

in a single line if you needed to.

For that reason (i.e. convenience), it has become convention.

Related