I want to use an IRR function which has the following syntax:
finance('IRR',var1,var2,var3....,varn);
How can I apply a range to this? I've tried:
finance('IRR',var1-var120);
but it doesn't like it. It thinks there are only 2 arguments
Use the variable name list operator OF.
finance('IRR', OF var1-var120);
Related
I need to get information from a class function. Said class has overloaded operators for basically any standard type. Therefore
double foo = exampleObject.getInformation();
and
std::string faa = exampleObject.getInformation();
Would both work. If the information can not be transformed into a double, foo will be set to 0. The initialization of faa will always work. (It can always be expressed as a string)
My problem is: I want to get the information and save it as a double variable, if that can not be done as the information is not of numeric type, I want the variable to be a string. I basically need a variable that can change its type. How do I do this? I'm sorry if that is a very basic question, C++ is not my main programming language.
Have you tried using Function Templates?
They won't change the type of a variable but will allow you to write your code in a way that works with more than 1 data type.
If c++ is not your main, I would recommend checking the checking the documentation for Function Templates on cplusplus.com
Here => https://cplusplus.com/doc/oldtutorial/templates/
I am relatively new to sqlite using C++, I found a statement like
"INSERT INTO files "
"(md5path_1, md5path_2, parent)"
"VALUES (:md5_1, :md5_2, :p)"
Why are those colons used?
These are called Bind Variables
With the use of bind variables the statement remains the same, therefore there is only one statement cached as opposed to many.
This is taken from the introduction to SQLite
SQLite allows a parameter wherever a string literal, numeric constant,
or NULL is allowed. (Parameters may not be used for column or table
names.) A parameter takes one of the following forms:
?
?NNN
:AAA
$AAA
#AAA
In the examples above, NNN is an integer value
and AAA is an identifier. A parameter initially has a value of NULL.
Prior to calling sqlite3_step() for the first time or immediately
after sqlite3_reset(), the application can invoke the sqlite3_bind()
interfaces to attach values to the parameters. Each call to
sqlite3_bind() overrides prior bindings on the same parameter.
So, it's a placeholder you can bind later to a variable using sqlite3_bind()
They called "bind variables". Later in the code you'll definitely see something like
exec_query("INSERT....", val1, val2, val3)
where val1 - val3 will contain value to be inserted.
Using variables has many advantages. In case of insert statement:
It helps to avoid SQL-injections. Thus no one will be able to ruin your query by passing special statements to variables.
You don't have to compose sql-statement every time you need it. You can just use that one from your question passing new parameters each time you run it
When creating a live template in WebStorm 2017.3.2 is there a way to apply multiple predefined functions on a single input? Or perhaps reference template variables from other template variables from within the same template?
Say for example I want to apply the capitalizeAndUnderscore function to $FOO$ and also apply the camelCase function to the same input supplied to the $FOO$ variable elsewhere in the template?
In other words, is it possible to achieve the following:
$FOO$: '$FOO_REFERENCE$' expands to MY_WHATEVER: 'myWhatever'
While only having to type mywhatever 1 single time?
Both capitalizeAndUnderscore() and camelCase() functions have String parameter - it can be a string constant, expression or a reference to already defined variable. So, you can easily use capitalizeAndUnderscore(FOO) as $FOO_REFERENCE$ value. But referencing variables defined in other templates is not supported. And you need to make sure that $FOO$ value is defined before being used.
Usually in my code I need to use specific functions for various variables i.e.
object->SetStatus("var1",1); object->SetAddress("var1",&var1);
object->SetStatus("var2",1); object->SetAddress("var2",&var2);
object->SetStatus("var3",1); object->SetAddress("var3",&var3);
...
My idea is to use a function that will do this automatically by calling it, i.e.
object->function(var1,var2,var3,...);
To achieve that I have to solve 3 issues
I need to read the number of arguments when calling function()
I need to parse somehow the argument names inside the code
Since the variables are not of the same type, I need to find a way to make function() type "transparent"
Since I am newbie in c++ coding, I tried to search fo something similar, but I couldn't find anything.
Any help, advice or remark is more than welcome!
There are multiple ways to do so. One way is make a Base class and all your variable type will inherit from this base class. Then pass a map<string,Base> as an argument to you function. name of variable will be key and value will be actual variables. Iterate through the map and set and assign values to methods.
You could consider some variadic template, if coding in C++11 or C++14. There is considerable literature about that subject (e.g. this tutorial), which is a bit tricky (so explaining it here is not reasonable). Read also about parameter pack
You could also use C style varargs using <cstdarg>
Perhaps std::initializer_list could be useful too.
Is there such a mechanism in OCaml, such that I could invoke a function dynamically based on a variable storing the function name, like what I can do in other scripting languages?
For example, I have written a function foo(). And I store the String constants "foo" somewhere in a variable "x". In JavaScript I'm able to do something like this window[x](arguments); to dynamically invoke the method foo(). Can I do something similar in OCaml?
No, this is not the kind of thing that OCaml lets you do easily. The program definition, including the names of functions and so on, isn't available for the program itself to manipulate.
A simple way to get this effect for a set of functions known ahead of time is to make a dictionary (a hash table or a map, say) of functions using the function name as the key. Note that this will require the functions to have the same type (which is a feature of OCaml not a problem :-).