开发者

Do stack-based languages have a concept of scope?

开发者 https://www.devze.com 2022-12-11 21:17 出处:网络
Do stack-based languages have a concept of scope?It would seem to me that if function parameters are placed on the stack before the function exe开发者_如何学运维cutes, that they do in an unorthodox so

Do stack-based languages have a concept of scope? It would seem to me that if function parameters are placed on the stack before the function exe开发者_如何学运维cutes, that they do in an unorthodox sort of way.

Or, I could be trying to impose an abstraction that doesn't quite fit.


Scope is a concept that is applied to languages with named variables. In a purely stack-based language, there may not be any named variables and therefore the concept of scope does not apply. Useful stack-based languages do have named variables, and may certainly incorporate the concept of scope.

As a concrete example, Wikipedia has the following to say about Forth:

Data objects defined by these and similar words are global in scope. The function provided by local variables in other languages is provided by the data stack in Forth (although Forth also has real local variables). Forth programming style uses very few named data objects compared with other languages; typically such data objects are used to contain data which is used by a number of words or tasks (in a multitasked implementation).

0

精彩评论

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