#!/bin/sh
# procd1.tcl \
exec tclsh "$0" ${1+"$@"}
proc prco1 {} {
set xm 4
puts "$xm"
}
proc prco2 {} {
set xd 3
return $xd
}
proc adder {m n} {
set s 0
set s [expr $m + $n]
return $s
}
#############procedure when you are not sure how many arguments will be passed during calling
##############and calling procedure proc2 from inside of multi_add procedure
proc multi_add {args} {
if {$args eq ""} {
puts "got no argument"
}
puts "got $args"
set lgth [llength $args]
puts "lgth:$lgth"
set myList $args
foreach i $myList {
puts $i }
for {set i 0} {$i <= [llength $args] } {incr i} {
set j($i) [lindex $args $i]
puts "j($i)=> $j($i)"
}
#puts "$i"
set test [adder $j(0) $j(1)]
puts "test:$test"
}
####################MAIN###################
#######calling just by function name
prco1
set x [prco2]
puts "value of x : $x"
set z [adder $x 2]
puts "value of resutl: $z"
multi_add 4 3
# procd1.tcl \
exec tclsh "$0" ${1+"$@"}
proc prco1 {} {
set xm 4
puts "$xm"
}
proc prco2 {} {
set xd 3
return $xd
}
proc adder {m n} {
set s 0
set s [expr $m + $n]
return $s
}
#############procedure when you are not sure how many arguments will be passed during calling
##############and calling procedure proc2 from inside of multi_add procedure
proc multi_add {args} {
if {$args eq ""} {
puts "got no argument"
}
puts "got $args"
set lgth [llength $args]
puts "lgth:$lgth"
set myList $args
foreach i $myList {
puts $i }
for {set i 0} {$i <= [llength $args] } {incr i} {
set j($i) [lindex $args $i]
puts "j($i)=> $j($i)"
}
#puts "$i"
set test [adder $j(0) $j(1)]
puts "test:$test"
}
####################MAIN###################
#######calling just by function name
prco1
set x [prco2]
puts "value of x : $x"
set z [adder $x 2]
puts "value of resutl: $z"
multi_add 4 3
No comments:
Post a Comment