Topic
  • 2 replies
  • Latest Post - ‏2014-03-31T20:34:56Z by llandale
llandale
llandale
3035 Posts

Pinned topic addr_ of Params

‏2014-03-28T18:35:02Z |

Can someone make this work?  All this address of alias and pointers is still VooDoo to me.

I want to associate a declared variable with a Parameter then set the variable by associating the parameter with an actual value.  Success is when the final print statement is:

  • <<SSFolder = 'SpecFolder Value'>>

Skip   skpParams = createString() // I think I need a Skip list to remember the associations
string  SSFolder  = ""  // This is the variable I wish to set
const string cSpecParam = "SpecFolder"

//************************************************
void Associate(string Variable, Parameter)
{ //Associate the Variable with the Parameter
 int &iAddr = (int addr_(Variable))
 put(skpParams, Parameter, iAddr)
} // end Associate()

//************************************************
void ParamSet(string Parameter, Value)
{ // Set the Variable associated with the Parameter to the Value
 int &iAddr
 find(skpParams, Parameter, iAddr)
 iAddr = (string Value) // This should set the Variable
} // end ParamSet()

              // begin MAIN:
Associate(SSFolder, cSpecParam)
ParamSet (cSpecFold, "SpecFolder Value")
print "<<SSFolder = '" SSFolder "'>>" // should print <<SSFolder = 'SpecFolder Value'>>

-Louie

I'm really after initializing a bunch of variables in my include file based on the values specified for the current project, as defined in a project parameter module.  For instance, one project may want a particular link module named "Testing Links", and another project call the same link module "Verification Links".  So I'd have a variable "Testing_LMName" which gets set at run time, depending on the current Project running the script.

  • Mathias Mamsch
    Mathias Mamsch
    2135 Posts

    Re: addr_ of Params

    ‏2014-03-30T22:31:28Z  

    Well. You can put a reference to a variable into a Skip easily (common mistake resulting in Skip crashes), but retrieving the reference from the skip is not so easy (because of the references super powers). Therefore I guess the easiest way to get the reference back is to use a pointer (i.e. a reference without 'super powers') to retrieve the reference back from the Skip and assign a new value to it:

        Skip   skpParams = createString() // I think I need a Skip list to remember the associations
        string  SSFolder  = ""  // This is the variable I wish to set
        const string cSpecParam = "SpecFolder"
    
        //************************************************
        void Associate(string &Variable, Parameter)
        { //Associate the Variable with the Parameter
           put (skpParams, Parameter, Variable); 
        } // end Associate()
    
        //************************************************
        void ParamSet(string Parameter, Value)
        { // Set the Variable associated with the Parameter to the Value
           string *ref; 
           if (find(skpParams, Parameter, ref)) { *ref = Value }
    
        } // end ParamSet()
    
        // begin MAIN:
        Associate(SSFolder, cSpecParam)
        ParamSet (cSpecParam, "SpecFolder Value")
        print "<<SSFolder = '" SSFolder "'>>" // should print <<SSFolder = 'SpecFolder Value'>>
    

    Hope this helps, regards, Mathias

    Updated on 2014-03-31T00:00:35Z at 2014-03-31T00:00:35Z by Mathias Mamsch
  • llandale
    llandale
    3035 Posts

    Re: addr_ of Params

    ‏2014-03-31T20:34:56Z  

    Well. You can put a reference to a variable into a Skip easily (common mistake resulting in Skip crashes), but retrieving the reference from the skip is not so easy (because of the references super powers). Therefore I guess the easiest way to get the reference back is to use a pointer (i.e. a reference without 'super powers') to retrieve the reference back from the Skip and assign a new value to it:

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr"> Skip skpParams = createString() // I think I need a Skip list to remember the associations string SSFolder = "" // This is the variable I wish to set const string cSpecParam = "SpecFolder" //************************************************ void Associate(string &Variable, Parameter) { //Associate the Variable with the Parameter put (skpParams, Parameter, Variable); } // end Associate() //************************************************ void ParamSet(string Parameter, Value) { // Set the Variable associated with the Parameter to the Value string *ref; if (find(skpParams, Parameter, ref)) { *ref = Value } } // end ParamSet() // begin MAIN: Associate(SSFolder, cSpecParam) ParamSet (cSpecParam, "SpecFolder Value") print "<<SSFolder = '" SSFolder "'>>" // should print <<SSFolder = 'SpecFolder Value'>> </pre>

    Hope this helps, regards, Mathias

    That will work thanks.