Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MethodError: objects of type Float64 are not callable

Tags:

julia

I made a function to find the volume of a sphere:

function volume_sphere(r)
  (4/3)(round(π, sigdigits=6))(r)^3
end

julia> println(volume_sphere(5))

I got this error message:

ERROR: MethodError: objects of type Float64 are not callable
Stacktrace:
[1] volume_sphere(::Int64) at C:\Users\Practice.jl:27
[2] top-level scope at none:0

Where is the issue coming from?

like image 872
nominalize Avatar asked May 19 '19 19:05

nominalize


2 Answers

This problem is explained in detail here.

In short you are not allowed to omit * in juxtaposition of two parenthesized expressions, nor when placing a variable before a parenthesized expression. Therefore this is a valid code:

4/3*round(π, sigdigits=6)*r^3

But you could write e.g. 2r+3(r^2+1)r and it would be a valid line of code.

like image 195
Bogumił Kamiński Avatar answered Nov 17 '22 13:11

Bogumił Kamiński


function volume_sphere(r)

 (4/3)*(round(π, sigdigits=6))*(r^3)

end
like image 1
nominalize Avatar answered Nov 17 '22 15:11

nominalize