37 lines
1.0 KiB
Hare
37 lines
1.0 KiB
Hare
use bufio;
|
|
use fmt;
|
|
use os;
|
|
use strings;
|
|
|
|
export fn main() void = {
|
|
fmt::println("Hello world!")!;
|
|
|
|
const user = askname();
|
|
greet(user);
|
|
};
|
|
|
|
// ask for a name.
|
|
fn askname() str = {
|
|
// the exclamation mark at the end makes a pledge to the compiler that
|
|
// the function call will not fail. should it fail, the program would
|
|
// crash.
|
|
fmt::println("Hello, please enter your name:")!;
|
|
// this looks like it's storing user input as an array of unsigned 8-bit
|
|
// data types, presumably unsigned 8-bit ints
|
|
const name = bufio::scanline(os::stdin)! as []u8;
|
|
return strings::fromutf8(name);
|
|
};
|
|
// ^ weirdly/interestingly, functions in hare are ended using a semicolon like
|
|
// everything else usually is.
|
|
|
|
// greet a user by name.
|
|
fn greet(user: str) void = {
|
|
// rust-like syntax for fn args, "fn" keyword and rust/cpp-like "::" for
|
|
// namespace delimiting are used.
|
|
|
|
// printfln prints a "formatted" string (terminated by a newline) as
|
|
// opposed to just printfn, that simply prints a fixed string,
|
|
// apparently.
|
|
fmt::printfln("Hello, {}!", user)!;
|
|
};
|