Zen Programming Language Documentation

Getting Started

Installation

$ curl -sSL https://get.zenlang.org | sh
$ zen --version
Zen 1.0.0

Hello World

fn main() {
    println("Hello, World!");
}
Note: Zen uses the `fn` keyword to define functions and `println` for console output.

Language Basics

Variables and Types

let x: Int = 5;        // Explicitly typed
let y = 10;            // Type inferred
var z = 15;            // Mutable variable

let pi: Float = 3.14159;
let message: String = "Hello, Zen!";
let is_zen: Bool = true;

Control Flow

if x > 0 {
    println("Positive");
} else if x < 0 {
    println("Negative");
} else {
    println("Zero");
}

for i in 0..5 {
    println(i);
}

while condition {
    // do something
}

Functions

fn add(a: Int, b: Int) -> Int {
    a + b
}

let result = add(3, 4);

Advanced Features

Pattern Matching

let result = match value {
    0 => "Zero",
    n if n > 0 => "Positive",
    _ => "Negative",
}

Asynchronous Programming

async fn fetch_data() -> Result {
    // Asynchronous operations
}

async fn main() {
    let data = fetch_data().await?;
    println("Fetched: {data}");
}

Generics

fn identity(x: T) -> T {
    x
}

let int_val = identity(5);
let str_val = identity("Hello");

AI Integration

Ethical Decision Making

use zen::ai::ethical;

let decision = ethical::decide(action, context);
if decision.is_ethical() {
    perform_action(action);
} else {
    report_ethical_concern(decision.reason());
}

Natural Language Processing

use zen::ai::nlp;

let sentiment = nlp::analyze_sentiment(text);
println("Sentiment: {sentiment}");

Standard Library

Collections

use zen::collections::Vector;

let mut vec = Vector::new();
vec.push(1);
vec.push(2);
vec.push(3);

for item in vec {
    println(item);
}

File I/O

use zen::io::File;

let contents = File::read("example.txt")?;
println("File contents: {contents}");

Tooling

Package Manager

$ zen add network
Adding network v1.2.3...

Testing

#[test]
fn test_addition() {
    assert_eq!(add(2, 2), 4);
}

$ zen test
Running 1 test...
test test_addition ... ok

Test result: ok. 1 passed; 0 failed
Warning: This documentation is for Zen 1.0.0. Some features may change in future versions.

For more detailed information on each topic, please refer to the specific sections in the documentation.

Join the Zen Community | Try Zen Online