42 questions
0
votes
0
answers
44
views
Why does SIMD[DType.bool, 4](True, False, True) give unexpected reduce_bit_count() results in Mojo?
I'm investigating the method reduce_bit_count() from Mojo's SIMD API.
According to the documentation:
Returns the total number of bits set in the SIMD vector.
I expected the following behavior:
3 ...
0
votes
0
answers
47
views
How to sort a List in Mojo?
sort() can be used on lists of integers without further ado.
But if I define my own type, which trait shall I implement on it so that lists made of it can be sorted?
@value
struct MyStruct(...
2
votes
1
answer
96
views
Magic fails to install Mojo dependencies
I cannot use the Mojo dependency called lightbug_http in a fresh Mojo project.
magic init hello_web --format mojoproject
cd hello_web
magic shell
Printing «Hello world» works fine.
Then I add https://...
0
votes
1
answer
104
views
String literals, List Literals and let statements not working as expected with Mojo 24.4.0
I am new to Mojo and just started learning the language. I am practicing some code on my Jupyter notebook in my Mac mini. My Mojo version is 24.4.0
CASE1:
The below simple code for ListLiterals gives ...
1
vote
1
answer
528
views
How can I write asynchronous code in mojo? ("Coroutine not copyable")
How can I implement asynchroneous code in mojo (using async etc.)?
In the Changelog, I find the following example (slightly adjusted):
async fn add_three(a: Int, b: Int, c: Int) -> Int:
return ...
3
votes
0
answers
596
views
Can not connect VSCode to WSL2 running Ubuntu-22.04
I am setting up a test environment to try the MOJO language in my Windows 11 Pro laptop (V 10.0.22631 Build 22631). Since MOJO doesn't have a Windows SDK available (yet), I installed WSL2 using ...
1
vote
0
answers
31
views
Is there a way to load a memory-only pointer type
I'm trying to write a solution to a problem I found online using Mojo. The problem is a graph theory related so I wanted to implement the data structure by hand to get more familiar with the language.
...
1
vote
1
answer
131
views
How to define overloaded function in MOJO language?
The code below fails.
fn greet(n: Bool) -> String:
return "Hello, 2!"
fn greet(name: String) -> String:
return "Hello, " + name + "!"
fn main():
...
0
votes
1
answer
75
views
Cannot return a struct implementing a trait in a function
I have this code :
trait State:
fn to_string(self) -> String:
...
struct StateTtt(State):
fn __init__(inout self):
pass
fn to_string(self) -> String:
...
0
votes
1
answer
143
views
Does eval() have performance advantage in Mojo vs. Python?
I would like to use eval() for validation of short function synthesis. The search space may be fairly large, e.g. more than a million different functions. Functions will be synthesized as a string ...
0
votes
1
answer
498
views
Issue using Python.import_module to import python numpy package in Mojo
I've just started learning Mojo, following the documentation to get started. I've run into a problem with importing the Python module numpy. Below is the code I am using which is taken from the ...
0
votes
2
answers
129
views
How do I do a typedef in mojo?
I want to implement a class with a property whose type I can change globally at compile time.
For example,
let ID_TYPE = Int
@value
struct MyStruct:
var a: ID_TYPE
However, let seems not to be ...
0
votes
1
answer
182
views
Pass arguments to a Python module in Mojo?
I have a python module : myScript.py.
Normally, I run it like this
python3 myScript.py -i example.jpg
I want to pass this argument to this python modules's main function
from python import Python
fn ...
0
votes
1
answer
225
views
installed mojo programming language but finding a repeating command when executed
I've installed mojo on my compute : and went to ran the code 'nano__.zprofile'
previously when downloading modular/mojo I ve got network issue, couple of times so I've done it multiple times
Now when ...
1
vote
1
answer
211
views
Mojo (Mac) using wrong python lib
As most Mac users, I have two separate versions of python on my machine: The one installed by Apple (version 3.9 in /usr/bin) and one installed via Homebrew (version 3.11 in /opt/homebrew/bin).
I've ...