1
0
Fork 0
forked from fun/fun

Added byte as a new datatype. (0.9.3)

This commit is contained in:
Johannes Findeisen 2025-09-28 23:10:49 +02:00
commit 2a1b74f13f
4 changed files with 61 additions and 6 deletions

View file

@ -0,0 +1,31 @@
#!/usr/bin/env fun
// Byte + for-loop demonstration
print("=== byte with hex literal and clamping ===")
byte b = 0x1223 // 0x1223 -> 0x23 after 8-bit clamp
print(b) // -> 35
b = 0xFF
print(b) // -> 255
b = 0x1FF // 0x1FF -> 0xFF after clamp
print(b) // -> 255
print("")
print("=== for-loop reassigning a byte variable (shows clamping near the top end) ===")
byte acc = 0
for i in range(250, 260)
acc = i // will clamp at 255
print(acc)
print("")
print("=== dynamic vs typed ===")
x = 0xAB
print(typeof(x)) // -> "Number"
x = "now string" // dynamic variable can change type
print(typeof(x)) // -> "String"
// Typed byte must remain numeric (uint8):
// b = "oops" // Uncomment to see a runtime type error