Dumping variables from lists ColdFusion 9 - coldfusion

I have this struct after I dump it like this:
<cfdump var="#currentInfo.answers#">
How can I access the value inside the LIST?
I need to compare that value with another variable in the future to allow me to do certain operations.

The code below ought to do it:
currentInfo.answers["F0FF5FDC-D2C3-4D0F-D7D2D2886D5B430d"].LIST

Since the value is dynamic you'll need something like this:
currentKey="F0FF5FDC-D2C3-4D0F-D7D2D2886D5B430d";
currentInfo.answers[currentKey].LIST;

Related

Shorter way to write variables as input/ output of function

I`m using a function within a script which produces a number of variables.
The function is used at different places in the script.
It produces variables a,b,c,d,e etc
def function(input):
a,b,c,d,e = 1,2,3,4,5
return a,b,c,d,e
I call the function as follows:
a,b,c,d,e = function(input)
This way all the variables a,b,c,d,e etc... need to be repeated every time I want to use the function. Is there a way to prevent this repetition?
For example I tried to make a list of the variables and then zip them with the output of the function and then connect them but that is not working.
listofvariables = [a,b,c,d,e]
outputfunction = function(input)
gezipt = zip(listofvariables,outputfunction)
for itm in gezipt:
itm[0] = itm[1]
That way when I change the function I would have to rewrite the list with the variables once and not every time the function is used. but that doesnt work.
The answer to your question, of whether you can programmatically set variables is mostly no. There probably are ways you could make it work, but they'd be fragile or hard to understand. Generally speaking, treating variable names as part of your program's data is a bad idea.
If you have lots of related data items, you should generally be using a data structure to group them all together, rather than using separate variables for each one. Your example is dealing with a batch of five variables, and at several different points keeps them in a tuple. That tuple is probably what you want, though you could use a list if you need to modify the values, or maybe a dictionary if you wanted to be able to index them by key (e.g. {"a": 1, "b": 2}). For other more complicated situations, you might need to program up your own container for the data, such as a class. You might even use several different containers for different sub-sets of your data, and then keep those separate containers in a further container (resulting in a nested data structure).
Unfortunately, that's about as detailed as we can get without more details about your circumstances. If you need more specific help, you should probably ask another question with more details about your actual application.

Is there any way to give different names to the members of an array?

For example I am making a Pacman game and I am using a struct array to represent the ghosts.
But is there any way to change the ghost[0] expression to Inky ?
It seems you are looking for associative array. Associative array is an array that can be accessed with something like association. For example, if you want to access your fruits array and get the apple, you could do: fruits["apple"] and get the value, instead of wondering which index the apple was.
If this is what you are really looking for, then in C++ it is called a map. The map is the same as associative array. Take a look onto how to use it.
https://en.cppreference.com/w/cpp/container/map
You can define a reference to any item in your struct array.
Example:
Ghost &inky = ghosts[0];
Ghost &blinky = ghosts[1];
Ghost &pinky = ghosts[2];
Ghost &clyde = ghosts[3];
To respect C++ convention, I recommand that all these references are defined with a name that begin with a lower case.
You can then use all these references as normal variables using . to call member's functions or to read or assign member's variables.
Example:
inky.setBackColor(blue);
inky.remove();
clyde.size += 2;

Can we use variables in Siddhi SQL statements?

I'm going to use the same value in lots of statements in the SQL Expression. So it is possible to declare and assign the value to a variable at the beginning of the query and refer the value by it?
(I'm writing an execution plan in WSO2 DAS)
This is not supported as of now. However, supporting this has been under discussion, hence this might be implemented in a future release.
If you want to store a value and use it in a query, the currently available ways are:
Putting that value into an indexed event table and then doing a join with the event table to read that value whenever required.
Indexed In-memory Event Table internally uses a Hash-Map, therefore you could use one to store your variables, in such a way that the key of the hashmap will be the name of your varaible and the value of the hashmap will be the value of your variable.
However I feel that above solution is too complicated for your requirement.
Using the Map Extension in Siddhi

Is it possible to programmatically create objects of structs and fill the fields, when you have a list of struct names and field values

Is it possible to programmatically create objects of structs and fill the fields, when you have a list of struct names and field values?
Say I have to read entry from (JSON)file and fill up my structs. I have value struct names and values but i want to code such that code will loop all structs and fill the in-memory data. may sound wierd, but is there a way?
Nope. The language feature you're looking for is called reflection, and C++ does not have it.
You could build up a std::map<std::string, SomeType> instead? If SomeType differs depending on the field, a boost::variant will allow you to store any of a number of types at any given time (it's basically a tagged union).
Or you could switch to Python. :)

C++11 modify values in std::discrete_distribution

Is it possible to modify single value in std::discrete_distribution? I can't find a simple way of doing this. I was thinking of initializing it with std::vector with assigned probabilities and modifying it everytime I want, but reinitializing discrete_distribution everytime seems to be not the best idea.
You can't, there's no following function in std::discrete_distribution.
You can get probabilities, but not set, so, there is only one way - reinit discrete_distribuion (probably you can use vector of predefined destributions).