26 lines
671 B
Plaintext
26 lines
671 B
Plaintext
#import system.
|
|
#import system'collections.
|
|
#import extensions.
|
|
|
|
#symbol program =
|
|
[
|
|
// Create a queue and "push" items into it
|
|
#var queue := Queue new.
|
|
|
|
queue push:1.
|
|
queue push:3.
|
|
queue push:5.
|
|
|
|
// "Pop" items from the queue in FIFO order
|
|
console writeLine:(queue pop). // 1
|
|
console writeLine:(queue pop). // 3
|
|
console writeLine:(queue pop). // 5
|
|
|
|
// To tell if the queue is empty, we check the count
|
|
console writeLine:"queue is ":((queue length == 0) iif:"empty":"nonempty").
|
|
|
|
// If we try to pop from an empty queue, an exception
|
|
// is thrown.
|
|
queue pop | if &Error: e [ console writeLine:"Queue empty.". ].
|
|
].
|