Jonathan writes:
> Having noticed a complaint by John Gillespie that this newsgroup
> was a bit slow, I feel entitled to respond unnecessarily to a post :-).
Absolutely! It's nice to get some heat and smoke going. What? You
want light as well?! Some people are never satisfied ...
> Actually, if you want a fast prototyping language, I don't understand why
> you should have to declare any local variables at all (this criticism
> applies equally to lisp and other dynamic languages). The compiler could
> easily notice all the free variables in a procedure and declare them
> as lvars _unless_ they were explicitly declared otherwise.
Duh. I think this is just poorly worded. Here's my spin on
this issue and, I suspect, something similar to Jonathan's
view.
There are certain syntactic contexts (input/output locals, loop
variables) which name variables that, almost always, are declared
the same way, as a lexical local. For example, in the code fragments
below, the variable "x" is almost always going to be declared
as an "lvars".
define foo( x ); ...
for x in ....
... fmatches [ ... ?x ... ] ...
If these contexts were to be considered to be implicit declarations of
the usual type, the number of explicit declarations would be significantly
reduced and the code would be less error-prone and easier to understand.
I think that Jonathan is saying that with the appropriate default
declarations and appropriate syntactic constructs, the need for explicit
local declarations disappears - and that is quite right.
The recent change to Pop11, that of making input/output locals be
implicitly declared as "lvars" goes part of the way towards this.
And because I believe that this is a highly desirable change, I
am pleased to see it. Aaron's complaints about the change are, I
think, not so much about the merit of the change but about the
migration policy that was adopted - and I would agree with that.
But the change itself is wonderful. (The business about forbidding
local vars declarations is unfortunate and, from what I can gather,
likely to be put into the right state. This is NOT a reversal to
the original position which was a complete disaster and totally
unsatisfactory to everyone.)
Chris Dollin's Pepper language, a variant of Pop11, goes much further
and, I think, demonstrates just how much room for improvement there
is. Personally, I would like to see at least 4 more ideas
incorporated into Pop11 in the short term. (However, rather than use
a compile-mode to distinguish it, I would like to see a ".pop"
extension and a subsystem. I think that's a much superior route
and likely to cause much less hassle.)
Firstly, I think that for loops should implicitly declare the
loop variables. (And to make this work, we need explicit "free"
declarations as Jonathan suggests.) Secondly, the for-loop
syntax should be rationalised to eliminate the completely pointless
exceptions. Thirdly, all block constructs (especially loops and
if expressions) should introduce lexical blocks. And fourth, and
most important of all, implicitly declared variables should be
made non-assignable. The missing category of contant-lexical
variables is sorely missed in Pop11. (N.B. lconstant is
an entirely different concept, despite the name.)
All these suggestions need justifying and I don't propose to
do that here since the arguments are extensive. However, all these
ideas are present in Pepper and this is a demonstration of how
they all play together marvellously to create a simpler language
that is (in my view) easier, safer and more natural to program
with.
Steve
|