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 rangeOn 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.
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.
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!
> 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.)
I couldn't agree more strongly. Syntax is bikeshedding and semantics is language design. My favorite example is the wholesale abandonment of M-Expressions by the early lispers. I don't know of any other (kind of) mainstream language community that has so wholeheartedly put semantics first. Maybe the ML family? Any other examples?
Yeah Dijkstra, Hoare, Knuth, Lamport, and friends are basically my heroes. Algol 60 is fine work. It has a very readable syntax. It's easy to see why it's even now used for scholarly publication. Hadn't heard of Milner though, any suggested reading?
https://amturing.acm.org/award_winners/milner_1569367.cfm
https://en.wikipedia.org/wiki/Robin_Milner
ML did not spring fully-formed from the heads of the creators of OCaml…
Note: CTF is a very different kind of thing than what we are doing here. In CTF, usually, there is some clear sense of a goal and you are (as you note) given a measure of how close you are, or at least told when you've Ced The F. In mystery languages, there is no well-defined end and there is no measure. Also, your job is not to break one thing, but rather to break the difference between multiple things. That kind of «differential reasoning» is its own separate sort of activity.
As an aside, real life often does not give you a measure or an indication of when you're done. Sometimes, maybe, you've set yourself your own goal (e.g., to steal a particular resource), and then you may be able to tell. But otherwise, especially when it comes to learning new things (like programming languages), I'd say this is a more authentic learning activity. Indeed, it grew out in part from my trying to reflect on how I myself approached a new language. So, at least, it's more authentic to me. (-:
This seems like splitting hairs. You could wrap this differential reasoning assignment in a function that returns true iff the outputs are different and achieve the same CTF-style behavior. The only difference here is that students get one assignment at a time instead.
I would love to record and publish the videos. However, the moment I do, I have essentially published the solutions to the homeworks. It's very hard to reuse them again. But mystery languages are really difficult to generate (especially with the additional constraints that we explain in the SNAPL paper), as there are only so many meaningful variations to go around. So, no.
You are very right that PAPL doesn't incorporate them at all. Part of the issue is the above. But part of it is also, now that I am getting really comfortable with this being a notable portion of my PL course, what becomes the nature of a "textbook" for such a course? I've struggled with this question before: I taught a (I think) really good software engineering course, but couldn't really can it into a book. I feel the same way about this now. But it means PAPL may end up being less a (half) PL textbook and more some other thing that is still being formed in my mind…