Version 3 of HelloWorld

Updated 2015-06-21 16:20:14 by MiHa

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 quite simple , so an amount of code to fill about one printed page should be enough.

Basic features to cover:

  • Comments
  • Output / format
  • Numeric variables
  • String variables / quoting
  • simple calculations / incr / expr
  • if / then / else
  • for - loop, maybe while-loop
  • foreach
  • proc / return

Advanced features (to include if space permits):

  • input / checking the input
  • catch
  • string-operations (e.g. find/extract/replace char in a string, append, delete/split ...)
  • data-structures: array / list / dict
  • file-operations

...

Even more advanced features (to be left out, for a later lesson):

  • upvar / uplevel
  • namespaces
  • 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

  # HelloWorld001.tcl - 2015-06-13 - http://wiki.tcl.tk/41268
  # Output string to terminal:

  puts "Hello, World!"

  ### EOF ###

Program 2

 # 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

Demo:
1 Hello
2 ,
3 World
4 !

Remarks

This is the Alpha-version, there will be bugs, so use with caution
...


See also: