masak / alma

ALgoloid with MAcros -- a language with Algol-family syntax where macros take center stage
Artistic License 2.0
138 stars 15 forks source link

Implement Python's slice syntax instead of .slice and .splice #291

Open masak opened 6 years ago

masak commented 6 years ago

This would obviate #238, or at least provide a serious contender/complement.

I thought about being a rebel and making the syntax be array[x..y] instead of Python's array[x:y]. The former seems more sensible to me. (Except, ugh, that it should be array[x..^y] because the slice is half-open.) But... let's not introduce more problems than we need; let's stick with array[x:y] (and array[x:y:z]) for now.

There's the small matter of negative indices, which work in Python and are an integral part of list slices there. I'm willing to have negative indices work in 007 too, I think.

masak commented 6 years ago

Note: tc39 currently has a slice syntax proposal going.

masak commented 5 years ago

Reading the tc39 proposal, I'm struck by a number of things:

masak commented 5 years ago

But... let's not introduce more problems than we need; let's stick with array[x:y] (and array[x:y:z]) for now.

I no longer believe that to be the right trade-off. Instead I think we should do everything with the already proposed range syntax, with syntactic infinities (#517), and possibly also with a syntactic Whatever (no issue for that yet), both as range endpoints and stand-alone. Details to follow.

masak commented 5 years ago

Another nice force multiplier would be being able to do array[from..to] .= reverse(); that is, combining array slicing and the .= operator.

As far as I can see, that follows immediately. What would be most impressive, however, would be if the optimizer carried enough information to know not to create any intermediate arrays while reversing in-place.