Local ät
getType(#än)→ät
Return ät
EndFunc
A similar method embeds underscore characters "_" in the variable names. For example, you could
use n_ for n, t_ for t, and so on. Again, you assume that the user does not use these names.
As another work-around, expr() can be used to build expressions to evaluate, for example
v→#n becomes expr("v→"&n)
#n→v becomes expr(n&"→v")
getType(#n)→n becomes expr("getType"&n&")→t")
With this method, this version of testtype() returns the correct results:
testtype(n)
Func
Local t
expr("getType("&n&")→t")
Return t
EndFunc
(Credit to Martin Daveluy)
[7.42] Find variable names used in expressions
It is often useful to extract the variable names from an expression or equation. For example, the
variables can be deleted, archived, initialized and so on. Timité Hassan and Bhuvanesh Bhatt, have
both written functions to extract variable names. This tip discusses both methods.
Timité's TI Basic version
Timité's function getvars() returns the variable names of an expression passed as a string. I have
slightly modified his function, and changed the name to exprvars() to avoid confusion. My modifications
change the external subroutines to local routines, and convert some nested-If expressions to when()
functions. The basic algorithm and code remains unchanged.
exprvars(g_str)
Func
©("expr") return list ofvariables in "expr"
©Timité Hassan, modified by dab
Local k,i,cc,g_vr,g_d,g_dim,g_ll,ss,varin,vardeb
Define varin(c)=Func
Local cc
ord(c)→cc
when(c≥"a" and c≤"z",true,when(c≥"0" and c≤"9",true,when(cc≥128 and cc≤148 and
cc≠140,true,when(c="_",true,false))))
EndFunc
Define vardeb(c)=Func
Local cc
ord(c)→cc
when(c≥"a" and c≤"z",true,when(cc≥128 and cc≤148 and cc≠140,true,false))
EndFunc
dim(g_str)→g_dim
7 - 42