ivellapillil
ivellapillil
MModular
Created by ivellapillil on 5/15/2024 in #community-showcase
Online book on Mojo
Now some concepts on memory has been added. https://ruhati.net/mojo/_memory_management_and_pointers.html Please take a look. If you see any mistakes, would be glad if pointed out.
35 replies
MModular
Created by ivellapillil on 10/24/2024 in #questions
Preserving mutability when passing to function
But most developers would not have to worry.
42 replies
MModular
Created by ivellapillil on 10/24/2024 in #questions
Preserving mutability when passing to function
Yes. Most likely
42 replies
MModular
Created by ivellapillil on 10/24/2024 in #questions
Preserving mutability when passing to function
Or some kind of a preprocessor like:
use memory.ReferencePointer for ref
use memory.ReferencePointer for ref
But then we need to be super carefull that the different reference types interoporate seamlessly.
42 replies
MModular
Created by ivellapillil on 10/24/2024 in #questions
Preserving mutability when passing to function
So being a Reference is a "trait" as you suggest, but there is a default implementation used by the compiler when we use ref
42 replies
MModular
Created by ivellapillil on 10/24/2024 in #questions
Preserving mutability when passing to function
We can have that, and have a "default" referencepointer which is blessed with a syntax... The default one would be enough for 95% of cases...
42 replies
MModular
Created by ivellapillil on 10/24/2024 in #questions
Preserving mutability when passing to function
I am not a PL expert - but could ref and the others be just syntax sugar over a library defined ReferencePointer?
42 replies
MModular
Created by ivellapillil on 10/24/2024 in #questions
Preserving mutability when passing to function
I like your idea to keep reference a library type. Though also like Nick's syntax. A combination of both would be greaet
42 replies
MModular
Created by ivellapillil on 10/24/2024 in #questions
Preserving mutability when passing to function
Yes - I am actually following the conversations... Another set of refactorings on the way 🙂
42 replies
MModular
Created by ivellapillil on 10/24/2024 in #questions
Preserving mutability when passing to function
I am writing what I am learning. I had to do quite a few refactoring though 😆
42 replies
MModular
Created by ivellapillil on 10/24/2024 in #questions
Preserving mutability when passing to function
Actually I wanted to explain the usage of Mojo's Pointer in my book.
42 replies
MModular
Created by ivellapillil on 10/24/2024 in #questions
Preserving mutability when passing to function
Understood. Thanks!!
42 replies
MModular
Created by ivellapillil on 10/24/2024 in #questions
Preserving mutability when passing to function
I used MutableAnyOrigin in place of MutableOrigin and it was not a type but a value... I got confused after that 🙂
42 replies
MModular
Created by ivellapillil on 10/24/2024 in #questions
Preserving mutability when passing to function
Thanks a lot! That works!
42 replies
MModular
Created by ivellapillil on 10/24/2024 in #questions
Preserving mutability when passing to function
mojo 2024.10.2406 (54f70ee8)
42 replies
MModular
Created by ivellapillil on 10/24/2024 in #questions
Preserving mutability when passing to function
I am getting
error: 'Pointer' parameter 'origin' has 'Origin[?.value]' type, but value has type 'Origin[is_mutable]'
def change_value[is_mutable: Bool, //, origin: Origin[is_mutable]](p: Pointer[A, origin=origin]):
^~~~~~
error: 'Pointer' parameter 'origin' has 'Origin[?.value]' type, but value has type 'Origin[is_mutable]'
def change_value[is_mutable: Bool, //, origin: Origin[is_mutable]](p: Pointer[A, origin=origin]):
^~~~~~
42 replies
MModular
Created by ivellapillil on 10/24/2024 in #questions
Preserving mutability when passing to function
Thanks for the response. Actually I did try that, but didn't know what to put in the __origin_of .. MutableAnyOrigin does not work (as it seems to expect the origin of the a_instance itself. If the function is inside the same lexical scope of as_instance, then we can use that. But in case it is outside, it is not possible..
struct A:
var val: Int
fn __init__(inout self, val: Int):
self.val = val

def print_value(p: Pointer[A]):
print(p[].val)

def change_value(p: Pointer[A, origin=__origin_of(a_instance)]): # Gives error ofc as a_instance is not in scope. What should go inside origin_of?
p[] = 15
...

def main():
var a_instance = A(12)
var ref_a = Pointer.address_of(a_instance)
print_value(ref_a)
change_value(ref_a)
ref_a[] = 15
struct A:
var val: Int
fn __init__(inout self, val: Int):
self.val = val

def print_value(p: Pointer[A]):
print(p[].val)

def change_value(p: Pointer[A, origin=__origin_of(a_instance)]): # Gives error ofc as a_instance is not in scope. What should go inside origin_of?
p[] = 15
...

def main():
var a_instance = A(12)
var ref_a = Pointer.address_of(a_instance)
print_value(ref_a)
change_value(ref_a)
ref_a[] = 15
42 replies
MModular
Created by jmky on 10/7/2024 in #questions
Is there a disdain for Rust from the Mojo team?
Yes. There are some design work that is in flux at the moment.. As soon as they are stable, I would get back to incorporating them in.. Excited to see things around lifetime becoming more easier to explain..
23 replies
MModular
Created by jmky on 10/7/2024 in #questions
Is there a disdain for Rust from the Mojo team?
Hi Darin, thanks for the suggestion. I was also trying to introduce concepts gradually in the book... Or is there something that is confusing or introduced a bit too early which needs adjustment?
23 replies
MModular
Created by ivellapillil on 7/23/2024 in #questions
Bug or optimisation
Thanks! I was not aware compilers perform this optimisation.
7 replies