Code Examples
Explore the power and elegance of Clyp through these comprehensive examples
Hello World
A simple greeting program showing variable declaration and function definition.
# A simple "Hello, World!" program in Clyp
str name = "World";
print("Hello, " + name + "!");
# Define a function to greet someone
def greet(str person) returns str {
return "Greetings, " + person + "!";
};
# Call the function and print the result
print(greet("Clyp Developer"));
Data Structures
Working with lists, chunking, and flattening operations.
# Working with data structures in Clyp
list[int] numbers = [1, 2, 3, 4, 5, 6];
print("Original list:");
print(numbers);
# Get chunks of the list
list[list[int]] chunks = chunk(numbers, 2);
print("List chunked into size 2:");
print(chunks);
# Flatten the list back
list[int] flattened = flatten(chunks);
print("Flattened list:");
print(flattened);
# Repeat loop for iteration
repeat [3] times {
print("Hello from a repeat loop!");
};
Advanced Features
Classes, conditionals, and the powerful pipeline operator.
# Advanced Clyp features
class Counter {
int count = 0;
def increment(self) returns null {
self.count = self.count + 1;
};
def get_count(self) returns int {
return self.count;
};
};
let c = Counter();
c.increment();
c.increment();
print("Count is: " + toString(c.get_count()));
# Pipeline operator example
def double(int n) returns int {
return n * 2;
};
def add_five(int n) returns int {
return n + 5;
};
let initial_value = 10;
# Pipeline passes value left to right
let final_value = initial_value |> double |> add_five;
print("Pipeline result: " + toString(final_value));