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:
- Assigning to
int→ generates an integer input reader. - Assigning to
double→ generates a floating-point input reader. - Assigning to
string→ generates a string input reader. - Assigning to
char→ generates a char input reader. - Assigning to
float→ generates a float input reader.
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
input()is blocking: the program waits until the user provides a value.- The concrete parsing (for
int,double,string, etc.) is performed by the generated runtime helpers. -
If the user types something incompatible with the expected type
(e.g. letters when an
intis expected), the current behavior depends on the implementation/runtime and may result in an error.
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
input()has no explicit type annotation in the code.- The type is inferred from the variable or expression that receives the value.
- The compiler specializes and generates a dedicated reader for each type context.