Skip to content

rilinkedlistlib

This library keeps up to five linked lists, numbered 0 to 4, whose items hold copies of variables. Unlike a Dim List array, the items are not of one fixed type: each item stores a copy of whatever variable was put into it, and the list moves on and back through its items. The commands are meant for variables of a NewType. Each list has a current item, which the commands work on. AddrListItem and SizeOfListItem are functions; all other commands can be used as functions too, and most of them return -1 on success and 0 on failure. When there is not enough memory for an item or a copy, the program stops with the error “Out of Memory!”.

The library copies with a command of the RI Amos Func library, which must be present as well. DelListItem frees an item with its copy, SetListItem the copy it replaces, and InitList a list that is already there; the memory still in use is freed with the program’s other memory when it ends.

On a list that was never started with InitList, the commands do nothing and return 0. Only the list numbers 0 to 4 are allowed: with runtime error checking, any other number is the error “List number must be 0 to 4”; without it, such a number overwrites the other lists or memory.

A list of three items, walked from the first one:

NEWTYPE .t
  a.l
End NEWTYPE
DEFTYPE .t v
v\a=1 : InitList 0,v
v\a=2 : AddLastListItem 0 : SetListItem 0,v
v\a=3 : AddLastListItem 0 : SetListItem 0,v
FirstListItem 0
Repeat
  GetListItem 0,v
  NPrint v\a
Until NextListItem(0)=0

The fixed bugs of the library are listed in Fixes in rilinkedlistlib.

Based on the RI LinkList Library guide by Steven Matty.

Library number 12.

Commands

AddFirstListItem

Adds an empty item in front of the first item of a list and makes it the current one. As a function it returns -1, or 0 if the list has no items; it does not start a list.

Statement or function, result .l. Help text: list#
Arguments: .l

AddLastListItem

Adds an empty item behind the last item of a list and makes it the current one. As a function it returns -1.

Statement or function, result .l. Help text: list#
Arguments: .l

AddListItem

Adds an empty item behind the current item of a list and makes it the current one; put a copy into it with SetListItem. As a function it returns -1.

Statement or function, result .l. Help text: list#
Arguments: .l

AddrListItem

The address of the current item of a list, 0 if it has none.

Function, result .l. Help text: list#
Arguments: .l

DelListItem

Deletes the current item of a list; the next item, or at the end of the list the previous one, becomes the current one. As a function it returns -1, or 0 if the list has no current item or this is its only item, which is not deleted.

Statement or function, result .l. Help text: list#
Arguments: .l

The item is freed with its copy.

FirstListItem

Makes the first item of a list the current one; as a function it returns -1, or 0 if the list has no items.

Statement or function, result .l. Help text: list#
Arguments: .l

GetListItem

Copies the contents of the current item of a list into the variable var. As a function it returns -1, or 0 if the item holds no copy.

Statement or function, result .l. Help text: list#,var
Arguments: .l, &any

It copies no more bytes than the stored copy has: the rest of a larger variable stays as it is.

InitList

Starts list list# (0 to 4) with one item that holds a copy of the variable var; this item becomes the current one. As a function it returns -1.

Statement or function, result .l. Help text: list#,var
Arguments: .l, &any

A list that is already there is freed first, with the copies of its items.

LastListItem

Makes the last item of a list the current one; as a function it returns -1, or 0 if the list has no items.

Statement or function, result .l. Help text: list#
Arguments: .l

NextListItem

Makes the next item of a list the current one. As a function it returns -1, or 0 at the end of the list, where the current item stays.

Statement or function, result .l. Help text: list#
Arguments: .l

PrevListItem

Makes the previous item of a list the current one. As a function it returns -1, or 0 at the start of the list, where the current item stays.

Statement or function, result .l. Help text: list#
Arguments: .l

SetListItem

Stores a copy of the variable var in the current item of a list. As a function it returns -1.

Statement or function, result .l. Help text: list#,var
Arguments: .l, &any

A copy the item held before is freed once the new one is made.

SizeOfListItem

The size in bytes that the list commands copy for the variable var.

Function, result .l. Help text: var
Arguments: &any