K2yfi

joined 2 years ago
[–] K2yfi@programming.dev 6 points 2 months ago (2 children)

I've been working on this problem for my own language, and have landed on something more clear than just following a convention. Basically you use [] and () to specify if the left and right bounds are included or not (based off of interval notation: https://en.wikipedia.org/wiki/Interval_(mathematics)#Including_or_excluding_endpoints). e.g. for your case

--slice [1:5)    # include the left index. don't include the right index
--slice [1:5]    # include both left and right index
--slice (1:5]    # don't include the left index. include the right index
--slice (1:5)    # don't include the left or right index

potentially not relevant to your case, but my version supports an end keyword which you can do math on, similar to python's negative indexing

[2:end-3]    # start at index 2 (included) and go through till the third from last index (included)
(end-3:end]  # start at the third from last (excluded) and go to the end (included)

Personally I'm a fan of 0 indexing, but for your context, I think it would depend on how the user sees what they're slicing. E.g. if it was pages with page numbers, the numbers would indicate if it was 0 or 1 index based. If there's nothing to actually show the user, I think picking something reasonable and documenting it well is probably the best bet.

[–] K2yfi@programming.dev 5 points 9 months ago

Sounds like you should take a look at https://www.nand2tetris.org/. Basically it walks through the process of building up a game like Tetris starting from logic gates. It has you write a very simple compiler for a mini language where you've built everything up from the base logic gates level, so it should be a pretty good guide for what you want.

[–] K2yfi@programming.dev 6 points 2 years ago* (last edited 2 years ago)

https://www.hedycode.com/ might be exactly what you are looking for. It's designed to teach python to children by starting with a super simplified version of the language, and then gradually adding in syntax and features until it's full python. Here's a great talk by its creator: https://youtu.be/fmF7HpU_-9k?si=pa7jkOELQ5X7xeuu