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
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.
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]:...
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)...
Check types
How to check a type of a variable?
raises an error
also raises an error
I was only able to print the types using:...
type(x)
type(x)
isinstance(1, Int)
isinstance(1, Int)
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.
Will Mojo be a "true" systems programming language?
Will you be able to create things like device drivers or even operating systems like you can in Rust?
Will imported python modules eventually be compiled by Mojo instead of relying on the python env?
I understand that currently imported python packages run on the CPython interpreter which will require a compiled Mojo program to run with the same python environment in which it was complied (same installed packages etc).
Will the need for this go away once Mojo is a true superset of Python. IOW, will the imported python module get complied just as if the Python code was written directly in the Mojo program?...