> I need to have [snip] a stack data structure.

Here's a very rudimentary implementation using strings -- items
on the stack cannot contain spaces, and no error checking is
performed, but you get the idea.  If necessary, the macros
can be generalized to accept the name of the stack string as
argument (instead of it being hard-coded), so that multiple
stacks can be handled simultaneously using the same macros.

.\"
.\" ----------------------------------------------------------------
.de push
.ds stack \\$1 \\*[stack]
..
.de pop
.pop1 \\$1 \\*[stack]
..
.de pop1
.ds \\$1 \\$2
.shift 2
.ds stack \\$*
..
.\" ----------------------------------------------------------------
.sp 2c
.push foo
pushed `foo', stack now contains `\*[stack]'
.br
.push xxx
pushed `xxx', stack now contains `\*[stack]'
.br
.push hello
pushed `hello', stack now contains `\*[stack]'
.br
.pop result
popped `\*[result]', stack now contains `\*[stack]'
.br
.push world
pushed `world', stack now contains `\*[stack]'
.br
.pop result
popped `\*[result]', stack now contains `\*[stack]'
.br
.pop result
popped `\*[result]', stack now contains `\*[stack]'
.br
.pop result
popped `\*[result]', stack now contains `\*[stack]'
.br




Reply via email to