File: stack-q.tf

package info (click to toggle)
tf5 5.0beta8-14
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,976 kB
  • sloc: ansic: 25,499; perl: 103; makefile: 79; sh: 70
file content (30 lines) | stat: -rw-r--r-- 743 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
;;;; Stack and queue macros.
;;;; Lets you keep stacks and queues of words.  /pop and /dequeue give their
;;;; results via /echo; use $(/pop) and $(/dequeue) to capture their results.

/loaded __TFLIB__/stack-q.tf

/require lisp.tf

;;; /push <word> [<stackname>]
; push word onto stack.

/def -i push = /@test %{2-stack} := strcat({1}, " ", %{2-stack})

;;; /pop [<stackname>]
; get and remove top word from stack.

/def -i pop = \
    /eval /car %%{%{1-stack}}%; \
    /@test %{1-stack} := $$(/cdr %%{%{1-stack}})

;;; /enqueue <word> [<queuename>]
; put word on queue.

/def -i enqueue = /@test %{2-queue} := strcat(%{2-queue}, " ", {1})

;;; /dequeue [<queuename>]
; get and remove first word from queue.

/def -i dequeue = /pop %1-queue