Indexing System

Certain procedures, such as list-ref, string-ref and vector-ref, work with an indexed character or item within an object. It is important to know that all indices in Mosquito Lisp start from 0.

So:

The indices for the string "MOSREF" would be

M=0, O=1, S=2, R=3, E=4, and F=5.

If you wanted the "R" from "MOSREF", you would use

(string-ref "MOSREF" 3)

while to retrieve the "M", you would use 0 as the integer in that expression.

Let's look at another procedure:

(list-ref '(a b c) 1) returns b

In all cases, the index reference must be >=0 AND a valid index for the object. So,

(list-ref '(a b c) 7) returns an error.