Getting Started with Tea
This guide will help you install Tea, write your first program, and understand the basics of the language. You'll be up and running in less than 10 minutes.
Prerequisites
Before installing Tea, make sure you have:
- Git - Version control system (download here)
- C++ Compiler - GCC 9+ or Clang 10+ for building from source
- LLVM 14+ - Required for native compilation
- Make - Build automation tool
Installation
Clone the Repository
First, clone the Tea repository from GitHub to your local machine:
git clone https://github.com/special-tea/tea.git
cd teaBuild and Install
Run the setup script to build Tea and install it to your system:
make setup
make installThis will compile the Tea compiler and install it to /usr/local/bin by default. You may need to use sudo for installation.
Verify Installation
Check that Tea is installed correctly:
tea --versionYou should see output like:
Tea version 0.1.0Your First Tea Program
Let's write a simple "Hello, World!" program to get started.
Create hello.tea
Create a new file called hello.tea with the following content:
# hello.tea
print("Hello, Tea!")Run your program
Execute your program using Tea:
tea run hello.teaOutput:
Hello, Tea!Compile to native binary
Compile your program to a native binary for optimal performance:
tea compile hello.tea -o hello
./helloThe compiled binary runs directly on your system with no runtime dependencies.
A More Complex Example
Let's explore Tea's features with a program that demonstrates functions, types, and control flow.
# greet.tea
# Define a function with type annotations
def greet(name: String, age: Int) -> String
if age < 18
"Hello, young ${name}!"
else
"Hello, ${name}!"
end
end
# Create an array of names
var people = [
{"name": "Alice", "age": 25},
{"name": "Bob", "age": 16},
{"name": "Charlie", "age": 30}
]
# Iterate and greet each person
for person of people
var message = greet(person["name"], person["age"])
print(message)
endOutput:
Hello, Alice!
Hello, young Bob!
Hello, Charlie!Key Concepts Demonstrated
- Function Definitions: Use
defwith type annotations for parameters and return types - String Interpolation: Embed variables in strings using
${variable} - Control Flow: Use
if/elsefor conditional logic - Loops: Iterate over collections with
for...of - Type Inference: Variables like
messagehave their types inferred automatically
Next Steps
Now that you've written your first Tea programs, here's what to explore next:
Need Help?
If you run into any issues or have questions, here are some resources: