November 6, 201510 yr I need to determine whether a variable exists as distinct from whether it is empty. From what i can tell, if i access a non-existent variable, it returns empty. If $$foo doesn't exist, IsEmpty($$foo) returns true. But If $$foo exists and is empty, then IsEmpty($$foo) also returns true. How can I distinguish an existing but empty $$foo from a non-existant $$foo? Thanks,
November 6, 201510 yr Quote "An empty variable does not exist." Sort of. Declare $$foo, with a value. Use variable watcher (or script) to set $$foo to empty $$foo is still visible in the variable watcher. You can even close the variable watcher and open it again, and still see $$foo and its (now empty) value. But I agree 100% with your point. Treat it as not-existing if empty.
November 6, 201510 yr 1 hour ago, BruceR said: Use variable watcher (or script) to set $$foo to empty $$foo is still visible in the variable watcher. That's not what I observe. I have Script A to set a $$variable to a value, and Script B to set it to empty. Watching the Current tab of the Data Viewer, the $$variable comes up when Script A runs and is taken off the board when Script B runs.
November 6, 201510 yr I would guess there is in implicit "unset" type function that destroys the variable when it gets cleared via a script, but that behavior is not included when manually setting variables using the data viewer. The expected behavior is that setting a variable to "" will destroy it.
November 6, 201510 yr It's also kind of interesting to create a couple of caclulations in the data viewer Watch panel: Let( $$TESTMODE = "" ; "" ) Let( $$TESTMODE = 0 ; "" ) Whether or not the variable appears in the Current panel will depend on the order of the calcs in the Watch panel. Be that as it may, I was able to replicate Bruce's result by manually clearing the variable in the data viewer.
November 6, 201510 yr 11 minutes ago, Mike Duncan said: that behavior is not included when manually setting variables using the data viewer 10 minutes ago, Fitch said: I was able to replicate Bruce's result by manually clearing the variable in the data viewer This could be a feature of the data viewer. If you manually set the variable to empty, you may also wish to set it to something else later - so the data viewer keeps a spot for it. I don't think it has implications beyond that. It's sort of like "if a tree falls in a forest, and only the data viewer is around to hear it". Edited November 6, 201510 yr by comment
November 7, 201510 yr Data Viewer can throw off perceptions in this way (and a few others). Just running a script, the empty global variable disappears but if you've copied it to watch tab, it will stick around (only in the watch tab) even after script end. I like that analogy, Michael. :-) And I mean setting it via script to empty - it still sticks around. It doesn't have to be manually cleared.
November 7, 201510 yr A little more detail. If I set up this expression in data viewer, evaluate it, then cancel, (so my expression is not stored in WATCH) Let( [ N = 1 ; $$foo1 = 1 ; $$foo2 = 2 ; $$foo3 = 3 /* ; $$foo1 = "" ; $$foo2 = "" ; $$foo3 = "" */ ]; N ) I get the first of the attached results. If I eliminate the comment markers and evaluate again, cancel ( so the expression is not stored in WATCH) then the empty values are declared, - see second screenshot.
November 7, 201510 yr 15 minutes ago, LaRetta said: the empty global variable disappears but if you've copied it to watch tab, it will stick around (only in the watch tab) even after script end. I don't think that applies here. The Watch tab keeps track of expressions, not of variables. 13 minutes ago, BruceR said: If I eliminate the comment markers and evaluate again, cancel ( so the expression is not stored in WATCH) then the empty values are declared, - see second screenshot. I am looking at your second screenshot and I don't see them. Edited November 7, 201510 yr by comment
November 7, 201510 yr 1 minute ago, BruceR said: Yes. That is the correct result. They do no exist. Okay then. I guess you meant to say they were erased, instead of declared.
November 7, 201510 yr I guess so. We may want to come up with consistent terminology. My attempt to summarize: If a variable is declared to hold a value (by script, Dataviewer watch statement, or whatever); then you can see it in the Current tab of Data Viewer. In Data Viewer, you can even clear the value; but the variable name will persist, and in data viewer you can go back and put a value in it. That is, if nothing else ( WATCH expression, script, layout object expression re-declares it). However, if a variable declaration statement ( WATCH expression, script step, layout-based variable declaration, etc) sets (declares? erases?) the value to empty, when you go back to Data Viewer CURRENT tab you won't see the variable name at all.
November 7, 201510 yr I don't disagree, I just think that for all practical purposes it's sufficient to say that setting a variable to empty erases it . Even if we were to concede the possibility of an empty variable "existing" somehow, there is no way I know of to distinguish it from a variable that doesn't exist (to answer the original question). So this is just a matter of "do you believe that empty variables exist?".
Create an account or sign in to comment