dictu-lang / Dictu

Dictu is a high-level dynamically typed, multi-paradigm, interpreted programming language.
https://dictu-lang.com
MIT License
268 stars 53 forks source link

[FEATURE] Iterators #486

Closed gvwilson closed 1 month ago

gvwilson commented 2 years ago

Is there an existing issue for this?

Is your feature request related to a problem?

C-style for loops are more complex for novice programmers to work with than iterator-based loops (it's one of the reasons the latter were added to Python).

Describe the solution you'd like

Wren-style iterators's would be relatively straightforward to add to Dictu; I'd be happy to help with implementation and testing.

Describe alternatives you've considered

No response

Additional context

I'm looking for a teaching language the size of Python as it was in the early 2000s or Pascal as it was in the early 1980s; Dictu seems promising. I'd be happy to chat - https://third-bit.com/ for contact details.

Jason2605 commented 2 years ago

Iterator based loops I think would be a nice addition. Things like .forEach are in the language which I find can be slightly easier to reason than standard C-style loops but they're a bit bare at the moment (and need to be implemented manually for each data type).

If we can make it more generic (kinda like Wren in that it has .iterate / .iterateValue methods (if memory serves)) that would be much better, and allow users to define custom iterators.

gvwilson commented 2 years ago

I think a Wren/Python-style iteration protocol would be straightforward, and would move a few things out of the compiler/VM into user space. What I don't understand is how that would interact with fibers (assuming they're added): a readline iterator would probably want to be written as a wrapper around call/yield, which would require some careful thought, and given how I much I had for dinner last night, careful thought isn't on today's menu :-)

Jason2605 commented 2 years ago

given how I much I had for dinner last night, careful thought isn't on today's menu :-)

Haha, hope you had a good Christmas if you celebrate it!

Yeah I think there's probably a few places which may need some thought with regards to fibers, but I still think given all the types of concurrency models there are this is probably the best choice for Dictu.

I think even a naive implementation for IO where it blocks as it reads and returns an iterator object is perfectly fine, especially for now (unless you meant something different and I misunderstood?).