开发者

Why scripting languages use dynamic scope rule?

开发者 https://www.devze.com 2023-01-26 10:37 出处:网络
do any one know why scripitng langu开发者_StackOverflow中文版ages use dynamic scope rule ? I can not find any thing about this matter on the Internet.Scripting languages generally do not have dynamic

do any one know why scripitng langu开发者_StackOverflow中文版ages use dynamic scope rule ? I can not find any thing about this matter on the Internet.


Scripting languages generally do not have dynamic scoping. Scheme, Lua, Ruby, and Python are all lexically scoped. Only a few languages still around use dynamic scope because it makes it painfully hard to reason about what your code is doing by looking at it.

When you say "dynamic scoping" what are you trying to describe?


Partly because they can. Scripting languages already have substantial overhead to access variables compared to compiled languages. Adding dynamic scoping is easy, as is adding fun features like closures.


There is a useful overview of dynamic scoping here: From http://c2.com/cgi/wiki?DynamicScoping

This includes the following:

"Dynamic scoping is useful as a substitute for globally scoped variables. A function can say "let current_numeric_base = 16; call other functions;" and the other functions will all print in hexadecimal. Then when they return, and the base-setting function returns, the base will return to whatever it was."

0

精彩评论

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