Tuesday, 7 February 2017

Procedures in tcl-tk

Check it @ Coding Ground





#!/usr/bin/tclsh

#y= fun(k,u,v)

proc proc_by_copy {a b c}  {

#$set a 1

#set b 2

#set c 3

puts ">>>>>>>inside by copy a,b,c:$a $b $c"

}

proc proc_by_reference { a b c } {

upvar $a a_

upvar $b b_

upvar $c c_

set a_ [expr $a_*2]

set b_ [expr $b_*2]

set c_ [expr $c_*2]

puts ">>>>>>inside by reference a,b,c: $a_ $b_ $c_"

}

proc myfunc {x} {

return [expr 2 * $x]

 }

proc proc_by_global { } {



global K

global L

global M



puts ">>>>>inside by copy K,L,M: $K $L $M\n\n"

}

###################\/main

set A 2

set B 4

set C 6

puts "\n\n A,B,C before by copy :$A $B $C"

proc_by_copy $A $B $C

puts " A,B,C after by copy : $A $B $C\n\n"



set A 2

set B 4

set C 6



puts "A,B,C before by ref : $A $B $C"

proc_by_reference A B C

puts " A,B,C after by ref :$A $B $C"

set X 3

set Y [myfunc $X]

puts "\n\nY=myfunc(X=$X) is $Y\n\n"



set K 10

set L 20

set M 30

proc_by_global

No comments:

Post a Comment