I was told to writeup what an OO queue is, so here we go
interface ITuple = {
first : any
second : any
}
interface IQueue = {
enqueue : IQueue -> any -> IQueue
pop : IQueue -> IQueue
first : IQueue -> any
empty? : IQueue -> Bool
;; dequeue : IQueue -> ITuple(IQueue, any)
;; can be implemented by doing pop and first
}
Tuple(f, s) µ this. {
first = f
second = s
}
Empy_Queue µ this. {
enqueue = λa. Cons_Queue(a, this)
pop = nil
first = nil
empty? = true
}
Cons_Queue(item, queue) µ this. {
enqueue = λa. Cons_Queue(a, this)
pop = if empty?(queue) then queue else Cons_Queue(item, pop(queue))
first = if empty?(queue) then item else first(queue)
empty? = false
}
This should be a correct and complete implementation of an OO queue.
We made two objects, one which is the empty_queue which is always empty, and a cons_queue that can cons items.
If so desired I can implement this in logtalk and have it actually run