http://www.perlmonks.org?node_id=451154


in reply to Re^2: Some Insights from a Traveler Between Languages
in thread Some Insights from a Traveler Between Languages

In a language like Perl, it's not clear to me that the distinction between "array" and "array ref" is a useful one.

This is the core of the issue right here.

For example, the fact that you can return a reference to a local (er, my) variable inside a function is indicative to me that Perl doesn't seem to have the concept of auto variables.

It's indicative of the fact that Perl does have the concepts of lexical scope, anonymous objects, and, in particular, lexical closures. my variables are not local in the same sense that e.g. Inform means by "local variable". (They are closer to it than Perl's local variables, which are dynamically scoped, but that is neither here nor there ATM.) In particular, it is an easy mistake to make (and one that I made once upon a time, when I was very new to Perl) to misunderstand Perl's lexical variables, thinking either that they are persistently scoped to a given function or block ("static" in C parlance) or to go wrong in the other direction, failing to account for references and assuming immediate destruction at the end of the block. But neither of these semantics would be nearly as useful as the one Perl has (although the former could be a useful *additional* option, and I think we may be getting that in Perl6; I cannot think of any use for the latter).

Presumably the things getting placed onto the function call stack are not actual variables, but reference counting pointers

The function call stack is not part of Perl (as a language). It is part of perl (the interpreter), an implementation detail that could change between minor versions without having any significant impact on existing Perl code.

Reference counting is another matter; yes, Perl5 does reference counting. (Perl6 will have real GC, so I am told, likely of the mark-and-sweep variety.) However, that rears its head in other situations, such as when you have cyclic data structures. In the case you're talking about (assuming I correctly understand what it is you are talking about), the same thing would happen if Perl5 had mark-and-sweep garbage collection today. You can do the same thing in Scheme, for instance. If you can't do it in Python, that is because Python deliberately steers you to thinking according to the OO paradigm; Perl embraces various paradigms: OO, FP, contextual, ... this is the essential paradigmatic flexibility that makes Perl the language that it is. TMTOWTDI, and for various situations or problems one of them may be more helpful than another.

Do we really need to care about the distinction between variables and references?

Yes, absolutely -- or, at least, we have to have a distinction between references and the things that they reference. The question of what constitutes a "variable" is another whole thread, and one that I suspect would be a tangent here, not the real issue.


"In adjectives, with the addition of inflectional endings, a changeable long vowel (Qamets or Tsere) in an open, propretonic syllable will reduce to Vocal Shewa. This type of change occurs when the open, pretonic syllable of the masculine singular adjective becomes propretonic with the addition of inflectional endings."  — Pratico & Van Pelt, BBHG, p68