Segmentation Fault, Got Object when returning a Float
mojo test.🔥
/mnt/d/Projects/QUk.YW5k.TUw/Cartoonify/test.🔥:18:32: error: cannot implicitly convert 'object' value to 'FloatLiteral' in assignment
pi = monte_carlo_simulation(10)
~~~~^~
mojo: error: failed to parse the provided Mojo
7 Replies
This resulted in
I am new to mojo, started yesterday so i dont know much
You hav ea type mismatch when assigning
pi = monte_carlo_simulation(10)
. When you initially set pi
to 0
, mojo will infer the type as FloatLiteral
and expect the variable to always hold that type. The type returned from monte_carlo_simulation
is an object
. Anything returned from a python function is an object
I believe.
The fix is just to use let pi = monte_carlo_simulation(10)
and remove the var pi
line. That way it is inferring the correct type for your return value.Ok but the segmentation fault?
Oh wait a new one
I used to build it previously
Now i just ran it instead
I think the fix I provided is all that is needed for the code you provided. It runs on my machine with output of 3.20 after asking me to input a number of iterations. So if problems persist for you, I would try reinstalling Mojo.
Oh
I am using windows, wsl
Maybe thats why?
Maybe. I am on a Macbook. But I think Windows via WSL should work. Are you using WSL 1 or WSL 2? Their is a comment in the docs to prefer 2.
GitHub
mojo/docs/roadmap.md at 700bc916fb6db60a5c1ad565c47c9d2dc49abd02 · ...
The Mojo Programming Language. Contribute to modularml/mojo development by creating an account on GitHub.
Ws; 2