Hello, World!
Let’s begin by writing and executing a minimal program in Wysna.
Creating the Source File
Section titled “Creating the Source File”Create a file named main.wysna:
## main.wysna
fn greet(name: str) -> str { return "Hello, " + name + "! Welcome to Wysna."}
fn main() -> unit { let message = greet("World") print(message)}Anatomy of the Program
Section titled “Anatomy of the Program”Let’s break down each element of this program:
- Comments: Comments begin with double hashes
##(or single#for inline comments). - Function Declaration (
fn):greetaccepts a parameternameof typestrand returns astr.- In Wysna, function parameter types and return types are explicit.
- String Concatenation: Strings are managed buffers that support concatenation using the
+operator with automatic ARC lifecycle tracking. - The
mainEntry Point:- Every executable program defines an entry point named
main(). - Its return type is
unit(indicating no meaningful return value, analogous tovoidin C or()in Rust).
- Every executable program defines an entry point named
- Immutable Variables (
let):let message = greet("World")bindsmessage. By default, variables defined withletare immutable.
- Built-in
print:print(...)writes formatted strings and values to standard output (stdout) followed by a newline.
Compiling and Running
Section titled “Compiling and Running”You can compile and immediately execute the program with a single command:
wysna run main.wysnaOutput:
Hello, World! Welcome to Wysna.Compiling to a Standalone Executable
Section titled “Compiling to a Standalone Executable”To produce a native binary file for distribution:
wysna build main.wysna -o app./app