Mojo
2 mins·
0
·
0
·
new tech
programming languages
mojo
Table of Contents
New Programming Language (Mojo) trial
Why Try Mojo 為何想嘗試一下Mojo #
- Because saw this article Mojo Language: The New Programming Language for AI
一直在尋求除了Python以外其他的AI開發用程式語言,Python 的performance 極差造成在邊緣運算的開發瓶頸,因此在嘗試的使用其他跟硬體整合度更好的高階程式語言 (不需要做Cross compiler 額外的編譯) e.g. GO, RUST.
Feature | Python | Go |
---|---|---|
Programming language | General-purpose | General-purpose |
Type system | Dynamic | Static |
Concurrency | Yes | Yes |
Garbage collection | Yes | Yes |
Memory safety | Yes | Yes |
Performance | Interpreted, slower | Compiled, faster |
Simplicity | Easier to learn and use |
More complex to learn, but simpler syntax |
Community | Large and active |
Smaller but growing |
Popular use cases | Web development, data science, machine learning | Systems programming, cloud computing, distributed systems |
- Just like to learn new programming languages 💖💕🫶
Mojo Installation (VS Code + WSL) #
- Install VS Code, the WSL extension. (also see Python Dummy Day 1)
- Install Ubuntu 22.04 for WSL and open it.
- In the Ubuntu terminal, install the Modular CLI:
curl https://get.modular.com | \
MODULAR_AUTH=mut_0056b5ebbaab4074af12927c8d9af244 \
sh -
- Install the Mojo SDK:
modular install mojo
-
Open VS Code, connect to WSL, and install VS Code Mojo Extension.
-
Check Mojo in shell initialization ( ~/.zshrc as an example)
export PATH=$PATH:/usr/local/go/bin
export MODULAR_HOME="$HOME/.modular"
export PATH="$MODULAR_HOME/pkg/packages.modular.com_mojo/bin:$PATH"
if not in rc script, run commands:
echo 'export MODULAR_HOME="$HOME/.modular"' >> ~/.zshrc
echo 'export PATH="$MODULAR_HOME/pkg/packages.modular.com_mojo/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
First Mojo Program : Hello World! #
Run code in the REPL(Read-eval-print loop) #
- Run mojo execution environment
~/work/mojo » mojo
Welcome to Mojo! 🔥
Expressions are delimited by a blank line.
Type `:mojo help` for further assistance.
1>
- print hello world
1> print("hello world") ### not allow backspace
2. ### press enter here
hello world
2>
Build and run Mojo source files #
- create a hello work folder
~/work/mojo » mkdir hello
- create a hello.mojo file
~/work/mojo/hello » code hello.mojo
- write hello world mojo codes in hello.mojo file
fn main():
print("Hello, world!")
- run hello.mojo
~/work/mojo/hello » mojo hello.mojo
Hello, world!
- build hello world executable binary
~/work/mojo/hello » mojo build hello.mojo
- check generated executable binary file
~/work/mojo/hello » ls
hello hello.mojo
- run hello
~/work/mojo/hello » ./hello
Hello, world!
不負責之試用心得 #
- binary size : 1.7 MB,比之前用GO build做出來還小一些,但是差距不大。
~/work/mojo/hello » ls -alh hello
-rwxr-xr-x 1 anitawu anitawu 1.7M Sep 23 13:51 hello
- 稍微看一下它包了什麼進去
~/work/mojo/hello » hexdump -C hello | more
Link GNU
期待能整合到各家GPU/APU/NPU whatever Unit。應該是跟RUST 不同走向。語法其實跟python 比較類似,學起來不會太久。下次來試試其他的example (看看有什麼演算法或是training相關的)。
Reference
Related
Python Dummy Day 1 : 開發環境
2 mins·
0
·
0
training
python
dummy
如何使用 WSL 在 Windows 上安裝 Linux 如何使用 WSL 在 Windows 上安裝 Linux # 安裝 WSL # Windows 搜尋 Powershell # 開啟powershell 安裝WSL # wsl --install Hacking!