List manipulation

Built-in commands

Editing members of a list

To directly change the 5th member of List 1 to 77:

  77->List 1[5]


Other manipulations

A major weakness of the cfx-9850 and cfx-9950 is that there are no commands for:

Fortunately, there are ways to get around all of these problems, to greatly increase the power of lists as programming tools.

Appending an item to a list

To append 77 to List 1 (matrix method):

  Trn Augment(List->Mat(List 1),[[77->Mat A
  Mat->List(Mat A,1

This has the disadvantage that it requires a spare matrix, taking up more memory than necessary. Because of this, you may prefer instead to use the following method:

To append 77 to List 1 (sequence method):

  1+Dim List 1
  Seq(77Int X%Ans + (X<>Ans)List 1[X - (X=Ans, X, 1, Ans, 1->List 1

This has a speed disadvantage when compared to the matrix method however.

Concatenating two lists

Concatenating two lists is a more complicated version of the append function. Similarly, there are two methods, a matrix method and a sequence method.

To concatenate List 1 and List 2 and store the result in List 3 (matrix method):

  Trn Augment(Trn List->Mat(List 1),Trn List->Mat(List 2)->Mat A
  Mat->List(Mat A,1->List 3

To concatenate List 1 and List 2 and store the result in List 3 (sequence method):

  Dim List 1
  Seq(List 2[X - Ans + (X<=Ans)(1 - X + Ans](X>Ans) + (X<=Ans)List 1
   [X - (X>Ans)(X - 1, X, 1, Ans + Dim List 2, 1->List 3

Inserting an item into a list

To insert 77 into the 5th place in List 1:

  Seq(77(X=5)+(X<>5)List 1[X - (X > 5, X, 1, Dim List 1 + 1, 1->List 1

Removing an item from a list

To delete the 5th item in List 1:

  Seq(List 1[X+(X>=5, X, 1, Dim List 1 - 1, 1->List 1

Note that you can't delete the first item in a list if it is the only item in the list. I must admit that at the moment I can't remember/think how to do that, as I think ClrList clears all lists and { } -> List 1 gives a syntax error. It could be the one thing you can't do with lists... If it is, you might have to keep a dummy value in the first item.

To delete the last item in a list:

  Seq(List 1[X, X, 1, Dim List 1 - 1, 1->List 1

This page was created by Tom Lynn. Comments etc. to: tom-calcs@mythic-beasts.com.

W3C Wilbur Checked!