Thursday, January 10, 2019

The nature of stacks

Well registers can be better understood using graph theory, stacks can be better understood as total orders. Stacks, lists, vectors, and other related structures can all be classified as totally ordered data structures. Their underlying structure is that of a total order, but they are represented differently so that certain operations work differently on them. Stacks are optimized to deal with the top of the stack by pushing and popping elements from the top. The operations of push and pop are reverse to one another. This makes for an ideal implementation of stacks.

The relationship between lists and stacks is the reason why Lisp is so amenable towards programming on stack machines. Lists, which are fundamental to Lisp, and stacks are both totally ordered data structures. As a result, in order to make a Lisp dialect that works on a stack machine, all that you have to do is map between these two isomorphic data structures. Ideally, a Lisp dialect can be created for a stack machine which exposes all the aspects of its functionality to the user.

No comments:

Post a Comment