Getting started

  1. Install Mys as described on the Installation page.

  2. Create a package called foo with the command mys new foo, and then enter it. This package is used in throughout the tutorial.

    ../_images/new.png

    src/main.mys implements the hello world application.

    func main():
        print("Hello, world!")
    
  3. Build and run the application with the command mys run. It prints Hello, world!, just as expected.

    ../_images/run.png

  4. src/lib.mys implements the function add() and its test add(). This examplifies how to test your Mys modules.

    func add(first: i64, second: i64) -> i64:
        return first + second
    
    test add():
        assert add(1, 2) == 3
    
  5. Build and run the tests with the command mys test.

    ../_images/test.png

  6. Run mys test -c to build and run the tests again and create a coverage report.

    ../_images/test_c.png

  7. Open the coverage report in a web browser. The URL is found in the output of the previous step.

    ../_images/test_c_index_html.png

  8. Add the bar package as a dependency and use its hello() function.

    package.toml with the bar dependency added:

    [package]
    name = "foo"
    version = "0.1.0"
    authors = ["Mys Lang <mys.lang@example.com>"]
    description = "Add a short package description here."
    
    [dependencies]
    bar = "latest"
    

    src/main.mys importing hello() from the bar module:

    from bar import hello
    
    func main(argv: [string]):
        hello(argv[1])
    
  9. Build and run the new application. Notice how the dependency is downloaded and that mys run universe prints Hello, universe!.

    ../_images/run-universe.png

  10. Replace the code in src/main.mys with the code below. It examplifies how to use functions, classes, errors, types and command line arguments. The syntax is almost identical to Python, so many readers should easily understand it.

    func func_1(a: i64) -> (i64, string):
        if a == 5:
            text = "Foo"
        else:
            text = "Bar"
    
        return 2 * a, text
    
    func func_2(a: i64, b: i64) -> i64:
        for i in range(b):
            a += i * b
    
        return a
    
    func func_3(a: i64) -> {i64: [f64]}:
        return {
            1: [2.0],
            10 * a: [7.5, -1.0]
        }
    
    func func_4():
        try:
            raise ValueError()
        except:
            print("func_4():      An error occurred.")
    
    func func_5() -> [i64]:
        small: [i64] = []
    
        for v in [3, 1, 5, 7, 2]:
            if v < 5:
                small.append(v)
    
        small.sort()
        small.reverse()
    
        return small
    
    class Calc:
        value: i64
    
        func triple(self):
            self.value *= 3
    
    func main(argv: [string]):
        value = i64(argv[1])
        print("func_1(value):", func_1(value))
        print("func_2(value):", func_2(value, 1))
        print("func_3(value):", func_3(value))
        func_4()
        print("func_5():     ", func_5())
        calc = Calc(value)
        calc.triple()
        print("calc:         ", calc)
    
  11. Build and run it with mys run 5.

    ../_images/run-features.png

  12. Continue to explore Mys by reading the Language Reference, and at the same time modify the code in src/main.mys to test anything you find interesting.