Getting Started
This guide will help you get started with the Swirl programming language.
Installation
Before getting started make sure Swirl is installed in your system. Follow the installation guide for more info.
After installing Swirl make sure its working properly by running
swirl --version
You are now ready to create your first swirl program.
Write a program
Create a new Swirl file and save it with the .sw or .swirl extension. For example, hello.sw.
Then write the following or you can write your own.
// This is a comment in Swirl
func sayHello(string name) {
print("Hello, " + name + "!")
}
// Call the sayHello function
sayHello("world")
This is a simple Swirl program that defines a function called sayHello, which takes a single parameter of type string. The function then prints the message "Hello, " followed by the value of the name parameter, followed by an exclamation mark.
After defining the sayHello function, the code then calls this function, passing in the string "world" as the argument. When the program is run, the output on the console will be "Hello, world!".
Overall, this code serves as a basic example of how to define functions and pass parameters in Swirl. For a more in depth tutorial check the Swirl tour.
Compilation
Run the following commands to compile and run the program.
swirl hello.sw --run
It will compile and run the program.
If everything worked correctly it should output Hello, world!
.
Congrats you've made your first Swirl app.
Check out the Swirl Tour, for a introduction to the most important concepts and features of the language.
To fully utilize the power of Swirl and enhance your programming experience, setting up a development environment is a crucial next step. For detailed instructions, refer to our guide on Setting up a Development Environment.
If you run into any issues, feel free to reach out for help on our Discord community.