The FlavorLang Standard Library provides a comprehensive set of built-in functions for common programming tasks. This document details each function's syntax, behavior, and usage.
- Core Functions
- Best Practices
- License
Converts a value to its string representation.
Parameters:
value
: any
Returns:
string
: string representation of the value
Examples:
string(42); # "42"
string(3.14); # "3.14"
string(True); # "True"
Converts a value to a floating-point number.
Parameters:
value
: string or numeric value
Returns:
float
: floating-point representation- Raises error if conversion fails
Examples:
float("3.14"); # 3.14
float("42"); # 42.0
float("-0.5"); # -0.5
Converts a value to an integer.
Parameters:
value
: string or numeric value
Returns:
int
: Integer representation- Raises error if conversion fails
Examples:
int("42"); # 42
int(3.14); # 3
int("-17"); # -17
Reads a line of input from the terminal with an optional prompt.
Parameters:
prompt
: any value
Returns:
string
: User input line
Examples:
let name = sample(); # Waits for user input
Outputs values to the terminal.
Parameters:
*args
: Values to outputnewline
: Boolean flag for newline (optional)
Examples:
serve("Hello"); # Hello\n
serve("No", "newline", False); # No newline
Raises an error with specified message(s).
Parameters:
*messages
: Error message components
Examples:
burn("Invalid input:", value);
Generates a random float between 0 and 1.
Returns:
float
: Random value in [0.0, 1.0]
Generates a random integer between 0 and max.
Parameters:
max
: Upper bound (exclusive)
Returns:
int
: Random value in [0, max)
Generates a random integer in specified range.
Parameters:
min
: Lower bound (inclusive)max
: Upper bound (exclusive)
Returns:
int
: Random value in [min, max)
Examples:
random(); # 0.0 to 1.0
random(10); # 0 to 9
random(5, 10); # 5 to 9
Rounds a floating-point number down to the nearest integer.
- value: A floating-point number.
- int: The largest integer less than or equal to value.
serve(floor(3.8)); # Output: 3
serve(floor(-2.4)); # Output: -3
Rounds a floating-point number up to the nearest integer.
- value: A floating-point number.
- int: The smallest integer greater than or equal to value.
serve(ceil(3.2)); # Output: 4
serve(ceil(-2.8)); # Output: -2
Rounds a floating-point number to the nearest integer.
- value: A floating-point number.
- int: The nearest integer to value.
serve(round(3.5)); # Output: 4
serve(round(-2.5)); # Output: -2
Returns the absolute value of a number.
- numeric: An integer or floating-point number.
- numeric: The absolute value of the input.
serve(abs(-42)); # Output: 42
serve(abs(-3.8)); # Output: 3.8
Returns current UNIX timestamp.
Returns:
int
: Seconds since Unix epoch (1st January 1970 at 00:00:00 UTC)
Examples:
let now = get_time();
Reads entire file content.
Parameters:
path
: File path
Returns:
string
: File contents- Raises error if file not found
Writes content to file (overwrites).
Parameters:
path
: File pathcontent
: Data to write
Appends content to file.
Parameters:
path
: File pathcontent
: Data to append
Returns collection length.
Parameters:
collection
: string or Array
Returns:
int
: Number of elements
Examples:
length([1,2,3]); # 3
length("hello"); # 5
Pauses execution.
Parameters:
milliseconds
: Delay duration
Examples:
sleep(1000); # Pause for 1 second
- Always check file operations for errors
- Use type conversion functions defensively
- Handle random number generation edge cases
- Consider performance implications of sleep
- Validate user input from
sample()
This project is licensed under the Apache 2.0 License β see the LICENSE file for details.
Β© 2024-2025 Kenneth Oliver. All rights reserved.