Iterators: Difference between revisions

Content added Content deleted
m (J: improve grammar slightly)
m (J: show more detail about trailing empty example)
Line 203: Line 203:
col=: '' ]F..(,<) ;:'red orange yellow green blue purple'
col=: '' ]F..(,<) ;:'red orange yellow green blue purple'
</lang>
</lang>

<lang J> col
┌──────┬───────────────────────────────────────┐
│purple│┌────┬────────────────────────────────┐│
│ ││blue│┌─────┬────────────────────────┐││
│ ││ ││green│┌──────┬───────────────┐│││
│ ││ ││ ││yellow│┌──────┬──────┐││││
│ ││ ││ ││ ││orange│┌───┬┐│││││
│ ││ ││ ││ ││ ││red│││││││
│ ││ ││ ││ ││ │└───┴┘│││││
│ ││ ││ ││ │└──────┴──────┘││││
│ ││ ││ │└──────┴───────────────┘│││
│ ││ │└─────┴────────────────────────┘││
│ │└────┴────────────────────────────────┘│
└──────┴───────────────────────────────────────┘</lang>


This creates an issue that a single element nested list looks very much like a flat array. To prevent that from being a problem, we include an empty element at the end of our flat array:
This creates an issue that a single element nested list looks very much like a flat array. To prevent that from being a problem, we include an empty element at the end of our flat array:
Line 209: Line 224:
dow=: a:,~;:'monday tuesday wednesday thursday friday saturday sunday'
dow=: a:,~;:'monday tuesday wednesday thursday friday saturday sunday'
</lang>
</lang>

<lang J> dow
┌──────┬───────┬─────────┬────────┬──────┬────────┬──────┬┐
│monday│tuesday│wednesday│thursday│friday│saturday│sunday││
└──────┴───────┴─────────┴────────┴──────┴────────┴──────┴┘</lang>


Now everything is the same as before, except that we need to explicitly ignore the empty trailing element:
Now everything is the same as before, except that we need to explicitly ignore the empty trailing element: