Reputation: 1
I'm writing a program on my TI-84 Plus CE-T and would like to check if Ans is currently a list or not. I want Ans to work as a type of optional input so that if Ans is a list i will use that and if not i will default it to something else.
Calling dim(Ans) throws an Error only if Ans isn't a list/matrix but i dont want the program to crash. If you could somehow eliminate the possibility that Ans is a number, you could then check if dim(dim(Ans))=1 to narrow it down to lists.
Upvotes: 0
Views: 36
Reputation: 21
You can use the toString() command to turn ANS into a string (toString(ANS)
), and from there you can analyze the brackets to find the type. ToString(ANS)
may crash if ANS is a string already.
If you use an older calculator that doesn't have the toString command then it will get tricky, you could try to run:
ANS(1) = 2*ANS(2)
If this comparison is true, ANS likely would have been a number. However, ANS would have been overwritten with the comparison result, and the program would crash if the list had a length of 1 or if ANS were a string or a matrix. If the list started with two identical values the comparison would have a false positive.
Upvotes: 0