latest pushes
This commit is contained in:
100
bellronos_file/hello_world.bellronos
Normal file
100
bellronos_file/hello_world.bellronos
Normal file
@@ -0,0 +1,100 @@
|
||||
# example.bellronos
|
||||
|
||||
import math
|
||||
import io
|
||||
import string
|
||||
|
||||
define calculate_circle_area(radius: float) -> float:
|
||||
return math.pi * radius * radius
|
||||
|
||||
define greet(name: string) -> none:
|
||||
io.print("Hello, " + string.to_upper(name) + "!")
|
||||
|
||||
class Person:
|
||||
define __init__(self, name: string, age: int) -> none:
|
||||
self.name = name
|
||||
self.age = age
|
||||
|
||||
define introduce(self) -> none:
|
||||
io.print("My name is " + self.name + " and I'm " + string.to_string(self.age) + " years old.")
|
||||
|
||||
define main() -> none:
|
||||
# Basic operations and function calls
|
||||
set radius to 5.0
|
||||
set area to calculate_circle_area(radius)
|
||||
io.print("The area of a circle with radius " + string.to_string(radius) + " is " + string.to_string(area))
|
||||
|
||||
greet("Bellronos")
|
||||
|
||||
# Class usage
|
||||
set person to Person("Alice", 30)
|
||||
person.introduce()
|
||||
|
||||
# Closures
|
||||
set multiplier to closure (x: int) -> int: return x * 2
|
||||
io.print("Doubled 5: " + string.to_string(multiplier(5)))
|
||||
|
||||
# Generators
|
||||
define count_to(n: int) -> generator:
|
||||
set i to 0
|
||||
while i < n:
|
||||
yield i
|
||||
set i to i + 1
|
||||
|
||||
for num in count_to(5):
|
||||
io.print("Generated number: " + string.to_string(num))
|
||||
|
||||
# Async/await (simulated)
|
||||
async define fetch_data() -> string:
|
||||
# Simulating an asynchronous operation
|
||||
io.print("Fetching data...")
|
||||
return "Data fetched successfully"
|
||||
|
||||
async define process_data() -> none:
|
||||
set result to await fetch_data()
|
||||
io.print("Processing result: " + result)
|
||||
|
||||
process_data()
|
||||
|
||||
# Language interoperability
|
||||
set c_code to "
|
||||
#include <stdio.h>
|
||||
int main() {
|
||||
printf(\"Hello from C!\\n\");
|
||||
return 0;
|
||||
}
|
||||
"
|
||||
io.print(execute_c(c_code))
|
||||
|
||||
set python_code to "
|
||||
print('Hello from Python!')
|
||||
"
|
||||
io.print(execute_python(python_code))
|
||||
|
||||
set js_code to "
|
||||
console.log('Hello from JavaScript!');
|
||||
"
|
||||
io.print(execute_javascript(js_code))
|
||||
|
||||
set java_code to "
|
||||
public class Temp {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(\"Hello from Java!\");
|
||||
}
|
||||
}
|
||||
"
|
||||
io.print(execute_java(java_code))
|
||||
|
||||
set rust_code to "
|
||||
fn main() {
|
||||
println!(\"Hello from Rust!\");
|
||||
}
|
||||
"
|
||||
io.print(execute_rust(rust_code))
|
||||
|
||||
set swift_code to "
|
||||
print(\"Hello from Swift!\")
|
||||
"
|
||||
io.print(execute_swift(swift_code))
|
||||
|
||||
main()
|
Reference in New Issue
Block a user