1 # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
3 # $Id: Push.tcl,v 1.4 2003-01-22 02:59:02 mikeclarkson Exp $
6 ############################################################
7 # Netmath Copyright (C) 1998 William F. Schelter #
8 # For distribution under GNU public License. See COPYING. #
9 ############################################################
14 #-----------------------------------------------------------------
16 # pushl -- push VALUE onto a stack stored under KEY
22 #----------------------------------------------------------------
26 proc pushl
{ val key
} {
28 append __pushl_ar
($key) " [list $val]"
33 #-----------------------------------------------------------------
35 # peekl -- if a value has been pushl'd under KEY return the
36 # last value otherwise return DEFAULT. If M is supplied, get the
37 # M'th one pushed... M == 1 is the last one pushed.
38 # Results: a previously pushed value or DEFAULT
42 #----------------------------------------------------------------
44 proc peekl
{key
default {m
1}} {
46 if {![info exists __pushl_ar
($key)]} {
48 } elseif
{ [catch { set val
[set __pushl_ar
($key) ] } ] } {
52 if { $m > 0 && $m <= $n } {
53 return [lindex $val [incr n
-$m]]
63 #-----------------------------------------------------------------
65 # popl -- pop off last value stored under KEY, or else return DFLT
67 # Results: last VALUE stored or DEFAULT
69 # Side Effects: List stored under KEY becomes one shorter
71 #----------------------------------------------------------------
73 proc popl
{ key dflt
} {
76 if { [catch { set val
[set __pushl_ar
($key) ] } ] } {
80 set result
[lindex $val [incr n
-1]]
83 set __pushl_ar
($key) [lrange $val 0 [expr {$n -1}]]
85 unset __pushl_ar
($key)
93 #-----------------------------------------------------------------
95 # clearl -- clear the list stored under KEY
99 # Side Effects: clear the list stored under KEY
101 #----------------------------------------------------------------
103 proc clearl
{ key
} {
105 catch { unset __pushl_ar
($key) }
110 ## endsource push.tcl