mirror of
https://github.com/bearlanguageorg/bear.git
synced 2026-08-26 15:37:18 +00:00
Production pass: floats, GC, type checking, and tooling
Adds floats, bitwise ops, UTF-8 strings with methods, try/catch, closures, generics validation, a compile-time type checker, a mark-and-sweep GC, source-level debug info, constant folding, and the repl/fmt/package-manager commands. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
// generic function syntax (V-style type parameters)
|
||||
|
||||
// generic functions: type params are parsed but the VM handles types dynamically
|
||||
fn first[T](arr) {
|
||||
return arr[0]
|
||||
}
|
||||
|
||||
fn last[T](arr) {
|
||||
let n = len(arr)
|
||||
return arr[n - 1]
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// works with integers
|
||||
let nums = [10, 20, 30]
|
||||
println("first num: ${first[int](nums)}")
|
||||
println("last num: ${last[int](nums)}")
|
||||
|
||||
// works with strings
|
||||
let words = ["hello", "world", "foo"]
|
||||
println("first word: ${first[string](words)}")
|
||||
println("last word: ${last[string](words)}")
|
||||
|
||||
// type args are optional (VM is dynamically typed)
|
||||
println("first (no type arg): ${first(nums)}")
|
||||
}
|
||||
Reference in New Issue
Block a user