Skip to content
Haoxi Zhan edited this page Nov 29, 2013 · 13 revisions

A total of 11 stacks is used in Clojush to run the Push programs. And stack is one of the core idea of Push/Clojush. This portal brings information about stack-based languages and stacks in Clojush. The first section is an introduction to the general introduction to the ideas while the second part links to some detailed resources.

Introduction to General ideas

Stack-based programming

Stack is a data structure. The feature of a stack could be described with the word LIFO (Last In First Out). Generally, 2 operations are widely used on stacks. push would add an item on the top of a stack while pop would get the top item out from a stack. So the item which is pushed into the stack last would be on the top and it would be the first item when we are popping the stack.

A typical stack-based programming language is postscript. A very basic postscript code is:

1 2 +

1 and 2 would be pushed into the stack. When the instruction + is being executed, 2 items would be popped and the result would be pushed back to the stack. Thus in this example, 1 and 2 would be popped and the result is calculated to be 3, which would be pushed to the stack.

The stack system of Clojush

The stack system in Clojush is more complex than the one in postscript. A Push program contains only instructions. When Clojush is executing an instruction, it would find the inputs from the related stack and after calculating the result would be pushed into the target stack.

For example integer_lt compares 2 integers and decide whether the first one is lesser than the second one or not. This instruction takes 2 integers as inputs and outputs a boolean value. Thus when it is executed, Clojush would gets the inputs from the :integer stack and pushes the result into the :boolean stack.

noop

If there isn’t enough items in the inputing stack, it would be regarded as a noop, which stands for "no options". And nothing would be done.

Type safety

With this stack system, it would be very easy for automatic-generated evolving programs to deal with types. And the type safety is also guaranteed easily.

Stacks in Clojush

In Clojush, 11 stacks are defined. They are: :exec, :integer, :float, :code, :boolean, :string, :zip, :tag, :auxiliary, :return and :environment.

The stacks are defined in global.clj.

;; push-types is the list of stacks used by the Push interpreter
(def push-types '(:exec :integer :float :code :boolean :string :zip
                        :tag :auxiliary :return :environment)) ;; Stack types

Besides this definition, various functions which operates the stacks are defined in Clojush. Detailed information is in Operation on Stacks.

Clone this wiki locally