28th May 2023
"for AI/....... developers"
as quoted from the Mojo manual - 28th May '23
Â
BUT, when you invoke the spells
Â
At least, that's my experience/understanding
Let's dig into these spells, and see the building blocks.
let
 is for immutable, and var
 for mutable
def
declaration)def
declarationsstruct
is very similar to Python class
struct
MUST be explicitly declared with let
or var
del
to remove method or change its valuestruct
works well with operator oveloading
Int
, Bool
, String
, Tuple
) are made up of struct
Int
vs int
int
 type can handle really big numbers and has some extra features, like checking if two numbers are the same object.
Int
 is designed to be simple, fast, and tuned for your computerâs hardware to handle quickly.struct
fn
is âstrict modeâ for def
, the callee doesn't carefn
has the following limitations
let
)None
(instead of unknown return type)let
or var
)raises
keyword on the fn
__copyinit__
and __moveinit__
special methods__copyinit__
( __init__
but "how to copy")__moveinit__
( __init__
but "how to move")def
function use reference semantics.def
function use value semantics by default
fn
function are immutable references by default.
struct
s are always inlined to their container
self
(as __iadd__
)let
work, prevent mutation & how are lifetimes of these values controlled for Mojo to be memory safe ?borrowed
object is an immutable reference to an object that a function receivesfn
arguments, made explicit with borrowed
keywordself
 argument of methodsself
values@register_passable
Â
inout
 keywordinout
s possible__getitem__
is implemented but not __setitem__
inout
convention is the same, since the internal impl. may actually pass values using pointers^
operator at the call site on the value that we want to transferowned
 convention on destructors and on consuming move constructorowned
in the del function is important because you must own a value to destroy it.def
vs. fn
argument passing : Mojodef
is just sugaring for the fn
functiondef
 argument without an explicit type annotation defaults to Object
def
 argument without a convention keyword (such as inout
 or owned
) is passed by implicit copy into a shadow mutable var with the same name as the argument__copyinit__
 methodObject
 are cheap to copyPython.import_module("module_name")
let mod_name = Python.import_module("module_name")
is equivalent to import module_name as mod_name
Python.add_to_path("path/to/module")
dict
 methodÂ
Text