Comment

Comment by kerkeslager

I like the deep dive into the source, but big picture, I think if you understand the general order of evaluation which applies to most languages, this isn't all that unintuitive. The arguments going into the outer [ ] get evaluated before the outer [ ], meaning the inner [] gets evaluated first. Once that happens the inner list is created, and there's no code left that even visually could create more inner lists.

The more unintuitive example of this to me is in function defaults, because those feel more like part of the function signature--i.e. I'd expect them to be assigned at function call time. But apparently, function defaults get called once when the function is defined.

    >>> def grow(items=[0]):
    ...    items.append(items[-1] + 1)
    ...    return items
    ... 
    >>> grow()
    [0, 1]
    >>> grow()
    [0, 1, 2]
    >>> grow()
    [0, 1, 2, 3]
parent kerkeslager 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton