News for hackers. Stuff that matters.

Ask HN: Confused by a friend in discussion of variables (repost)

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.

( 4 comments | on HN )
Re:Ask HN: Confused by a friend in discussion of variables (... by cnocito on Thursday March 30, 2017 @07:08AM (#13994380)
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.

Re:Ask HN: Confused by a friend in discussion of variables (... by IAskForAFriend on Thursday March 30, 2017 @08:17AM (#13994704)
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.
Re:Ask HN: Confused by a friend in discussion of variables (... by cnocito on Friday April 07, 2017 @05:24PM (#14063616)
It it isn't "next", it's next{x}. It's a function, not a variable.
Re:Ask HN: Confused by a friend in discussion of variables (... by al2o3cr on Thursday March 30, 2017 @07:11AM (#13994391)
It's a little weird, but not without precedent - for instance, take a look at "setf" found in most Lisps.