Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

WHERES YOUR SICP NOW

Name: Anonymous 2008-01-06 12:16

Books better than SICP and people better than sussman

TAOCP. better known as The Art Of Computer Programming.
Donald Ervine Knuth.

I just got this monograph for christmas, discuss

Name: Anonymous 2008-01-06 12:17

Sams Teach yourself PHP in 24 hours

Name: Anonymous 2008-01-06 12:25

Pythonista - Abelsonius

Name: Anonymous 2008-01-06 12:31

Extreme Java Programming

Name: Anonymous 2008-01-06 12:32

>>4
Fuck, there's a ctually a similar book.

Name: Anonymous 2008-01-06 12:37

    > one thing I like very much about Python is that statements
    > work like you would expect them to work.

    Well, Python works very much as I expect it, but it's not clear if
    this says more about me or Python <wink>.

    At the end of your email, you say:

    > Who is wrong here: my intuition or Python (2.2)? If it's
    > my intuition, how can I train my thinking about Python's
    > execution model, so that my intuition get's better ;-)

    It's you :) As I can't read my email at the moment[1], I have no
    better way of wasting my time to hand than drawing you some ascii art.

    First, some terminology.  Actually, the very first thing is some
    anti-terminology; I find the word "variable" to be particularly
    uphelpful in a Python context.  I prefer "names", "bindings" and
    "objects".

    Names look like this:

        ,-----.
        | foo |
        `-----'

    Names live in namespaces, but that's not really important for the
    matter at hand as the only namespace in play is the one associated
    with the read-eval-print loop of the interpreter.  In fact names are
    only minor players in the current drama; bindings and objects are the
    real stars.

    Bindings look like this:

        ------------>

    Bindings' left ends can be attached to names, or other "places" such
    as attributes of objects and entries in lists or dictionaries.  Their
    right hand ends are always attached to objects[2].

    Objects look like this:

        +-------+
        | "bar" |
        +-------+

    This is meant to be the string "bar".  Other types of object will be
    drawn differently, but I hope you'll work out what I'm up to.

    > Take for example the use of dict.values() for dictionaries: If you
    > store the result of dict.values(), and change the dictionary after-
    > wards, the previously stored result remains untouched.
    >
    > >>> dict = {'a':1,'b':2}

    After this statement, it would seem appropriate to draw this picture:

        ,------.       +-------+
        | dict |------>|+-----+|     +---+
        `------'       || "a" |+---->| 1 |
                       |+-----+|     +---+
                       |+-----+|     +---+
                       || "b" |+---->| 2 |
                       |+-----+|     +---+
                       +-------+

    > >>> list = dict.values()

    Now this:

        ,------.       +-------+
        | dict |------>|+-----+|             +---+
        `------'       || "a" |+------------>| 1 |
                       |+-----+|             +---+
                       |+-----+|              /\
                       || "b" |+-----.    ,---'
                       |+-----+|     |    |
                       +-------+     `----+----.
                                          |    |
        ,------.       +-----+            |    \/
        | list |------>| [0]-+------------'   +---+
        `------'       | [1]-+--------------->| 2 |
                       +-----+                +---+

    > >>> list
    > [1, 2]

    Which is of course, no surprise.

    > >>> dict['a']=3

    Now this:


        ,------.       +-------+
        | dict |------>|+-----+|             +---+
        `------'       || "a" |+-.           | 1 |
                       |+-----+| |           +---+
                       |+-----+| |            /\
                       || "b" |+-+---.    ,---'
                       |+-----+| |   |    |
                       +-------+ |   `----+----.
                                 |        |    |
        ,------.       +-----+   |        |    \/
        | list |------>| [0]-+---+--------'   +---+
        `------'       | [1]-+---+----------->| 2 |
                       +-----+   |            +---+
                                 |            +---+
                                 `----------->| 3 |
                                              +---+


    > >>> list
    > [1, 2]
    > >>> dict
    > {'a': 3, 'b': 2}

    These should also come as no surprise; just chase the arrows
    (bindings) above.

    > However, if a dictionary has lists as value entries, I get
    > a counterintuitive behavior (which, just recently, broke my
    > code): If you change the dict, the list you previously
    > created via dict.values() gets automagically updated. A nice
    > feature, but nothing I would have expected!

    That's because you're not thinking in terms of Names, Objects and
    Bindings.

    > >>> dict = {'a':[1],'b':[2]}

        ,------.       +-------+
        | dict |------>|+-----+|     +-----+   +---+
        `------'       || "a" |+---->| [0]-+-->| 1 |
                       |+-----+|     +-----+   +---+
                       |+-----+|     +-----+   +---+
                       || "b" |+---->| [0]-+-->| 2 |
                       |+-----+|     +-----+   +---+
                       +-------+

    > >>> list = dict.values()

        ,------.       +-------+
        | dict |------>|+-----+|             +-----+   +---+
        `------'       || "a" |+------------>| [0]-+-->| 1 |
                       |+-----+|             +-----+   +---+
                       |+-----+|               /\
                       || "b" |+-----.    ,----'
                       |+-----+|     |    |
                       +-------+     `----+-----.
                                          |     |
        ,------.       +-----+            |     \/
        | list |------>| [0]-+------------'   +-----+   +---+
        `------'       | [1]-+--------------->| [0]-+-->| 2 |
                       +-----+                +-----+   +---+

    > >>> list
    > [[1], [2]]

    Again, no surprises here.

    > >>> dict['a'].append(3)

                                                        +---+
        ,------.       +-------+                     ,->| 1 |
        | dict |------>|+-----+|             +-----+ |  +---+
        `------'       || "a" |+------------>| [0]-+-'
                       |+-----+|             | [1]-+-.
                       |+-----+|             +-----+ |  +---+
                       || "b" |+-----.         /\    `->| 3 |
                       |+-----+|     |    ,----'        +---+
                       +-------+     |    |
                                     `----+-----.
        ,------.       +-----+            |     \/
        | list |------>| [0]-+------------'   +-----+   +---+
        `------'       | [1]-+--------------->| [0]-+-->| 2 |
                       +-----+                +-----+   +---+

    > >>> dict
    > {'a': [1, 3], 'b': [2]}
    > >>> list
    > [[1, 3], [2]]

    And now these should not be surprising either.

    > Looks like that in the first case a copy is returned while
    > in the latter case list references are returned. Ok, but
    > according to Python's philosophy I shouldn't mind if I work
    > with lists in the dictionary or anything else. If the
    > behavior depends on the knowledge of the type of values I
    > put into a dictionary, I find that somehow counterintuitive.

    If you haven't realised where you're misconceptions come from from the
    above pictures, I'm not sure more prose would help.

    Cheers,
    M.
    [1] Does anyone know where the starship's gone?
    [2] Anyone mentioning UnboundLocalError at this point will be shot.

Name: Anonymous 2008-01-06 12:43

>>6
Valid SNUSP code

Name: Anonymous 2008-01-06 13:32

>>7
Valid ``sage this shit'' trigger.

Name: Anonymous 2008-01-07 1:09

>>8
This may surprise you, but ``faggot quotes'' are for homosexuals and the elderly.

Name: Anonymous 2009-03-18 3:07

The word pirahna, is all I can think of that rhymes with marijuana

Marijuana MUST be legalized.

Name: Anonymous 2012-03-23 22:25

hgthr

Name: Anonymous 2012-03-23 22:33

>>12
Nice necrobump, ``faggot''.

Don't change these.
Name: Email:
Entire Thread Thread List