Install rust https://www.rust-lang.org/tools/install then clone this repository then run
cargo r
Dyna Language Documentation
- Overview
- Variables and Immutability
- Control Flow and Pattern Matching
- Functions
- Arrays
- Type System and Type Checking
- Examples
Dyna is a language inspired by Rust, focusing on immutability, strict typing, and pattern matching. This documentation outlines the syntax, core concepts, and usage patterns of Dyna, guiding developers through its functionality.
In Dyna, variables are immutable by default. Variables are declared using the let
keyword. To make a variable mutable, add the mut
keyword.
let variable_name = String::new(); // Immutable variable
let mut variable_mutable = String::from("Hello"); // Mutable variable
The final expression in a block does not require a semicolon:
let variable = if true {
String::new()
} else {
String::from("false")
};
Dyna includes pattern matching and supports user-defined types such as enumerations (enum
) and structs.
enum T {
Some(String),
None,
}
let var = T::None;
match var {
T::Some(string) => println!(string),
T::None => (),
}
Functions in Dyna are declared with the fn
keyword. Each parameter requires an explicit type.
fn name_of_function(mut arg: String) -> String {
arg.push_str("value");
arg
}
Functions can specify a return type using ->
. The default return type is ()
(unit type).
Dyna supports compile-time arrays, requiring explicit types since type inference is not supported.
let array: &[u8] = [1, 2, 3, 4];
Dyna performs compile-time type checking to prevent mismatched types. While Dyna does not yet support advanced type theories, concrete type matching ensures type consistency.
fn name_of_function(mut arg: String) -> String {
arg.push_str("value");
arg
}
let array: &[u8] = [1, 2, 3, 4];
// Error: Expected `String`, found `&[u8]`
name_of_function(array);
Below are several examples demonstrating Dyna’s features.
let x = 5; // Immutable
let mut y = 10; // Mutable
y += x;
enum Option {
Some(i32),
None,
}
let value = Option::Some(10);
match value {
Option::Some(num) => println("Value"),
Option::None => println("No value"),
}
fn add_prefix(mut text: String) -> String {
text.push_str("prefix_");
text
}
let arr: &[u8] = [1, 2, 3];
// Error: Expected `String`, found `&[u8]`
add_prefix(arr);