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

GitHub Actions/Runner - Mojo

I created a GH Action that would download and run Mojo here. Unfortunately, even after running modular clean, re-installing, using GITHUB_PATH, running in an Ubuntu container (cause the runners are just containers), and attempting to add mojo to the normal PATH both ways (bash and zsh) it still gives the error mojo: command not found. What am I missing?

Calling mktime from mojo

I'm trying to call C's mktime from mojo but I seem to get a negative number. Here's the code, is the external call correct? mktime returns a time_t which should be a positive int, but I see a negative value. https://github.com/sa-/mo-time/blob/02cf8d1ccdd92ab1ca0863f1538d342d48b18f59/mo_time/date_time.mojo#L73...

Branchless way to convert bool to int?

Right now I do something like
# assuming b is a bool
let x = 1 if b else 0
# assuming b is a bool
let x = 1 if b else 0
...

Exit main

is there an exit function like exit(0)?

Pointer to a custom struct?

Is it possible to create pointers to a custom struct instance, and be able to load the instance from the pointer? According to the AI bot, "Mojo's Pointer struct is designed to work with basic types like Int, and it's not clear if it can directly handle custom structs". Here is my latest attempt (a linked list):...

Gitpod. The better way to run Mojo remotely

Here I will describe my work to configure Gitpod for mojo in the simplest way.
No description

How do I open files to read/write in Mojo?

I want to do the equivalent of the following Python code: ``` with open(file.txt, 'r') as file: x = file.read()...

Is struct inheritance implemented yet?

Can I make a struct inherit from another? For example can I take an Array that allows all types and make an inherited array that specializes in a singular type? What I imagine doing (gets a compiler issue): ```mojo struct Example[T: AnyType]:...

Can I use mojo instead of C++ for MLIR?

For example, can I use mojo to do Toy tutorial from MLIR?

How to store PythonObject in DynamicVector?

I'm trying the following: ``` let module = Python.import_module("my_module") let dv = DynamicVectorPythonObject let result = my_module.my_func()...

Mojo Not Found in CLI

After I installed mojo via modular, it says installed but it's not pre-configured in the environment path.

How do we import and use something like flask

Attempting to replicate this snippet of Flask/Python code in Mojo: ```python from flask import Flask app = Flask(name)...

plans for a net package?

socket or something else or systemcalls

FreeBSD

will there be a release of mojo for #freebsd?

Check types

How to check a type of a variable?
type(x)
type(x)
raises an error
isinstance(1, Int)
isinstance(1, Int)
also raises an error I was only able to print the types using:...
No description

Data type conversion

how can I convert String to StringLiteral?

Error with method append with string

When im try use List for string a get error
fn main() raises:
let list = List[String]()
list.append("123")
fn main() raises:
let list = List[String]()
list.append("123")
...

Python bug

When trying to install it in my Pika OS: ``` brito@AuroraBorealisWorkstation:~$ curl https://get.modular.com | MODULAR_AUTH=[redacted] sh - | distro=pika version=23.04 codename=lunar % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed...

How to use `raises`

What does the raises keyword do for error handling, how do I use it, and what does it returns if the function fails? All I could in the docs was "Both support raising exceptions, but this must be explicitly declared on a fn with the raises keyword." If its for raising exceptions, how do I do this properly?

When (if ever) can we expect arbitrary target support?

In Zig you can choose almost any target triple you need and it works, cross compilation is trivial too. Currently Mojo does not allow this, rejecting most targets - is this just a temporary limitation or is every target going to require patches to the compiler like Swift? Rust is also not that great here requiring installation of a separate toolchain for each target if I remember correctly.