An example of a procedure with variable number of arguments is

proc avg {numbers} {
  set sum 0
  foreach number $numbers {
    set sum [expr $sum + $number]
  }
  set average [expr $sum/[llength $numbers]]
  return $average
}
puts [avg {50 50 50 60}]
puts [avg {50 50 50}]

Result:

52
50

Discover more from Tips and Hints for Aerospace Engineers

Subscribe now to keep reading and get access to the full archive.

Continue reading