I want to evaluate a string that represents a variable name, simple example:
set varName to {1,2,3,4}
is it possible in Applescript to use the string “varName” to get access to the actual variable?
Assuming an evaluate function existed, I want the following to occur
evaluate(“varName”)
→ {1,2,3,4}
count evaluate(“varName”)
→ 4
is there also some way to get the type of the variable based on a string containing the variable name?
type evaluate(“varName”)
→ list of integer (or maybe just ‘list’)
Why? In Smile I can get a list of variable names with:
set varNames to name of every variable of context
The I want to go through it to findout how big and what type each variable is.
You missed the key point, I want to use a string that contains the variable name to access the variable.
Why? In Matlab (the language I use daily) a simple ‘who’ (or ‘whos’) will list all the variables (with type/size etc) currently defined in the workspace. I want to emulate this in Smile. Maybe this functionality already exists in Smile but I can’t find it.
I can get a text list of the variables in Smile’s context (name of every variable of context). I just need to figure out how to use those text names to get information about the variables themselves.
“class of varnames”, was helpful, now I know how to get what I thought was the type.
set varName to {1, 2, 3, 4}
set TheVar to {"empty"}
set myString to "this text contains VarName"
if myString contains "varName" then
set TheVar to varName
end if
return TheVar
But I think you want to coerce a string to a variable name. If it’s possibe to do this in Applescript, it’s not going to be an easy thing to do.
Maybe a different scripting language would be a better tool for the job.
Unfortunately, I know how to do this in other languages (e.g. in Matlab use the eval(‘stringToBeEvaluated’) function) but I want to be able to do it with variables in Smile’s workspace and hence need to use Applescript.
So now that we’ve landed on the correct terminology for my problem, any ideas? Anyone?