Values and objects

Chris Angelico rosuav at gmail.com
Fri May 9 22:33:28 EDT 2014


On Sat, May 10, 2014 at 12:19 PM, Rustom Mody <rustompmody at gmail.com> wrote:
> For me, Marko's comment that variables in python are not first-class
> whereas in C they are is for me the most important distinction Ive seen
> (in a long time of seeing these discussions).
>

https://en.wikipedia.org/wiki/First-class_citizen

For variables in C to be considered first-class, they must, by most
definitions, be able to be passed around as parameters and return
values. Some definitions also require that they be able to be
constructed at run-time. How do C variables shape up?

1) Passing them as parameters. You can pass a pointer to a variable,
which is effectively the same as passing a variable to a function. The
callee can mutate your variable through the pointer.
2) Returning them. This is a lot more dodgy, owing to the
dangling-pointer issue, but as long as you accept that the reference
to a variable doesn't ensure its continued life, I suppose this might
be acceptable. Maybe. But it's pushing it.
3) Constructing at run-time. Really REALLY pushing it. You can malloc
and call that a "variable", but it's not a variable any more, it's
just a patch of memory. In fact, all this proves is that variables
represent patches of memory, and patches of memory are first-class.

Not liking the results here. You might just as well define that all
Python variables must be backed by a dictionary (it's just as true as
"all C variables must be backed by memory") and then define the
first-class-variable as a combination of a dict and a key.

ChrisA



More information about the Python-list mailing list