mirror of
https://github.com/bearlanguageorg/bear.git
synced 2026-08-26 16:07:01 +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,44 @@
|
||||
// array and string slicing: arr[1..3], arr[1:], str[0..5]
|
||||
|
||||
fn main() {
|
||||
// --- array slicing ---
|
||||
let nums = [10, 20, 30, 40, 50]
|
||||
|
||||
// basic slice: arr[start..end]
|
||||
let mid = nums[1..3]
|
||||
println(mid) // [20, 30]
|
||||
|
||||
// slice from start
|
||||
let first_two = nums[0..2]
|
||||
println(first_two) // [10, 20]
|
||||
|
||||
// slice to end (open-ended)
|
||||
let tail = nums[2..]
|
||||
println(tail) // [30, 40, 50]
|
||||
|
||||
// single element slice
|
||||
let single = nums[3..4]
|
||||
println(single) // [40]
|
||||
|
||||
// --- string slicing ---
|
||||
let greeting = "hello, world!"
|
||||
|
||||
// basic substring
|
||||
let hello = greeting[0..5]
|
||||
println(hello) // "hello"
|
||||
|
||||
// slice from index
|
||||
let world = greeting[7..]
|
||||
println(world) // "world!"
|
||||
|
||||
// slice to index
|
||||
let hello_comma = greeting[0..6]
|
||||
println(hello_comma) // "hello,"
|
||||
|
||||
// --- slicing in expressions ---
|
||||
let data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
let first = data[0..3]
|
||||
let last = data[7..]
|
||||
println(first)
|
||||
println(last)
|
||||
}
|
||||
Reference in New Issue
Block a user