take

Richard Suchenwirth 2007-05-08 - The functionality of take is to retrieve the value from a variable, which is then unset. This is very simple, as you'll immediately see, but can be useful - I needed it for the global textvariable of a dialog. As the variable was named like the dialog window, which in turn had a name constructed with clock clicks, the global variables causes pollution of ::. By using take when returning the result, the variable is now immediately unset.

proc take _var {
    upvar 1 $_var var
    return [set var][unset var]
}

NEM take is also the name of a function in Haskell (and possibly other Functional Programming languages) that returns the first n elements in a list:

proc take {n xs} { lrange $xs 0 [incr n -1] }

MJ - Or in 8.5:

proc take {n xs} { lrange $xs 0 $n-1 }