Huge refactor: "apply" is now a normal function, "stack" a native List.

The state now stores a "queue", along with the "stack". This makes it
possible to create functions which modify the queue, and thus removes
the special case that was used for implementing "apply".

Also fixes the bug in "apply" whose test was commented out till now.