Georgery
Georgery

Reputation: 8127

Vectorizing Dot before or after the Function Name?

I can vectorize a function using the dot notation:

a = Vector(0:10) .* 4 

As in plenty of examples I read the dot comes prior to the asterisk. However, this does not work in the following case:

Complex.(a,a)

Here the dot suddenly goes behind the function name.

Is this intended? And is there a rule?

Upvotes: 5

Views: 467

Answers (1)

carstenbauer
carstenbauer

Reputation: 10157

For functions, the dot always goes behind the function name.

For operators, like * or + for example, the dot goes before the operator. However, you can enclose the operator in parentheses and suffix the dot.

To make this difference even more explicit, consider this example where we apply "multiply" with function call syntax:

x = rand(2,2)
sqrt.(x)
.*(x,x)
(*).(x,x)
x .* x

The last three commands all do the same thing.

See the corresponding sections of the Julia documentation for more: Dot Syntax for Vectorizing Functions and Vectorized "dot" operators.

Upvotes: 9

Related Questions