Next: , Previous: , Up: actor-lib: A standard library of sorts   [Contents][Index]


6.12 Pushdown

The (goblins actor-lib pushdown) module provides actors representing pushdown automata.

Procedure: spawn-pushdown-pair [initial-refr #f]

Return a pd-stack and pd-forwarder as values, which together represent a pushdown automaton. initial-refr, if provided, is the initial object on the stack.

A pd-stack has four methods:

  • push refr: Add refr to the top of the stack.
  • spawn-push constructor args ...: Spawn the actor constructed by constructor, passing the current top of the stack and the arguments args to the constructor; then add the new actor to the top of the stack. Return a reference to the new actor. This method facilitates implementing the State design pattern.
  • pop: Return the top of the stack. Calling pop on an empty stack is an error.
  • empty?: Return #t if the stack is empty, else #f.

A pd-forwarder simply invokes the top actor of the stack with whatever arguments it is passed.

> (use-modules (goblins actor-lib cell))
;; enter a vat
> (define a-chest (spawn ^cell 'sword))
> (define b-chest (spawn ^cell 'gold))
> (define-values (pd-stack pd-fowarder)
    (spawn-pushdown-pair a-chest))
> ($ pd-forwarder)
=> 'sword
> ($ pd-stack 'push b-chest)
> ($ pd-forwarder 'wand)
> ($ b-chest)
=> 'wand
> ($ pd-stack 'spawn-push ^cell)
=> #<local-object ^cell>
> ($ pd-forwarder)
=> #<local-object ^cell>
> ($ ($ pd-forwarder))
=> 'wand
> ($ pd-stack 'pop)
=> #<local-object ^cell>
> ($ pd-stack 'empty?)
=> #f
Persistence Environment: pushdown-env