Values and objects
Rustom Mody
rustompmody at gmail.com
Fri May 9 22:19:54 EDT 2014
On Saturday, May 10, 2014 6:31:49 AM UTC+5:30, Steven D'Aprano wrote:
> On Sat, 10 May 2014 01:34:58 +0300, Marko Rauhamaa wrote:
>
> > and you can't pass references to them.
>
>
> That at least you have got right.
>
And that's Marko's main point
>
>
> > Right, Python's variables aren't like variables in C. Rather, Python's
> > variables are like CPU registers. They cannot hold typed or structured
> > objects
>
>
> Surely you cannot mean that? It is *trivially simple* to disprove that
> statement:
>
>
> py> x = [1, 2, 3] # A structured object
> py> type(x) # that has a type
> <class 'list'>
You missed the 'hold'
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).
In C a pointer is a 'pre-variable' in this sense:
int i, *p;
p = &i
after this
i and *p are completely interchangeable
However p can also refer to -- (contain?hold?) depends on which side of this debate you are -- an element of an array or struct
p = &some_array[some_index]
p = &some_struct.some_field
And all the way to anonymity with
p = malloc(sizeof(*p))
This is what makes p a kind of meta-variable:
- it can 'contain' other variables
- it can contain variale-ish things like array elements
- it can contain new variables on the fly via malloc
These possibilities dont exist in python
More information about the Python-list
mailing list