Sequence Items - Old and New

Mutable Sequence

A sequence is "a list of items"; each item is a Euphoria object. Sequences are delimited using parentheses, {} . A character string which is delimited with double-quotation marks, " , is also a sequence. Each item in a sequence is indexed using subscript [ ] notation; we say items are indexed with integers.

Euphoria sequences are flexible; all aspects of a sequence may be changed. A sequence is mutable because any item may be changed or removed, and items may be added to a sequence. A great feature of Euphoria is that all sequences, numerical or character, behave in the same way.

Old Items


You can change the value of any item in a sequence using the assignment statement. Use the subscript notation, [ ] , to select the item and the assignment operator, = , to change the value.

In a character string each item must be a character. If you assign one character (such as 'X') to an item in a string then it is still a string. If you assign a string (such as "XX") to an item in a string it is no longer a character string but a nested sequence. Caution: the puts procedure can only output character strings; it is an error to output a nested string using puts.

A slice is several contiguous items. You can assign values to a slice:

It is important that there is a one to one correspondence between every item when slices are assigned.


You can remove an item from a sequence using the remove function when you specify the sequence and the index value.

You can also remove a slice from a sequence:

Removing an item using only sequence operations:

New Items

There are two fundamental ways you can add an item to a sequence: insert and splice.

If an added-object is an atom then it does not matter how you do it; an insert and a splice will produce identical results:

If the added-object is a sequence (any shape or empty) then the result of an insert differs from that of a splice.

insert prepend append

When you insert an item it remains intact; the length of the new sequence increases by just one item. It is like joining rope with a knot; insert a sequence and you leave a lump:

An insert adds an object as one item anywhere in a sequence.

A prepend adds an object before the first item in a sequence. An append adds an object after the last item in a sequence. (Prepend and append are special cases of insert.)

Character strings are inserted like all other sequences. Character strings prepend and append like all other sequences:

splice concatenate

When you splice an item it blends in; the length of the new sequence increases by the length of the item. The result is like a smooth rope splice:

A splice adds an object as separate items anywhere in a sequence:

The concatenation operator, & , is used to splice an object before the first item or after the last item of as sequence. (Concatenation is a special case of splicing.)

Character strings are spliced like all other sequences. Character strings are concatenated like all other sequences:


Quick Links

User menu

Not signed in.

Misc Menu