[Lesson 1] Hello world!
This page was last updated for version 0.6.
Hello, and welcome to Pogo! Pogo is a language made to introduce potential programmers to programming. It's really easy to get started and there's so much you can do with it! In this lesson, we are going to learn how to write a program that prints "Hello world!" to the console.
The first thing you need to do is declare a class. A class is a file that contains valid code.
In Pogo, here's how you declare a class:
class <Name>
This is the first line that shows up in the file. Replace with the name of the class. A class name cannot contain spaces and should begin with a capital letter. In this case, let's name the class HelloWorld
class HelloWorld
Now, we need to declare a main method. Simply put, a method is a block of code that runs when it is invoked. The main method is the first method called when you run your program. It is automatically called by the Pogo interpreter.
In Pogo, methods are declared in named lambda notation. It will look similar to lambdas or anonymous functions in other languages. Here's how you declare a method:
method <name> = ([<<type> <name>>...]) -> <returnType>
Don't worry about anything you don't understand. For the main method, we write:
method main = () -> void
main
is the name of the method. The ()
denotes that the method has no parameters. void
is the return type. void
means that the method doesn't return anything.
Now, let's go ahead and print the message! Pogo has a System
class full of low-level methods that are very useful.
In Pogo, here's how you invoke a method:
<variableName | className>.<method>([<<type> <name>>...])
The name of the class we want is System
and the method is print
. print
takes one parameter, the message.
Here's how we invoke the print
method:
System.print("Hello, world")
By putting Hello, world in quotes, we are telling Pogo that this is a string. We will learn more about that when we get to variables.
That's all it takes. Pretty simple. Here's the final code:
class HelloWorld
method main = () -> void
System.print("Hello, world")
I spaced the lines like that to show the tree. The line System.print("Hello, world")
belongs to the main method and the line method main = () -> void
belongs to the HelloWorld class.