4 ms·
> or wrap the index to a valid one (like Python)? Python doesn't wrap indices to a valid one. However, it does allow for negative indices which are shorthand f
by Shoop 8y ago
> or wrap the index to a valid one (like Python)?
Python doesn't wrap indices to a valid one. However, it does allow for negative indices which are shorthand for the length of the list plus that negative index.
>>> a = [1, 2, 3]
>>> a[3]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> a[-1]
3
>>> a[-3]
1
>>> a[-4]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
- baxter001 8y agoThat jumped out at me too, also an excellent example of where poking at a 'mystery language' rather than reading the documentation can lead to some really weird mental models (I'm reminded of myself trying to force a haskell program together until it ran). On that note, how the hell would you understand currying or do notation by trial and error? I wonder if they implemented one of their languages with true wrapping index behaviour.
- justinpombrio 8y ago> I wonder if they implemented one of their languages with true wrapping index behaviour. No, that was just me writing carelessly. None of the mystery languages use array indexing, and if they did we'd be careful to get it right. I actually know this behavior of Python, but didn't think about it much as I wrote. > On that note, how the hell would you understand currying or do notation by trial and error? It's not easy, but many of our mystery languages are harder than this, and our students figure them out! Sometimes they'll get 2/3 of the way to a solid explanation, and then Shriram gives them a canonical explanation in class the next day, while it's fresh in their minds. And sometimes they come to a perfect understanding by themselves. And currying could make a good mystery language. Thanks for the idea!
- skrishnamurthi 8y agoOur SNAPL paper [http://cs.brown.edu/~sk/Publications/Papers/Published/pkf-teach-pl-exp-adv-think/ http://cs.brown.edu/~sk/Publications/Papers/Published/pkf-te...] has data on how long students spend. It turns out relatively few hours for pretty high levels of attainment (i.e., of finding the languages). But as @justinpombrio says, this is also tied to a particular pedagogy. The day after the homework is due, in class, we: - collectively build up a classifier (programs that tell the languages apart) - present the intended theory (our ground truth of what is going on) and then spend the remaining time (30+ minutes) talking about which languages did those particular things, and — most importantly — why those languages did that, especially for the "weird" behaviors. There were often very good reasons for doing so, when viewed in a historical context. In this regard, I'm very much a historicist in the Kuhnian sense.
- jwilk 8y agoThe author updated the article: > EDIT: Specifically, Python wraps negative indices that are smaller than the length of the array. (But that's not quite correct either. 3 is not smaller than the length of a, but a[-3] worked.)