Changeset 4d3666d for doc/proposals/iterators.md
- Timestamp:
- Aug 25, 2022, 11:51:11 AM (2 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation
- Children:
- d2f09e4
- Parents:
- b59d6d1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/proposals/iterators.md
rb59d6d1 r4d3666d 2 2 ========= 3 3 This is the proposal for adding iterators to Cforall and the standard 4 lib ary. Iterators provide a common interface for sequences of values in4 library. Iterators provide a common interface for sequences of values in 5 5 the language. Many inputs and outputs can be described in terms of sequences, 6 6 creating a common interface that can be used in many places. … … 15 15 The operation is "get the next value in the sequence", but this actually has 16 16 several parts, in that it has to check if there are move values, return the 17 next one if there is , and update any internal information in the iterator.17 next one if there is one, and update any internal information in the iterator. 18 18 For example: `Maybe(Item) next(Iter &);`. 19 19 20 20 Now, iterators can have other operations. Notably, they are often also 21 iterables that return themselves. They can also have a veri aty of iterator21 iterables that return themselves. They can also have a verity of iterator 22 22 transformers built in. 23 23 … … 25 25 26 26 Anything that you can get an iterator from is called an iterable. There 27 is an operation to get an iterator from an itera tor.27 is an operation to get an iterator from an iterable. 28 28 29 29 Range For Loop … … 31 31 One part of the language that could be reworked to make good use of this is 32 32 for loops. In short, remove most of the special rules that can be done inside 33 the identif er and make it a generic range for loop:33 the identifier and make it a generic range for loop: 34 34 35 35 ``` … … 39 39 The common way to implement this is that expression produces an iterable. 40 40 The for loop gets an iterator from the iterable (which is why iterators are 41 often iterables, so they can be passed in with the same i terface) and stores41 often iterables, so they can be passed in with the same interface) and stores 42 42 it. Then, for each value in the iterator, the loop binds the value to the 43 43 identifier and then executes the statement. The loop exits after every value 44 has been used and the iterator is ex austed.44 has been used and the iterator is exhausted. 45 45 46 46 For the chained for loop (`for (i; _: j; _)`) can still have its existing 47 47 behaviour, advancing through each range in parallel and stopping as soon 48 as the first one is ex austed.48 as the first one is exhausted. 49 49 50 50 Ranges … … 54 54 logically instead of by copy. 55 55 56 The purpose of this container is to bridge the new iterator i terfaces with56 The purpose of this container is to bridge the new iterator interfaces with 57 57 the existing range syntax. The range syntax would become an operator that 58 58 returns a range object, which can be used as any other type. … … 91 91 pointers. 92 92 93 Rust also has a imp arative implementation of a functional style of iterators,93 Rust also has a imperative implementation of a functional style of iterators, 94 94 including a great number of standard transformers. Otherwise, it is very 95 95 similar to Python.
Note: See TracChangeset
for help on using the changeset viewer.