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.
letis for immutable, and
structis very similar to Python
structMUST be explicitly declared with
delto remove method or change its value
structworks well with operator oveloading
Tuple) are made up of
inttype can handle really big numbers and has some extra features, like checking if two numbers are the same object.
Intis designed to be simple, fast, and tuned for your computer’s hardware to handle quickly.
fnis “strict mode” for
def, the callee doesn't care
fnhas the following limitations
None(instead of unknown return type)
raiseskeyword on the
__init__but "how to copy")
__init__but "how to move")
deffunction use reference semantics.
deffunction use value semantics by default
fnfunction are immutable references by default.
structs are always inlined to their container
letwork, prevent mutation & how are lifetimes of these values controlled for Mojo to be memory safe ?
borrowedobject is an immutable reference to an object that a function receives
fnarguments, made explicit with
selfargument of methods
__getitem__is implemented but not
inoutconvention 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 transfer
ownedconvention on destructors and on consuming move constructor
ownedin the del function is important because you must own a value to destroy it.
fnargument passing : Mojo
defis just sugaring for the
defargument without an explicit type annotation defaults to
defargument without a convention keyword (such as
owned) is passed by implicit copy into a shadow mutable var with the same name as the argument
Objectare cheap to copy
let mod_name = Python.import_module("module_name")is equivalent to
import module_name as mod_name