guppylang icon indicating copy to clipboard operation
guppylang copied to clipboard

Prelude: `next` and `iter`

Open acl-cqc opened this issue 1 year ago • 1 comments

i.e. that allow you to manually iterate through a list, rather than using for.

While iter probably just needs a custom checker/compiler that calls __iter__(), next needs to be a bit more complicated to handle the failure case - what does next do to handle __hasnext__ returning false? (I.e. we need either an Optional return type, which would be pythonic, or else make next panic and then provide some way for client to call __hasnext__ first...)

acl-cqc avatar Sep 16 '24 09:09 acl-cqc

Longer term we should just get rid of __hasnext__ and make __next__ return an option type. However, this requires enums or some other ways to encode sums in the language.

See #96

mark-koch avatar Oct 01 '24 15:10 mark-koch