Hello World in SAPL
Learn how to write your first program in SAPL, the Simple Amharic Programming Language.
Learning Objectives
- Understand the basic structure of a SAPL program
- Create and run your first SAPL script
- Learn how to use the SAPL REPL for interactive coding
- Understand how to use the አሳይ() function for output
Introduction
Welcome to SAPL (Simple Amharic Programming Language)! In this tutorial, we'll write our first SAPL program: a simple "Hello, World!" application. This is traditionally the first program developers write when learning a new programming language, as it demonstrates the basic syntax and structure required to produce output.
Prerequisites
Before you begin, ensure you have the following:
- SAPL installed on your system (version 1.0 or higher)
- A text editor for writing code (VS Code, Sublime Text, Notepad++, etc.)
- Basic familiarity with using the command line or terminal
Verify Installation
Method 1: Using the SAPL REPL
The simplest way to try SAPL is through its REPL (Read-Eval-Print Loop), which allows you to write and execute code interactively. This is perfect for experimenting with small code snippets and learning the language.
Steps:
Open your terminal or command prompt
Run the SAPL interpreter
saplYou should see a prompt that looks like this: >>>
Type the following code and press Enter:
አሳይ("ሰላም ዓለም!")SAPLView the output:
ሰላም ዓለም!
Congratulations!
You've just written and executed your first SAPL command. The አሳይ() function displays the text inside the parentheses on the screen.
Method 2: Creating a SAPL Script File
For more complex programs or code you want to save and reuse, it's better to write your code in a file. Let's create a SAPL script file for our Hello World program.
Steps:
Open your text editor and create a new file
Name the file hello.sapl (SAPL files use the .sapl extension)
Add the following code to the file:
# የመጀመሪያ ፕሮግራም አሳይ("ሰላም ዓለም!")SAPLSave the file
Open your terminal or command prompt
Navigate to the directory where you saved the file
Use cd command to change directories, e.g., cd Documents/sapl-projectsRun the script using the SAPL interpreter:
sapl hello.saplView the output:
ሰላም ዓለም!
Understanding the Code
Let's break down what's happening in our simple program:
# የመጀመሪያ ፕሮግራምThis is a comment in SAPL. Comments start with # and are ignored by the interpreter. They're useful for adding notes to your code in either Amharic or English.
አሳይ("ሰላም ዓለም!")This calls the አሳይ function with the string "ሰላም ዓለም!" as an argument. The function displays the text on the screen. Note that text strings must be enclosed in quotation marks.
Extending the Program
Let's make our program a bit more interesting by adding a variable and using string concatenation:
# የተሻሻለ ሰላም ዓለም ፕሮግራም
ስም = "ሳፕል"
አሳይ("ሰላም ዓለም! እኔ " + ስም + " ነኝ።")
አሳይ("ፕሮግራሚንግን በአማርኛ እንማር!")What's New:
ስም = "ሳፕል"- Creates a variable named ስም (name) and assigns it the value "ሳፕል"አሳይ("ሰላም ዓለም! እኔ " + ስም + " ነኝ።")- Uses the + operator to concatenate (join) strings together with the variable- Multiple አሳይ() statements to display multiple lines of output
Important Note
Common Errors and Troubleshooting
Missing Quotation Marks
አሳይ(ሰላም ዓለም!)Error: Strings must be enclosed in quotation marks. The correct syntax is:
አሳይ("ሰላም ዓለም!")Incorrect Function Name
asay("ሰላም ዓለም!")Error: SAPL uses Amharic function names. The correct function name is አሳይ, not asay.
Missing Parentheses
አሳይ "ሰላም ዓለም!"Error: Function arguments must be enclosed in parentheses. The correct syntax is:
አሳይ("ሰላም ዓለም!")Summary
Key Concepts Learned
- How to use the SAPL REPL for interactive coding
- How to create and run a SAPL script file
- How to use the አሳይ() function to display output
- How to create variables and perform string concatenation
- How to add comments to your code
Congratulations! You've successfully written your first SAPL program. This is just the beginning of your journey with SAPL. As you continue through these tutorials, you'll learn more advanced concepts and techniques for building powerful programs.
Next Steps
Now that you've completed this tutorial, you're ready to move on to more advanced topics:
