Mojo 学习笔记(二)

Mojo 程序的执行方式有如下几种:

REPL 执行

REPL 是 Read Eval Print Loop 的首字母缩写,表示不断的在 Read/Eval/Print 的循环中执行。很多脚本语言都提供了这种交互模式:

$ mojo
Welcome to Mojo! 

Expressions are delimited by a blank line.
Type `:quit` to exit the REPL and `:mojo help` for further assistance.

  1> print("hello, world")
  2.
hello, world!

脚本方式执行

创建一个文件 hello.mojo,(或者 hello.🔥。mojo脚本可以用 🔥字符作为文件名后缀,真是一个骚操作,有点哗众取宠哩)。

fn main():
    print("hello, world")

然后就可以使用 mojo 执行之:

$ mojo hello.mojo
hello, world!

编译成可执行文件

mojo可以将脚本编译成可执行文件,这个是和 Python不一样的,倒是和 Golang 或者 Rust 一样。

$ mojo build hello.mojo
$ ./hello
hello, world
标签: 技术 Mojo