calog/examples/scripts/languages/tcl.tcl
2026-07-04 23:22:22 -05:00

20 lines
850 B
Tcl

# A guided tour of Tcl (9.0) running on calog.
# Demonstrates: set/expr, a foreach loop, a list and a dict, then the jsonStringify/jsonParse and
# cryptoHashSha256 natives. puts works; real file/socket IO is provided by calog's fs*/net* natives
# (not Tcl channels), so scripts stay uniform. Tcl values are strings, so a numeric literal handed
# to a native is coerced to an int.
# run: bin/calog examples/scripts/languages/tcl.tcl
set nums {1 2 3 4 5}
set total 0
foreach n $nums { set total [expr {$total + $n}] }
puts "nums = $nums, total = $total"
set user [dict create name ada age 36]
puts "user as JSON: [jsonStringify $user]"
set parsed [jsonParse {{"lang":"tcl","ints":[10,20,30]}}]
puts "parsed lang = [dict get $parsed lang], second int = [lindex [dict get $parsed ints] 1]"
puts "sha256(calog) = [cryptoHashSha256 calog]"
calogExit 0