gabrieldemarmiesse
gabrieldemarmiesse
MModular
Created by Caroline on 9/5/2024 in #community-showcase
Modverse #42 is out!
Are the nightlies available in magic or not yet? It's to work on the stdlib
13 replies
MModular
Created by mrrational on 8/2/2024 in #questions
How to overload methods of generic structs to target particular types
that's the only solution I could find while we wait for a proper solution in the language
6 replies
MModular
Created by mrrational on 8/2/2024 in #questions
How to overload methods of generic structs to target particular types
The only way I found currently is to pass an additional parameter and do a bitcast. See https://github.com/modularml/mojo/pull/3349 which does this
6 replies
MModular
Created by Frank Saez on 6/12/2024 in #questions
FFI
It's basically mapping those operations: https://mlir.llvm.org/docs/Dialects/IndexOps/ to dunder methods, while being careful to use the unsigned operations whenever available
16 replies
MModular
Created by Frank Saez on 6/12/2024 in #questions
FFI
I'm working on improving UInt but feel free to send PRs! It's pretty easy to get started with the stdlib 🙂
16 replies
MModular
Created by ✰Black_Star✰ on 3/12/2024 in #questions
can i use wsl for mojo?
Prefer Ubuntu. Installing Mojo on arch is pretty hard
3 replies
MModular
Created by ✰Black_Star✰ on 3/12/2024 in #questions
can i use wsl for mojo?
Yes that works well 🙂
3 replies
MModular
Created by Henk-Jan Lebbink on 2/29/2024 in #questions
How to tell Mojo that something is intended to be constant?
A workaround is to create a function. In a function signature, it's possible to declare that an input value can't be mutated. And it works with references too.
71 replies
MModular
Created by Aamir on 2/28/2024 in #questions
Mojo Source Code Repository
And possibly gpu programming, that seems like a standalone feature that doesn't require too much prep
10 replies
MModular
Created by Aamir on 2/28/2024 in #questions
Mojo Source Code Repository
I guess we'll have the nighlies this week
10 replies
MModular
Created by Zbornak on 2/22/2024 in #questions
Py def vs Mojo fn
People doing scientific computing generally (in research) don't want to type their code. So they'll massively use def over fn, even if, for an software development point of view, it's much better to use fn. Different use cases, different tools... When putting their Mojo code in production, then they just need to add types and var, and then turn def into fn, add unit tests and ship it. Which is much easier than to port all of their code to C++
9 replies
MModular
Created by Aamir on 2/19/2024 in #questions
Help Needed with Accessing High-Resolution Time via FFI in Mojo
Hi, you can find time.time_ns() implemented here: https://github.com/gabrieldemarmiesse/mojo-stdlib-extensions I hope it helps!
3 replies
MModular
Created by Phazer on 2/2/2024 in #questions
Store Reference in struct
I guess that maybe it would work if a was on the heap and not on the stack? But I'm unsure on how to do this with Mojo
18 replies
MModular
Created by Phazer on 2/2/2024 in #questions
Store Reference in struct
I had in my mind something like this, wondering how it would work:
@value
struct RefString[L: MutLifetime]:
var s: Reference[String, __mlir_attr.`1: i1`, L]

fn some_factory_func() -> RefString:
var a = String("hello")
let b = String("world")

let r = Reference(a)
let rs = RefString(r)
rs.s[] += b

return rs


fn main():
print(some_factory_func().s[])
@value
struct RefString[L: MutLifetime]:
var s: Reference[String, __mlir_attr.`1: i1`, L]

fn some_factory_func() -> RefString:
var a = String("hello")
let b = String("world")

let r = Reference(a)
let rs = RefString(r)
rs.s[] += b

return rs


fn main():
print(some_factory_func().s[])
But that can't work because when calling some_factory_func, it's not possible to specify a lifetime yet. (i get /projects/open_source/mojo-stdlib-extensions/trying_stuff.mojo:5:27: error: 'RefString' expects 1 input parameter, but 0 were specified, fn some_factory_func() -> RefString:) Furthermore, the variable a is on the stack, thus it will be destroyed when some_factory_func returns.
18 replies
MModular
Created by Phazer on 2/2/2024 in #questions
Store Reference in struct
I think it's the same
18 replies
MModular
Created by Phazer on 2/2/2024 in #questions
Store Reference in struct
In this example, if the struct rs is returned, I wonder how it works, since the string it's pointing to is on the stack and will be destroyed when the function returns
18 replies
MModular
Created by gabrieldemarmiesse on 1/26/2024 in #questions
How to do recursive structs?
To get a smaller reproducer with types from the stdlib:
from collections.vector import DynamicVector

@value
struct MyNewType(CollectionElement):
var possible_list: DynamicVector[MyNewType]
from collections.vector import DynamicVector

@value
struct MyNewType(CollectionElement):
var possible_list: DynamicVector[MyNewType]
/projects/open_source/mojo-stdlib-extensions/trying_stuff.mojo:5:38: error: 'DynamicVector' parameter #0 has 'CollectionElement' type, but value has type 'MyNewType'
var possible_list: DynamicVector[MyNewType]
^~~~~~~~~
/projects/open_source/mojo-stdlib-extensions/trying_stuff.mojo:1:1: note: 'DynamicVector' declared here
from collections.vector import DynamicVector
^
mojo: error: failed to parse the provided Mojo
/projects/open_source/mojo-stdlib-extensions/trying_stuff.mojo:5:38: error: 'DynamicVector' parameter #0 has 'CollectionElement' type, but value has type 'MyNewType'
var possible_list: DynamicVector[MyNewType]
^~~~~~~~~
/projects/open_source/mojo-stdlib-extensions/trying_stuff.mojo:1:1: note: 'DynamicVector' declared here
from collections.vector import DynamicVector
^
mojo: error: failed to parse the provided Mojo
3 replies
MModular
Created by gryznar on 1/20/2024 in #questions
Rewrite Mojo in Mojo
I can't find it, but I remember Chris saying that one day, the mojo compiler will be re-written in mojo. I think it was in Lex's podcast. He also said just after "I can't wait for the day when I won't have to write C++ anymore" 😂
9 replies
MModular
Created by gabrieldemarmiesse on 1/15/2024 in #questions
In which situation are IntLiteral, FloatLiteral, StringLiteral useful?
I wonder what StringLiteral can do that String can't...
38 replies
MModular
Created by gabrieldemarmiesse on 1/15/2024 in #questions
In which situation are IntLiteral, FloatLiteral, StringLiteral useful?
Doesn't work:
/projects/open_source/mojo-stdlib-extensions/trying_stuff.mojo:4:34: error: cannot implicitly convert 'String' value to 'StringLiteral' in alias initializer
alias a: StringLiteral = some_str()
~~~~~~~~^~
mojo: error: failed to parse the provided Mojo
/projects/open_source/mojo-stdlib-extensions/trying_stuff.mojo:4:34: error: cannot implicitly convert 'String' value to 'StringLiteral' in alias initializer
alias a: StringLiteral = some_str()
~~~~~~~~^~
mojo: error: failed to parse the provided Mojo
I don't know if it's the desired behavior....
38 replies