Also, is dynamic scoping still hanging around just for posterity? Is Perl moving away from dynamic scoping?

"No" and "No" in my opinion :-)

I don't need dynamic scoping often, but when I do I want it there ready and waiting.

I think many of the perceived problems with dynamic scope and perl are due to the fact that it was around before lexical variables - so people had to be re-educated to use lexicals where appropriate.

Removing dynamic scope because some people misuse it where lexicals would be more appropriate would be like removing map because some people misuse it in a void context instead of foreach :-)

Other languages allow you to do even more with dynamic scoping. For example Pop-11's dlocal statement allows you to dynamically scope arbritary expressions as well as variables. For example (taken from Pop-11 docs):

;;; make a three element list vars list =[1 2 3]; define test(); ;;; dynamically scope the second element dlocal %hd(tl(list))%; [original list ^list]=> ;;; update second element 5 -> hd(tl(list)); [updated list ^list] => enddefine; test(); ** [original list [1 2 3]] ** [updated list [1 5 3]] ;;; But the value of hd(tl(list)) has been restored on exit: list => ** [1 2 3]

(Yes, I know you can use tie in perl to bind functionality to dynamic scoping - but it's not simple).

In Pop-11 you can even dynamically scope lexicals if you want.

Personally I hope that perl6 will take dynamic scoping to new levels rather than taking it away.

Anyway - the point I'm trying to make is that dynamic scope can be a useful and powerful feature. Just because some people misuse it isn't a reason for it to be removed.


In reply to Re: Why does Perl use dynamic scoping? by adrianh
in thread Why does Perl use dynamic scoping? by blokhead

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.