Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: Re: Re: Re: Why does Perl use dynamic scoping?

by Boots111 (Hermit)
on Feb 10, 2003 at 03:50 UTC ( [id://234007]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Why does Perl use dynamic scoping?
in thread Why does Perl use dynamic scoping?

All~

I can try, but most of what I say is just from memory of the Programming Languages class that I took... Thus I cannot guarantee perfect recall...

The place where we learned about this is in closures and functional languages. In a purely functional language one cannot assign to variables (as that would be a side-effect). So the question becomes how is binding done, lexically or dynamically. In lexical binding you look for the most closely nested variable of that name in the code. In dynamic binding you look for the most closely defined variable in the call stack. Thus one code snippet can produce to different values depending on the binding scheme:
bar(z) { return x+z; } baz(x) { return bar(2); }
In such code, bar will access the x from baz, if the language has dynamic scoping.

I was told that the way to think of this in a language with side-effects is that all variables can be thought of as global, since they all access the most recently referenced version. So what we have here is fluid scoping which causes changes to a variable not to propogate to the outside world, by causing them to revert at end of scope. This would happen automatically in a language without side-effects, because you cannot assign to a variable...

That is at least the way I understand it. I could be mistaken.

Boots
---
Computer science is merely the post-Turing decline of formal systems theory.
--???

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://234007]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-23 23:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found