1
0
Fork 0
forked from fun/fun

Added to_string() and to_number() functions as built-ins.

This commit is contained in:
Johannes Findeisen 2025-09-15 03:45:26 +02:00
commit 559400a866
11 changed files with 113 additions and 3 deletions

View file

@ -1,3 +1,5 @@
#!/usr/bin/env fun
// Arrays basics
arr = [1, 2, 3]
print(arr) // -> [1, 2, 3]

View file

@ -1,3 +1,5 @@
#!/usr/bin/env fun
// Advanced Arrays Demo
// Start with a basic array

View file

@ -1,3 +1,5 @@
#!/usr/bin/env fun
// for-in over an array literal
for x in [1, 2, 3]
print(x) // prints: 1, then 2, then 3

View file

@ -0,0 +1,37 @@
#!/usr/bin/env fun
// Conversions and length built-ins demo
// len on array and string
print(len([1, 2, 3])) // -> 3
print(len("hello")) // -> 5
// to_number with various string inputs
print(to_number("42")) // -> 42
print(to_number(" -7 ")) // -> -7
print(to_number("12a")) // non-numeric suffix -> 0
print(to_number("")) // empty -> 0
print(to_number(" ")) // spaces -> 0
// to_string on numbers and arrays
print(to_string(42)) // -> "42" (printed as 42)
arr = [1, 2]
s = to_string(arr) // -> "[array n=2]"
print(s)
// combine to_string with concatenation
print("val=" + to_string(99)) // -> "val=99"
/* Expected output:
3
5
42
-7
0
0
0
42
[array n=2]
val=99
*/

View file

@ -1,3 +1,5 @@
#!/usr/bin/env fun
// Nested loops: break and continue behavior
// 1) Nested for range: inner continue on j==2, inner break on j==4, outer break on i==3

View file

@ -1,4 +1,5 @@
#!/usr/bin/env fun
// Strings test: concatenation with variables and literals, functions returning strings
print("=== strings test start ===")