Modular

M

Modular

This server is the home of the MAX and Mojo community. Join us to chat about all things Modular!

Join

questions

community-showcase

Posix compliant Mojo Shell?

Will Mojo have a shell like Python? If yes will it be Posix compliant? I was wondering if I can replace Bash or Zsh or Powershell on my computer with Mojo's speedy shell? It would be amazing if that's the case....

Compiling a dynamic/static library

Hi! Is there a way to compile a mojo file into a static or dynamic library to be linked to a c++ project? I see this thread from a while ago https://github.com/modularml/mojo/discussions/303, but still couldn’t find any information on how to actually compile one....

How Unsafe/Safe is this code?

I needed a way to store lists of data of different types in a list, so I have created a list like type that can store any type that conforms to CollectionElement. It works well and doesn't have any memory errors, but I wanted to get a second opinion on if it seems safe enough to use. One issue it has is that I can't check the type when you append or get from it since it does not store type info. Currently I just store the types size and compare to that. ```python simple example:...

How can I see the peak memory usage of a datastructure like alist in mojo?

I want to compare the memory usage of python and mojo. For python I use the memory profiler pip package. How can I get the accurate memory consumption of a list or other structure in mojo?...

Mojo documentation says "The Mojo compiler uses lifetime values to track the validity of references.

Specifically, a lifetime value answers two questions:What logical storage location "owns" this value?Can the value be mutated using this reference? If so, why call it as lifetime? Rather call it as 'refscope' or 'reftype' or something like that. the term 'lifetime' i think confusing when used to describe a reference. Or is there any reason which I'm missing. May be my understanding is limited, I'm pretty new to this. Thanks....

Using Mojo For Back-end Web Development

Hi, I am trying to build something like hacker rank online. Is it possible to do this using mojo? Is it possible to build the back-end of a website using mojo? Apologies if this is a naive question - I’m just starting out as a developer in my free time

What pointer lifetime to use when iterating through a tree?

I've created a tree data structure: ``` struct BKTree: var root: Optional[BKTreeNode] ...

Error when running Mojo when path contains # (hash)

Since the introduction of Magic I have noticed that previous mojo scripts would give me an error when running "magic run mojo hello.mojo". Even using "magic shell" and then "mojo hello.mojo" does not solve the problem. The files are contained in a path where one of the folders starts with a #. When running mojo I get the following error: /home/user/Documents/#MojoProjects/hello-world/.magic/envs/default/bin/mojo: error: cannot map file that is not an actual file or block device ...

Canonical way to add NuMojo to a Mojo project?

Looking at the NuMojo documentation there are directions for building a Mojo packages and making it visible to a Mojo project. Is there a "canonical" way of adding multiple packages like NuMojo to an existing Mojo project? I'm thinking of having a project/vendor or project/lib directory to host these external packages.

Preserving mutability when passing to function

How to make pointer passed to a function preserve/transmit its mutability? ``` var a_instance = A(12) var ref_a = Pointer.address_of(a_instance) ...

Python integration: address not mapped to object

I wrote the below simple python code at jupyter notebook for stamping my pdf documents: ```python import fitz # PyMuPDF def add_signature(input_pdf, output_pdf, signature_image, x, y, stamp_width, stamp_height): doc = fitz.open(input_pdf)...

Creating files from code

Is there a way to create a file from code? I've tried using a python script: ```python def create_proj(path: str): with open(path + "/main.mojo", "x") as f: f.write("text goes here")...

Pyserial-like communication in Mojo

Hi) Trying to port a FFT realtime audio signal visualiser in Mojo. Decided to reimplement most of my imports that were used in the python. However! I do not see any stdlib support for serial communication. no class, etc. So I decided to import it from a foreighn language: saw an example of C++ header import in the roadmap. Instructions unclear, can i use c++ based compiled *.so, or not?...

dict containing sets?

I'm having issuesto have a dict whose values are sets first, Set doesn't implement copyinit so I had to wrap it but now I get that rag[current_label] is a "function that might raise in a context that cannot" what's the simplest way to build a dict whose values are sets? can I operate on the sets? ...

Could Mojo be the first all purpose language?

All languages have their own strengths and weaknesses, which is why we have so many — to cover all our bases. I'm wondering if Mojo could realistically become an "all-purpose" language — not as the default for every use case, but as a strong contender in every domain. In my mind, there are 3 core requirements for a language to be truly all-purpose: Speed — to ensure performance-critical cases don't default to C/C++/Rust. Safety — to prevent Rust from being the go-to in security-sensitive environments....

modifying runtime value from @parameter scope crashes the compiler

This is probably not an allowed operation, should there be a different error? ``` fn cmd_unchecked(args: Tuple) raises -> UnixSocket: alias args_len = type_of(args).len__() ......

Segfault when `Tuple.get()` rebinds

```py fn cmd_unchecked(args: Tuple) raises -> UnixSocket: buf = ListByte buf.size = 4 ...

why does this String init work without len?

buf = InlineArray[UInt8, 640](0)
...
s = String(buf.unsafe_ptr())
buf = InlineArray[UInt8, 640](0)
...
s = String(buf.unsafe_ptr())
...

Global variable support?

Hello! I know there’s an open issue on GitHub for tracking global/file scoped variable support, but is there any high level estimate when it might come? It would helpful to understand if that’s a topic that’s to be broached in the short/mid/long term or if it’s unplanned as of now. A lot of the projects I’m working on would benefit from them. So, I’m curious if this is a “maybe in 6 months” kind of thing or potentially years down the road....

why is this return a copy?

```py @value struct UnixSocket: var address: Optional[UnixAddress] var fd: Int32...