Modular Mojo
A note on Modular Mojo
Some note about Modular and Mojo
Mojo π₯ β a new programming language for all AI developers.
Mojo combines the usability of Python with the performance of C, unlocking unparalleled programmability of AI hardware and extensibility of AI models.
“Mojo may be the biggest programming language advance in decades.”
“Language thatβs as elegant as Python and as fast as expert-written C, allows me to use one language to write everything from the application server, to the model architecture and the installer too, and lets me debug and profile my code directly in the language in which I wrote it.”
The taste of Mojo:
1$ cat hello.π₯
2def main():
3 print("hello world")
4 for x in range(9, 0, -3):
5 print(x)
6$ mojo hello.π₯
7hello world
89
96
103
11$
1def your_function(a, b):
2 let c = a
3 # Uncomment to see an error:
4 # c = b # error: c is immutable
5
6 if c != b:
7 let d = b
8 print(d)
9
10your_function(2, 3)
1def sort(v: ArraySlice[Int]):
2 for i in range(len(v)):
3 for j in range(len(v) - i - 1):
4 if v[j] > v[j + 1]:
5 swap(v[j], v[j + 1])
1struct MyPair:
2 var first: Int
3 var second: F32
4
5 def __init__(self, first: Int, second: F32):
6 self.first = first
7 self.second = second
1struct HeapArray:
2 var data: Pointer[Int]
3 var size: Int
4 var cap: Int
5
6 fn __init__(self&):
7 self.cap = 16
8 self.size = 0
9 self.data = Pointer[Int].alloc(self.cap)
10
11 fn __init__(self&, size: Int, val: Int):
12 self.cap = size * 2
13 self.size = size
14 self.data = Pointer[Int].alloc(self.cap)
15 for i in range(self.size):
16 self.data.store(i, val)
17
18 fn __copyinit__(self&, other: Self):
19 self.cap = other.cap
20 self.size = other.size
21 self.data = Pointer[Int].alloc(self.cap)
22 for i in range(self.size):
23 self.data.store(i, other.data.load(i))
24
25 fn __del__(owned self):
26 self.data.free()
27
28 fn dump(self):
29 print_no_newline("[")
30 for i in range(self.size):
31 if i > 0:
32 print_no_newline(", ")
33 print_no_newline(self.data.load(i))
34 print("]")
Waiting for the first public compiler version from Chris Lattner and Modular Mojo team.