if 0 {
MiHa 2015-06-13: HelloWorld-programs are supposed to be the most simple, working programs of a given language.
But I want to extend such a HelloWorld-program to a one-page - reference-card,
where all the essential features of the language are shown.
Several short programs would be ok, too.
If possible, while doing something useful (and/or funny).
Tcl by itself (without Tk) is quite simple , so an amount of code to fill about one printed page should be enough.
(The layout may need to be tweaked, e.g. printing front and back, landscape, and in 2-4 columns:)
Basic Tcl Commands to cover:
Advanced features (to include if space permits):
...
More features, to be left out, for a later lesson (too advanced, or too rarely needed for an introduction):
...
Things to be aware of:
Maybe there already are some programs here in the wiki that would qualify for such a refcard-program...
}
# HelloWorld001.tcl - 2015-06-13 - http://wiki.tcl.tk/41268 # Output a string to terminal: puts "Hello, World!" ### END ###
# HelloWorld002 - 2015-06-23 # http://ideone.com/9KlN4c # Assign value to variables, and output: set a "The answer is" set n 42 puts $a puts $n incr n ;# add 1 to a numeric variable puts "$a now $n" #END#
The answer is 42 The answer is now 43
# HelloWorld003.tcl - MiHa - 2015-06-13 # http://wiki.tcl.tk/41268 / http://ideone.com/xl0IBI # Query the time (cs as a number, td and hh as a string), # output depending on the value of the hour: set cs [clock seconds] ;# seconds since 1970-01-01 set td [clock format $cs -format "%Y-%m-%d %H:%M:%S" ] ;# timedate set hh [clock format $cs -format %H ] ;# hours (00-23) puts "cs=$cs td='$td' hh=$hh" if { $hh < "12" } { puts -nonewline "Good morning, " } else { puts -nonewline "Hello, " } puts "World!" #END#
cs=1434926575 td='2015-06-21 22:42:55' hh=22 Hello, World!
# HelloWorld004.tcl - MiHa - 2015-06-21 # http://wiki.tcl.tk/41268 / http://ideone.com/Llp8Os # Query the hour from the clock, # output text depending on the value of the hour: set cs [clock seconds] ;# seconds since 1970-01-01 set hh [clock format $cs -format %H ] ;# hours (00-23) puts "cs=$cs hh=$hh" if { $hh < "12" } { puts -nonewline "Good morning, " } elseif { $hh > "18" } { puts -nonewline "Good evening, " } else { puts -nonewline "Hello, " } puts "World!" #END#
cs=973531773 hh=17 Hello, World!
and
cs=1434927642 hh=23 Good evening, World!
Some ideas:
...
This is the Alpha-version, there will be bugs, so use with caution
...
See also: