Hacker News new | ask | show | jobs
Ask HN: Confused by a friend in discussion of variables (repost)
1 points by IAskForAFriend 3367 days ago
I asked this a little while ago, but I didn't get much of a response. I'll only ask it this once more in case people didn't see it - having lurked here a while I know there's a large dollop of chance in whether a post gets seen.

Anyhoo ...

A friend of mine is not a programmer, but does program. My friend has a degree in mathematics, works in the supply of a specific type of computer hardware, uses Perl to accomplish various scripting tasks, and is very capable in doing so.

While discussing programming languages recently I casually said that we can think of "variables" as boxes to put things in with the name of the variable on the outside, and the thing we put in these boxes are "values". "Values" can be complicated, and may actually be references to other things.

My friend went thoughtful, and then said:

Suppose I have a hash:

    $next{"thingy"}="whatname";
    $next{"whatname"}="wotsit";
    $next{"wotsit"}="doohickey";
Then I would have said (my friend said) that:

    $next{$next{$next{"thingy"}}}
is another name for "doohickey" and hence is a variable.

Is this a common point of view?

I'd appreciate any thoughts or feedback - perhaps my viewpoint is too narrow, or simply wrong.

2 comments

The hash table is not a good example, because a hash is not a variable, it is a function.

F(x) = "doohickey" when x = "wotsit"

I think you guys are confusing variables and data types (or data structures) too, they are different things.

Would you not say that "next" is a variable, and the value, the thing, that "next" contains is a hash? "Next" is, of itself, not a function, surely.
It it isn't "next", it's next{x}. It's a function, not a variable.
It's a little weird, but not without precedent - for instance, take a look at "setf" found in most Lisps.