Small example programs for tcl

#1.tcl keywords and variables are case sensitve.Filenames are not casesensitive

#2.puts $i AND puts "$i" are same

#3.arguments should be present at macro

#4.Unknown variables .we get error

puts "welcome to tcl"

set i 5

if {$i<10} {

puts "i value is $i" }

for { set i 6} {$i<9} {incr i } {

puts " i value is $i" }

while { $i<12} {

puts "i value is $i"

incr i }

for { set k 5 } {$k>0} {incr k -1} {

puts "k value is $k" }

set j [expr {$i+1} ]

puts "j value is $j"

proc macro1 {code} {

set id $code

set k1 [string index $id 0]

set k2 [string index $id 1]

set k3 [string index $id 2]

puts "the value of k1 is $k1 $k2 $k3"

}

proc macro3 {bc} {

puts "call another macro"

proc macro4 {dc} {

puts "this is another macro"

}

}

proc optional {a b c {d ""} } {

if {$d eq ""} {

puts "there is no d value" } else {

puts "d value is $d" }

}

set n 21

if {n!=20} {

puts "n is not 20" }

proc return1 { x y } {

set a $x

set b $y

set c [expr {$a+$b}]

return $c

}

puts "ur return value is :[return1 10 20]"

proc file1 {d} {

set fp [open "D:\\sample.txt" r]

while {[gets $fp data]>=0} {

puts [gets $fp data]

puts $data

}

close $fp

}