Pony Tutorial
Opens in a new window Opens an external site Opens an external site in a new window
  • Getting Started
    • Overview
    • What You Need
    • Hello World: Your First Pony Program
    • Hello World: How It Works
  • Types
    • Overview
    • The Pony Type System at a Glance
    • Classes
    • Primitives
    • Actors
    • Traits and Interfaces
    • Structs
    • Type Aliases
    • Type Expressions
  • Expressions
    • Overview
    • Literals
    • Variables
    • Operators
    • Arithmetic
    • Control Structures
    • Methods
    • Errors
    • Equality in Pony
    • Sugar
    • Object Literals
    • Partial Application
  • Reference Capabilities
    • Overview
    • Reference Capabilities
    • Reference Capability Guarantees
    • Consume and Destructive Read
    • Recovering Capabilities
    • Aliasing
    • Passing and Sharing References
    • Capability Subtyping
    • Combining Capabilities
    • Arrow Types aka Viewpoints
    • Reference Capability Matrix
  • Object Capabilities
    • Overview
    • Object Capabilities
    • Trust Boundary
  • Generics
    • Overview
    • Generics and Reference Capabilities
    • Constraints
  • Pattern Matching
    • Overview
    • Match Expressions
    • As Operator
  • Packages
    • Overview
    • Package System
    • Use Statement
    • Standard Library
  • Testing
    • Overview
    • Testing with Ponytest
  • C FFI
    • Overview
    • Calling C from Pony
    • Linking to C Libraries
    • C ABI
    • Callbacks
  • Gotchas
    • Overview
    • Divide by Zero
    • Garbage Collection
    • Scheduling
    • Function Call Side Effects
    • Recursion
  • Where Next?
    • Overview
  • Appendices
    • Overview
    • PONYPATH
    • Lexicon
    • Symbol Lookup Cheatsheet
    • Keywords
    • Examples
    • Whitespace
    • Compiler Arguments
    • Memory Allocation at Runtime
    • Garbage Collection with Pony-ORCA
    • Platform-dependent code
    • A Short Guide to Pony Error Messages
    • Program Annotations
    • Serialisation

GETTING STARTED

Overview

This chapter will get you up and running with Pony from installing the compiler to running your first program.

As you work your way through this tutorial, you’ll likely come across a lot of concepts that are familiar to you from any prior programming languages that you’ve had experience with. You’ll likely want to skim and skip around through these areas, and that’s totally fine.

However, if you’ve never used Pony before, we guarantee that you’ll come across concepts that are new to you, which will require close and careful attention if you want to learn and apply them: reference capabilities. These are the core innovation in Pony that make it a unique and compelling offering in the wide world of modern programming languages.

In this tutorial we start off with familiar basics, and try our best to avoid reference capabilities in the code examples until later on when they can be covered in detail. You should feel free to follow along with the code examples in your own text editor - we absolutely encourage it. Just be aware that as you venture off the beaten path of the curated tutorial, you’ll likely run into reference capabilities, and you’ll need to thoroughly read and understand the basics of those concepts before you’ll really feel fluent and able to work with the compiler as it tries to help you prove the safety of your program.

Stick with us and read on, even if you need to read through something a few times. Know that the community is here to help as you climb the learning curve and master new concepts that will change the way you think about concurrency.

What You Need

To get started, you’ll need a text editor and the ponyc compiler. Or if you are on a not supported platform or don’t want to install the compiler you can use the Pony’s Playground. The Pony compiler Before you get started, please check out the installation instructions for the Pony compiler. A text editor While you can write code using any editor, it’s nice to use one with some support for the language.

Hello World: Your First Pony Program

Now that you’ve successfully installed the Pony compiler, let’s start programming! Our first program will be a very traditional one. We’re going to print “Hello, world!”. First, create a directory called helloworld: mkdir helloworld cd helloworld Does the name of the directory matter? Yes, it does. It’s the name of your program! By default when your program is compiled, the resulting executable binary will have the same name as the directory your program lives in.

Hello World: How It Works

Let’s look at our helloworld code again: actor Main new create(env: Env) => env.out.print("Hello, world!") Let’s go through that line by line. Line 1 actor Main This is a type declaration. The keyword actor means we are going to define an actor, which is a bit like a class in Python, Java, C#, C++, etc. Pony has classes too, which we’ll see later. The difference between an actor and a class is that an actor can have asynchronous methods, called behaviours.