list constants (show all constants)

Is there any way to show all the constants available without entering the debugger?

The application will be within a panel showing the scientific constants that have been saved.

 

PS: The new forum formatting makes it a little hard to see where a post ends...

It's not, it's rather that I am using a package which includes various constants and I want to display to the user what they are.

In terms of that old thread, my question would be, how can we list all the constants after they are programmed in?

Thanks for pointing it out though.

Unfortunately, I think the only way would be to maintain a list of the names of available constants. With that, a name chosen from the list of available constant names can be "pseudo-dereferenced", for lack of a better term, with an execute statement. Here's an example of what I mean. 

 

constant kaaa = 3
constant kbbb = 5
constant kccc = 7
constant kddd = 12
strconstant constantsList = "kaaa;kbbb;kccc;kddd;"      //all constants that will be "listable" must be listed here

function getConstantValue(constantName)
    String constantName         //constant whose value is sought

    Variable/G getConstantTempVar
   
    if (findlistitem(constantName,constantsList) < 0)
        return NaN      //no constant in the constantsList has this name
    endif
    execute/q "getConstantTempVar = " + constantName
   
    Variable localVal = getConstantTempVar // store variable value locally so the global can be killed
    killvariables/z getConstantTempVar
    return localVal
end

function printChosenConstant()
    String chosenConstantName
    prompt chosenConstantName, "choose a constant", popup constantsList
    doprompt "constant chooser", chosenConstantName
    if (V_flag)
        print "no constant chosen"
    else
        print getConstantValue(chosenConstantName)
    endif
end

Compiling this and running printChosenConstant() at the command line allows the user to print the value of chosen constants. Other GUI tools could be created similarly. 

Personally, I have long wished that there was a WaveList for free waves, a VariableList for local (or constant) variables, and so on. I also presume the debugger must have a way to do this, so there would be a way for Igor to make such functions available at run time. For me, the most important use case would be that I could create a bunch of local variables during analysis and then place them into an wave output with concise code (where I never have to keep track of exactly how many local variables I created), but such functions would clearly be more broadly useful.

 

Thanks for the reply.  I can't say I judge Igor for not having this (I just googled and even Python doesn't really have it either).

In reply to by jcor

maybe you could parse the procedure file(s) for constant declarations?

see help for winList (to get a list of all open procedures), FunctionPath (to find one procedure file) and grep (to extract the appropriate lines of code).

here's an extract from some code to look for a specific static string constant:

sprintf s_exp, "(?i)^[\s]*static[\s]*strconstant[\s]*%s[\s]*=", constantNameStr
Grep /Q/E=s_exp/LIST/Z pathToFile

note that newly added constants in compiled but not saved procedures cannot be extracted like this.

In reply to by tony

That's a nice idea. The current (rather than last saved) procedure text is available through the ProcedureText function. Then GrepString could be used instead of Grep.

 

ProcedureText returns the current text even for uncompiled procedures, which is a downside in this case (I suppose saved procedures might also be uncompiled, though). I think that one could first determine whether a procedure window is compiled by checking function list for the first function in each procedure. There may be a more straightforward way to tell that I am not aware of. 

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More