Your first program
Start with one directory and one source file. A simple Noodle program does not need a manifest or a module declaration.
mkdir helloCreate hello/hello.nl:
func greeting(name : String) -> String do "Hello, " ++ name ++ "!"end
func main() -> Unit do Console.println(greeting("Noodle"));endThe greeting function declares the types at its boundary. Its final
expression is the returned String. The main function is the program entry
point and returns Unit, the type used when no meaningful value is returned.
Check and run it
Section titled “Check and run it”Ask Noodle to check every source file in the directory:
noodle check helloThen select hello.nl as the program entry file:
noodle run hello/hello.nlThe program prints:
Hello, Noodle!Add a test
Section titled “Add a test”Tests can live beside the code they exercise. Update hello/hello.nl so the
complete file is:
func greeting(name : String) -> String do "Hello, " ++ name ++ "!"end
func main() -> Unit do Console.println(greeting("Noodle"));end
test "builds a greeting" do Testing.assert_equal(greeting("Noodle"), "Hello, Noodle!")!;endRun all tests in the directory:
noodle test helloThe postfix ! propagates an assertion failure to the test runner. For now,
read it as “this test fails if the assertion fails.” Its general behavior is
explained in Error handling, while the Testing API
is documented under
Output, debugging, and tests.
Next, learn how these commands fit into the everyday workflow.