开发者

If a queue was used instead of a stack for activation records, what would our programs be like?

开发者 https://www.devze.com 2023-02-01 00:26 出处:网络
While the stack can give us nested function calls (and probably more), what would a queue give us? Call-after-exit? Would there be any use at all?

While the stack can give us nested function calls (and probably more), what would a queue give us? Call-after-exit? Would there be any use at all?

Are there any readings on this topic?

开发者_JAVA百科I'm curious, this is not homework.


I think you're looking at this backwards: it's simply not true that someone somewhere decided arbitrarily to use a stack and this determined the structure of programs from then on. It's the other way round: programmers wanted arbitrarily nested (and recursive) subroutine calls, and developed the stack structure to implement this. Queues are used to implement different requirements (e.g. scheduling, breadth-first graph traversal).


A queue can be used for tasks - a job queue. A language could support procedure calls which insert tasks into a queue.


I think this is somewhat related to what functional programming is all about. For instance, monads is a way of describing your program as a chain of sequential operations which take the results of the previous operation as their inputs.


It's called Cheney-on-the-MTA.

0

精彩评论

暂无评论...
验证码 换一张
取 消