Hello World Tutorial

Create your first Grey application

Basic Time: 15 minutes

Introduction

Welcome to the GreyOS Hello World tutorial! In this guide, you'll create your first application using the Grey programming language and the GreyOS ecosystem. This tutorial is designed for beginners and requires no prior Grey programming experience.

By the end of this tutorial, you'll understand:

  • How to set up a basic Grey application
  • The structure of a Grey program
  • How to run your application in the Grey environment
  • Basic Grey syntax and concepts

Prerequisites

Before you begin, make sure you have:

  • A GreyOS account (if you don't have one, sign up here)
  • Basic programming knowledge (variables, functions, etc.)
  • Access to the Grey Shell (available at /shell)

Note: All examples in this tutorial can be run directly in the Grey Shell, which is available to all GreyOS users.

Step 1: Create a new project

Let's start by creating a new Grey project. Open the Grey Shell and type the following command:

grey new hello-world

This command creates a new project directory called hello-world. Navigate to this directory using:

cd hello-world

The Grey CLI automatically generates the basic project structure for you:

hello-world/
├── app.grey      # Main application file
├── grey.toml     # Project configuration 
└── README.md     # Documentation

Step 2: Write your first Grey program

Open the app.grey file in your favorite editor. You'll see some boilerplate code. Replace it with the following:

// Hello World application in Grey

symbolic Program {
    function main() -> Void {
        print("Hello, Grey World!");
    }
}

// Starting point of the application
entry(Program.main);

Save the file after making these changes.

Step 3: Run your application

Now that you've written your first Grey program, let's run it. In the Grey Shell, make sure you're in the project directory and run:

grey run

You should see the following output:

Building hello-world...
Executing symbolic program...

Hello, Grey World!

Program exited successfully.

Congratulations! You've just run your first Grey program!

Step 4: Understand the code

Let's break down the code you just wrote:

symbolic Program {
    function main() -> Void {
        print("Hello, Grey World!");
    }
}
  • symbolic Program { ... }: Defines a symbolic structure called "Program". In Grey, symbolic structures are the building blocks of your application.
  • function main() -> Void { ... }: Defines a function called "main" that returns nothing (Void). This is similar to main functions in other languages.
  • print("Hello, Grey World!");: Prints the text to the console.
entry(Program.main);
  • entry(Program.main);: Specifies the entry point of your application. This tells the Grey runtime where to start execution.

Note: The Grey language uses Recursive Symbolic Execution (RSE) as its core concept, allowing programs to be expressed as symbolic structures that can be transformed, optimized, and executed efficiently.

Next Steps

Now that you've created your first Grey application, here are some ideas to expand your knowledge:

  • Modify the program to ask for the user's name and greet them personally
  • Explore Grey's symbolic data structures by creating and manipulating them
  • Check out the UI Basics Tutorial to learn how to create graphical applications
  • Read the Grey Language Guide for a comprehensive overview of the language

Remember: Grey is a symbolic language. Think in terms of symbols and transformations rather than just sequential operations.