Re: [Phix Tutorial] Basic Sequence Actions

new topic     » goto parent     » topic index » view thread      » older message » newer message
euphoric said...

_tom, can you explain the usage of a "gap?"

I've seen gaps like [2..1], but can there be other gaps, like [4..2]? And what does that do?

Gap | Item | Slice ( Caret | Cursor )

In a classic text based word processor a cursor "selects by highlighting a block on top of a character." In graphical word processors a caret "selects by a vertical line marker just before a character."

sequence s = "1234"  -- a string with four digit characters
"1❷34"  -- cursor  "on 2"
"1|234"   -- caret "before 2"

In a sequence|string we can use these ideas. In "1❷34" we say s[2] is the item 2 . In "1❷34" we say s[2..2] is the slice {2} . In "1|234" we say s[2..1] is the gap {} .

We can identify all gaps in a sequence as "|●|●|●|●|" ; there is a gap at the head and tail of a sequence; there is a gap between any two items. All gaps are an empty sequence {} or "" .

There is no item [0] or item [5] in the four item sequence "●●●●" , but there are lots of gaps.

                     Gaps in a Sequence or String ?                   
s = "|◍○○○" s = s[1..0] ""
s = "○|◍○○" s = s[2..1] ""
s = "○○|◍○" s = s[3..2] ""
s = "○○○|◍" s = s[4..3] ""
s = "○○○○|" s = s[5..4] ""

Each gap is an empty sequence.

To assign an atom to an empty gap is futile-- nothing happens.

An assignment will replace an empty gap with a new slice--the sequence grows by the length of the slice.

Reminder: This is a Phix tutorial. In oE you can not assign to a gap because the length of {} is zero and the length of anything interesting is >0 . In oE assignments must have equal lengths.

_tom

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu