input()

The input() function in Zard reads a value from standard input (stdin) and adapts its type based on the context where it is used. You do not specify the type of input() directly: instead, the compiler specializes it according to the expected type at that location.

In other words: input() is polymorphic and type-directed. For each concrete use (e.g. assigning to int, double, string), the compiler generates a dedicated model/handler for that type.


Type-directed behavior

When the compiler sees input(), it looks at the expected type in that position and specializes the call:

This behavior is resolved at compile time. No explicit cast is required, and input() itself remains syntactically the same in all cases.


main {

    int a = input();      # input specialized as int reader
    double c = input();   # input specialized as double reader

    print(c);
    print(a);
}
      

In the example above, the same input() syntax results in two different internal models: one for int, one for double.

Behavior and runtime notes

Internally, the compiler may generate different low-level functions or LLVM helpers for each observed usage of input(), effectively creating a dedicated model per case of use.


Summary