I'm wrong or Will we fix the ducks limp?
Marko Rauhamaa
marko at pacujo.net
Mon Jun 6 17:47:19 EDT 2016
Random832 <random832 at fastmail.com>:
> The box metaphor as I understand it involves a lot of boxes, which may
> contain arrows (call them pointers, references, or whatever) emerging
> from them pointing to other boxes, which are all free-floating with no
> implication that any of them are fixed locations or are not
> dynamically allocated.
When I first studied Java, I quickly made a realization that
Java's . (dot)
is
C's -> (arrow)
That's all there was to it. You could replace Java with Python.
Where a C programmer would write:
x->y->z
a Python programmer would express the same as:
x.y.z
> The most classic use of it, after all, is for Lisp, in which two boxes
> glued together represent a cons cell, something absolutely nobody
> would accuse of having a fixed location. Google "lisp box diagram" for
> any number of examples.
There doesn't seem to be any way to introduce Lisp/Java/Python's data
model except through lower-level programming concepts.
> On Sun, Jun 5, 2016, at 04:01, Marko Rauhamaa wrote:
> M> You could also think of variables as pegs, references as leashes,
> M> and objects as cute puppies. One puppy could be held with multiple
> M> leashes hung on separate pegs. Some puppies hold leashes in their
> M> mouths. Every leash is tied to a puppy or a special wooden post
> M> called None.
>
> (I disagreed with him on "None" needing to be a special wooden post for
> the analogy to work)
That's not an analogy -- that's an abstract data model!
Note: no boxes! However, there are strings attached. Now you can truly
*bind* objects to variables.
Seriously, though, it is notable that the high-level programming
languages pretty unanimously refuse to make variables first-class
objects. I wonder why.
Python (et al) can closely emulate pointers to variables with arrays:
>>> def double_it(it):
... it[0] *= 2
...
>>> it = [7]
>>> double_it(it)
>>> it[0]
14
>>> double_it(it)
>>> it[0]
28
although that would be bad style in Python, which can return tuples.
Marko
More information about the Python-list
mailing list