arguments

How to let a method accept two types of data as argument?

浪子不回头ぞ 提交于 2020-01-05 04:26:07
问题 I have a method, accepting a Hashtable (yes I know, it's outdated..) as argument: public static LuaTable HashtableToLuatable(Hashtable t, int depth = 1) This works correctly. Now I'd like to accept an ArrayList as first parameter as well, so you can let 't' have the value of both a Hashtable and an ArrayList. Currently I have copy-pasted the method two times, like this: public static LuaTable ArraylistToLuatable(ArrayList t, int depth = 1) The rest is exactly the same. I think there's a way

How does getArgs work?

我的未来我决定 提交于 2020-01-04 14:02:56
问题 I am trying to understand getArgs in Haskell. Here is what I have: import System.Environment myFunFunction = do args <- getArgs return $ head args What I am getting when I run the function is *Main> myFunFunction *** Exception: Prelude.head: empty list Does this not work the same way as getLine ? Why does it not ask for a command line argument? 回答1: The type of getArgs is IO [String] . When you bind it with <- , as in the OP, the bound symbol ( args ) gets the type [String] , i.e. a list of

Faster way to perform checks on method arguments

﹥>﹥吖頭↗ 提交于 2020-01-04 10:59:12
问题 This is mostly just out of curiosity, and is potentially a silly question. :) I have a method like this: public void MyMethod(string arg1, string arg2, int arg3, string arg4, MyClass arg5) { // some magic here } None of the arguments can be null, and none of the string arguments can equal String.Empty . Instead of me having a big list of: if(arg1 == string.Empty || arg1 == null) { throw new ArgumentException("issue with arg1"); } is there a quicker way to just check all the string arguments?

Giving arguments from “…” argument to right function in R [duplicate]

喜夏-厌秋 提交于 2020-01-04 07:37:07
问题 This question already has answers here : Split up `…` arguments and distribute to multiple functions (3 answers) Closed 3 years ago . I have a function to compute the correlation of matrix of both categorical and continuous variables: correlation <- function(matrix, ...) { xx <- do.call(rbind, lapply(colnames(mtrc), function(ex_i) { ty_i <- wtype(matrix, ex_i) yy <- sapply(colnames(mtrc), function(ex_j) { ty_j <- wtype(matrix, ex_j) if(ty_i == "numeric" & ty_j == "numeric") { cor(mtrc[ , c(ex

Giving arguments from “…” argument to right function in R [duplicate]

ぐ巨炮叔叔 提交于 2020-01-04 07:34:07
问题 This question already has answers here : Split up `…` arguments and distribute to multiple functions (3 answers) Closed 3 years ago . I have a function to compute the correlation of matrix of both categorical and continuous variables: correlation <- function(matrix, ...) { xx <- do.call(rbind, lapply(colnames(mtrc), function(ex_i) { ty_i <- wtype(matrix, ex_i) yy <- sapply(colnames(mtrc), function(ex_j) { ty_j <- wtype(matrix, ex_j) if(ty_i == "numeric" & ty_j == "numeric") { cor(mtrc[ , c(ex

Pointer to a function with reduced arguments

烈酒焚心 提交于 2020-01-04 06:43:46
问题 I've a problem with function pointers: I need to numerically integrate a function and want therefore pass a pointer with the function to the "integrator". The problem is, that the function to be integrated takes more then just one argument. Something like: double f(int i, double x){ // i to switch the function, x to evaluate if(i==1) {return sin(x);} if(i==2) {return exp(x);} } double integrate(double (*function)(double), double x0, double x1){ //integrate the passed *function from x0 to x1 }

wrong argument conversion preferred when calling function

本小妞迷上赌 提交于 2020-01-04 04:00:46
问题 I'm writing a program under MS Visual C++ 6.0 (yes, I know it's ancient, no there's nothing I can do to upgrade). I'm seeing some behavior that I think is really weird. I have a class with two constructors defined like this: class MyClass { public: explicit MyClass(bool bAbsolute = true, bool bLocation = false) : m_bAbsolute(bAbsolute), m_bLocation(bLocation) { ; } MyClass(const RWCString& strPath, bool bLocation = false); private: bool m_bAbsolute; bool m_bLocation; }; When I instantiate an

Proper way to limit possible string argument values and see them in intellisense

雨燕双飞 提交于 2020-01-03 10:46:09
问题 Environment: Visual Studio 2012, .NET 4 Framework, ASP.NET web application (C#) I'd like to know the best, most advisable approach to accomplish limiting incoming arguments (of any type...int, string, etc...) to a predefined set of desired values. I'd like to know the industry-accepted best way. (the following code does not work - it's just to better illustrate the question) Lets say I have a utilities class something like this: public class Utilities { public string ConvertFromBytes(int

How to unshift or add to the beginning of arguments object in JavaScript

早过忘川 提交于 2020-01-03 08:29:14
问题 I've just learned the convention for popping off the first element of the arguments array (which I also learned is actually an Object ). Now I need to do the opposite. I need to use an unshift operation to add a value to the beginning of the arguments array (or Object acting like an array). Is this possible? I tried: Array.prototype.unshift.apply('hello', arguments); That had no effect on arguments whatsoever. 回答1: use .call() instead of .apply() to invoke unshift() set arguments as the this

Why does the use of … in any expression in a function cause the value of arg to be nil in Lua?

强颜欢笑 提交于 2020-01-03 08:20:10
问题 function tell(num,...) print("value of implicit table:",arg) --print("value of implicit table:",...) select(1,arg) --select(1,...) end tell(12,43,12,55) Why is it that using ... in an expression causes the value of arg to be nil e.g. with print("value of implicit table:",...) or select(1,...) ? 回答1: Lua 5.1 officially deprecates the use of the arg table for varargs, preferring ... . However, there is a compile time option for Lua itself, LUA_COMPAT_VARARG , to permit the use of arg in 5.1