Tcl
1988fragletscriptingimperativescripting.tcl
docker run --rm --platform="linux/amd64" 100hellos/tcl:latest
MCP + fragletc
MCPstdinargs
This language supports code execution via MCP and the fragletc CLI. Stdin piping and argument passing are both supported.
Install fragletc →Tcl (Tool Command Language) is a scripting language that is used to create a wide variety of applications, including GUIs, web servers, and network clients. It is known for its simplicity and flexibility, and is often used as a "glue" language to connect different software components together.
It quickly captured my heart with the ridiculous "Hello World!" inside. Explore the tutorial here.
Hello World
#!/usr/bin/env tclsh
# BEGIN_FRAGLET
set H "H"
set e "e"
set l "l"
set o "o"
set W "W"
set r "r"
set d "d"
set excl "!"
proc string_repeat {s n} {
set res ""
for {set i 0} {$i < $n} {incr i} {
append res $s
}
return $res
}
set ll [string_repeat $l 2]
puts "$H$e$ll$o $W$o$r$l$d$excl"
# END_FRAGLETCoding Guide
Language Version
Tcl 8.6.x
Execution Model
- Interpreted, runs directly from source via
tclsh - Top-level code executes immediately
- No explicit main function required
- Commands are executed in order from top to bottom
Key Characteristics
- Everything is a string (with automatic type conversion)
- Dynamic typing
- Case-sensitive
- Command-based syntax:
command arg1 arg2 - Variables:
set var value - Braces
{}for literal strings, quotes""for substitution - Square brackets
[]for command substitution
Fragment Authoring
Write valid Tcl statements or expressions. Your fragment becomes the script body. Code executes at the top level, so commands run immediately in order. You can define procedures (procs) and use them in the same fragment.
Available Packages
Standard Tcl library is available. No additional packages are pre-installed.
Common Patterns
- Print:
puts "message"orputs {message} - Variables:
set name "value" - Command substitution:
set result [expr 2 + 2] - Procedures:
proc name {args} { body } - Lists:
set items {a b c}orlist a b c - Loops:
for {set i 0} {$i < 10} {incr i} { puts $i } - Conditionals:
if {condition} { body } - String operations:
string length $str,string toupper $str
Examples
# Simple output
puts "Hello, World!"
# Variables and expressions
set a 5
set b 10
set sum [expr $a + $b]
puts "Sum: $sum"
# Procedure definition
proc greet {name} {
return "Hello, $name!"
}
puts [greet "Alice"]
# List processing
set numbers {1 2 3 4 5}
set total 0
foreach num $numbers {
set total [expr $total + $num]
}
puts "Total: $total"
# String manipulation
set text "hello world"
set upper [string toupper $text]
puts "Uppercase: $upper"
# Conditional logic
set score 85
if {$score >= 90} {
puts "Grade: A"
} elseif {$score >= 80} {
puts "Grade: B"
} else {
puts "Grade: C"
}Caveats
- Braces
{}prevent variable substitution, quotes""allow it - Square brackets
[]execute commands immediately (command substitution) - Variables must be prefixed with
$when reading, but not when setting - Expressions require
exprcommand:expr 2 + 2not2 + 2 - Indentation is not significant (unlike Python), but good style is recommended
Fraglet Scripts
Echo Args
#!/usr/bin/env -S fragletc --vein=tcl
puts "Args: [join $argv " "]"Stdin Upper
#!/usr/bin/env -S fragletc --vein=tcl
while {[gets stdin line] >= 0} { puts [string toupper $line] }Tcl Fortune
#!/usr/bin/env -S fragletc --vein=tcl
# One from the vault: Tcl fortunes
puts "Tcl: the language that made everything a string look like a feature."Test
#!/usr/bin/env -S fragletc --vein=tcl
set H "H"
set e "e"
set l "l"
set o "o"
set W "W"
set r "r"
set d "d"
set excl "!"
proc string_repeat {s n} {
set res ""
for {set i 0} {$i < $n} {incr i} {
append res $s
}
return $res
}
set ll [string_repeat $l 2]
puts "$H$e$ll$o $W$o$r$l$d$excl"Connections
influenced by