if 0 { <> ---- **Introduction** [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 http://wiki.tcl.tk/10259%|%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: * http://wiki.tcl.tk/1669%|%Comments%|% / statements * Output: [puts] / -nonewline ** [format] * Numeric [variable]s: [set] * multiple statements / assignments in one line ** simple calculations: [incr] / [expr] * [proc] / [return] - for functions * basic flowcontrol: ** [if] / then / else / elseif / comparing ** [for] - loop, maybe also the [while]-loop / [break] / [continue] * [foreach] * String variables / quoting * [exit] Advanced features (to include if space permits): * input: [gets], [eof], [scan] / checking the input <
>This is an important topic, but likely too much for one page. * [catch] * [global] / $::var * [string]-operations (e.g. find/extract/replace char in a string, append, delete/split ...) * [data structure]s: ** [array] / [parray] ** [list] / [lassign], [lappend], [lset], [linsert], [lreplace] / [lindex], [llength] / [lrange], [lsearch], [lsort] ** [dict] * [file]-operations / [open], [close ] / [glob] ... More features, to be left out, for a later lesson (too advanced, or too rarely needed for an introduction): * [upvar] / [uplevel] * [namespace]s * [eval] * [interp] * [lambda] * [regexp] - this is very likely too complex to cover as just one small example on a general introduction page. * [switch] * [unknown] ... Things to be aware of: * comments are commands, so quotes and braces inside need to be balanced * when to use / not to use "$" with variablenames ( set i 1; puts $i; incr i $i ) Maybe there already are some programs here in the wiki that would qualify for such a refcard-program... } ---- **Program 1** ======tcl # HelloWorld001.tcl - 2015-06-13 - http://wiki.tcl.tk/41268 # Output string to terminal: puts "Hello, World!" ### EOF ### ====== Some ideas: * Table of primes * Dice-rolling ** with min/max/average * Calculate distance * Number of days between dates ... **Program 2** ======tcl # HelloWorld002.tcl - MiHa - 2015-06-13 # http://wiki.tcl.tk/41268 # http://ideone.com/xxx puts "Demo:" set i 0 foreach s { Hello , world ! } { incr i; puts "$i $s" } ### EOF ### ====== ---- **Output** ======none Demo: 1 Hello 2 , 3 World 4 ! ====== ---- **Remarks** This is the Alpha-version, there ''will'' be bugs, so use with caution <
> ... ---- '''See also:''' * http://wiki.tcl.tk/41210%|%ClockDemo%|% * ... <> Example | Tutorial