TI-BASIC doesn't have dictionaries
There are no lists/arrays of strings either. However, it's possible to implement one using strings. We'll use Str1
for the large string that contains all keys and values. Use a delimiter (say ?
) to start keys, and another one (say !
) to start values. You can represent the list thusly:
//starting delimiter
"?->Str1
//add value "SEARCH1" => "ANSWER1" at end
Str1+"SEARCH1!ANSWER1?→Str1
//add second value
Str1+"SEARCH2!ANSWER2?→Str1
Str1
is now ?SEARCH1!ANSWER1?SEARCH2!ANSWER2?
.
Then to access the value corresponding to the key Str0
=SEARCH1
:
"SEARCH1→Str0
inString(Str1,"?"+Str0+"!")+length(Str0)+2 //now Ans = index of key
sub(Str1,Ans,inString(Str1,"?",Ans)-Ans //get the key
The performance of this can be slightly improved through tricks. However, as Str1 gets larger, this routine gets slower—it does a linear search, O(n) through the whole string to find the key. If you want O(1)
access, implementation will be significantly more complicated, as it requires hashing.