Iterators: Difference between revisions

m
J: show more detail about trailing empty example
m (J: improve grammar slightly)
m (J: show more detail about trailing empty example)
Line 203:
col=: '' ]F..(,<) ;:'red orange yellow green blue purple'
</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:
Line 209 ⟶ 224:
dow=: a:,~;:'monday tuesday wednesday thursday friday saturday sunday'
</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:
6,951

edits