Skip to Content

Your First Program

Create an empty directory and, inside it, a text file named helloworld.ms. MushScript program code lives in UTF-8 text files with the .ms extension.

helloworld.ms
func main() -> int { print("Hello, world"); return 0; }
$ mush run helloworld.ms Hello, world

The program prints one line and exits. That is a complete development loop: write the file → run it → read the output.

Line by Line

  • Line 1 func main() -> int: declares a function named main. main is the conventional entry name: mush run starts executing here. -> int says it returns an integer.
  • Lines 2 and 5: a pair of braces framing the function body. The braces cannot be omitted, even when the body is a single statement.
  • Line 3: calls print, which prints what is inside the parentheses and appends a newline. The semicolon at the end marks the end of a statement; every statement needs one.
  • Line 4: return 0; hands 0 to the operating system as the exit code. The number becomes the program’s exit code, and 0 means “all is well”.

print takes numbers, booleans, strings, any value directly; there is no need to convert to text first.

Comments

Comments come in three forms, and the compiler ignores them all:

// Line comment: runs to the end of the line /* Block comment: can span lines, and /* supports nesting */, counted by depth, closed by a matching pair */ /// Doc comment: attaches to the next declaration and feeds documentation to the language service
  • Block comments nest
  • /// doc comments are their own kind, separate from //; their meaning is “a description of the next declaration”

Your First Error Message

Misspell print as pritn and run again to see a compile error:

$ mush run helloworld.ms error MS3001: Undefined name 'pritn'. --> helloworld.ms:3:5 | 3 | pritn("Hello, world"); | ^^^^^

An error message always has three parts: what went wrong (an error code plus a one-line description), where it happened (--> points to line:column), and a source excerpt with the offending characters marked.

One real error often drags a chain of follow-on diagnostics behind it; fix the first and the rest usually disappear.

To check that code compiles without actually running it, use mush check helloworld.ms. It runs the same compilation but executes nothing.

Notes

  • When compilation fails, not one line of the program executes; any output you see always comes from a program that compiled in full.
  • The entry function is the same with or without public: the main entry ignores visibility modifiers, and this reference manual omits it throughout.
  • Later pages show behavior as example-plus-output pairs; every snippet is runnable.
Last updated on October 11, 2026