A lightweight, interpreted scripting language
Blip is a simple, interpreted programming language designed for ease of use and flexibility. It supports variables, functions, loops, conditionals, lists, dictionaries, and built-in functions for mathematical, list, file, JSON, and HTTP operations. Blip is ideal for quick scripting tasks, API interactions, and learning programming concepts.
Blip uses a straightforward syntax with Python-like semantics. Below are the key elements:
=. No type declarations needed.func keyword, followed by parameters and a body enclosed in end;.for and while loops, with break and continue for control flow.if, else, and end; for control flow.[...], supports indexing (e.g., list[0]) and operations like append and pop.{"key": value}, supports key access (e.g., dict["key"]) or dot notation for identifiers (e.g., dict.key).# are ignored.;).{debug} at the start of a script to show execution time.Example syntax:
{debug}
x = 10;
func add(a, b)
return a + b;
end;
for i in range(1, 5)
print(i);
end;
if x > 5
print("x is greater than 5");
else
print("x is 5 or less");
end;
data = {"key": "value"};
print(data.key);
write_file("test.txt", "Hello, Blip!");
Blip provides a rich set of built-in functions for various tasks:
print(arg, ...): Prints arguments to the console, space-separated.input(prompt=""): Reads user input with an optional prompt.int(x), float(x), str(x): Type conversions.abs(x), sqrt(x), sin(x), cos(x), tan(x), asin(x), acos(x), atan(x), atan2(y, x), sinh(x), cosh(x), tanh(x): Mathematical functions.log(x), log10(x), log2(x), exp(x): Logarithmic and exponential functions.floor(x), ceil(x), round(x): Rounding functions.max(arg, ...), min(arg, ...): Maximum and minimum values.pow(x, y): Power function (x raised to y).len(x), size(x): Returns length of lists or strings.type(x): Returns the type name of x.range(start, end, step): Generates a list of numbers.append(lst, item), pop(lst, index=-1): List operations to add or remove elements.sort(lst), reverse(lst): Sort or reverse a list.sum(lst), avg(lst): Sum or average of list elements.random(), randint(a, b): Random number generation.factorial(n), gcd(a, b), lcm(a, b), mod(x, y), div(x, y): Number theory functions.is_prime(n), fib(n): Prime check and Fibonacci number.pi(), e(), deg(x), rad(x): Mathematical constants and conversions.get(url, headers=None): Sends HTTP GET request, returns dictionary with status, content, json, and error keys.post(url, data=None, headers=None): Sends HTTP POST request with JSON data, returns dictionary with status, content, json, and error keys.read_file(file), write_file(file, data), append_file(file, data): File read, write, and append operations.file_exists(file), list_dir(dir="."), delete_file(file), file_size(file): File system operations.json_parse(string), json_stringify(data), read_json(file), write_json(file, data): JSON parsing and file operations.For a full list, refer to the interpreter's b dictionary in the source code.
func fib(n)
if n <= 0
return 0;
end;
if n == 1
return 1;
end;
a = 0;
b = 1;
for i in range(2, n + 1)
temp = a + b;
a = b;
b = temp;
end;
return b;
end;
print(fib(10));
func factorial(n)
if n <= 1
return 1;
end;
return n * factorial(n - 1);
end;
print(factorial(5));
numbers = [1, 2, 3];
append(numbers, 4);
print(numbers);
print(numbers[2]);
print(numbers.length);
response = get("https://jsonplaceholder.typicode.com/todos/1");
print(response.status);
print(response.json);
data = {"title": "foo", "body": "bar", "userId": 1};
response = post("https://jsonplaceholder.typicode.com/posts", data);
print(response.status);
print(response.json);
write_file("test.txt", "Hello, Blip!");
content = read_file("test.txt");
print(content);
append_file("test.txt", "\nMore text.");
print(file_exists("test.txt"));
print(file_size("test.txt"));
data = {"name": "Blip", "version": 1.0};
write_json("config.json", data);
parsed = read_json("config.json");
print(parsed.name);
json_str = json_stringify(data);
print(json_str);
Below are common errors you may encounter when using Blip:
end;.append on a non-list variable.json_parse or file in read_json.