i am learning rust and tcl by writing a tcl interpreter. i chose tcl because it is "very simple" and actually used for some things.
implements a (probably broken) subset of tcl:
- syntax
- bare
words $variablesubstitution{braced words}${braced variable}substitution[command args]substituion"quoted strings""$variable and [command]"substitution in quoted strings
- bare
- builtin commands
breakcontinuedict create ?key value ...?dict get dictValue ?key ...?dict exists dictValue key ?key ...?dict set dictVariable key ?key ...? valueexpr arg ?arg arg ...?foreach varlist1 list1 ?varlist2 list2 ...? bodyglobal ?varname ...?if expr1 ?then? body1 elseif expr2 ?then? body2 elseif ... ?else? ?bodyN?incr varName ?increment?info exists varNamelappend listVar ?value value value ...?lindex listVal indexlist ?arg arg ...?llength listVallreverse listValproc name args bodyputs stringreturn ?result?set varName ?value?string index string charIndexstring length stringunknown cmdName ?arg arg ...?uplevel ?level? arg ?arg ...?upvar ?level? otherVar myVar ?otherVar myVar ...?while test body
this is enough to write simple scripts like:
proc fib {x} {
if {$x <= 0} {
return 0
}
if {$x == 1} {
return 1
}
return [expr {[fib [expr {$x - 1}]] + [fib [expr {$x - 2}]]}]
}
set i 1
while {$i < 30} {
puts [fib $i]
set i [expr {$i + 1}]
}cargo build --release
# repl
./target/release/tanaid
# run a script
./target/release/tanaid path/to/file.tclInstall Rust with rustup:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shRun any Cargo command from the repo root to install/use the toolchain:
cargo buildRun the compiler checks with:
cargo check --all-targets