Re: Variables and closures (Was: Objects and Relations)

From: Bob Badour <>
Date: Fri, 09 Feb 2007 23:38:18 GMT
Message-ID: <KB7zh.4570$>

Marshall wrote:
> On Feb 8, 11:05 pm, "David BL" <> wrote:

>>In common usage 'variable' is only used with reference to the
>>identifiers in the source that at run time are associated with an
>>instance of some type (whether a global variable, frame variable or
>>member variable).

> That's certainly the common usage in the C++ and Java worlds,

I don't know as much about the Java world, but the C++ world knows a dynamic variable is still a variable.

> which is perhaps unsurprising since they have specific terminology
> for their first-class variable construct ("object") and there is no
> relationship in the language semantics between their first class
> variables and their second class variables (which they call
> "variables.")

I am not sure I understand what you are saying above, which is the inevitable outcome when one uses "object" without qualification. An instance of an object class is a variable. Does that not relate what you call the "first-class construct" with what you call the "second-class" ?

> This article descibes the notion of a "first class" construct
> as the term is used in programming language theory:
> (The word "object" in the title above is the generic
> sense of the word, not the OOPL sense.)

I respectfully suggest that variables are first-class in C++ (if not Java.) They certainly are in C--at least by the description given in the wikipedia article you cite.

(Aside: Clicking through to the part wikipedia claims is about databases shows plenty of horseshit ends up in wikipedia. I don't see how an employment contract is any less "first class" than a company or an employee.)

> In SML, the notion of a name and the notion of a
> variable are completely decoupled. Names
> are always bound to constants, however that
> constant might be the identity of a variable.
> Relational language discussions generally omit the
> notion of first class variables, because they aren't
> a great fit with relational semantics.

I disagree. TTM is quite explicit that the only first class variables are relvars, is it not?

  For that reason
> I've mostly tried to avoid the notion of first class
> variables (as well as objects) in my own designs,
> however I've found it impossible to fully discard the
> notion of first class variables, because they crop up
> almost inevitably once we put together two ideas
> each of which are "must-haves" in my humble opinion:
> lexical scope and first-class functions.
> Consider:
> function make_sequence(initial_value:int):int {
> var x:int = initial_value;
> function sequencer():int {
> return x++;
> }
> return sequencer;
> }
> The nested function sequencer() closes over the variable
> x declared in the outher scope, a natural consequence of
> lexical scope. The function make_sequence returns a
> sequencer which is bound to a specific instance of x.
> Once we put these language features together, we are
> faced with a nasty choice: we have to either put some
> annoyingly artifical limits on its use, or else we have to
> live with the fact that we've just introduced first-class
> variables to our language. Most impure functional
> languages choose the later. I believe that's probably
> the right choice, but I'm still somewhat uneasy about it.

Interesting. One of these days I really have to start looking into some of this stuff more closely. Received on Sat Feb 10 2007 - 00:38:18 CET

Original text of this message