parameter-passing

When to use missing versus NULL values for passing undefined function arguments in R, and why?

醉酒当歌 提交于 2019-11-30 14:06:40
To date when writing R functions I've passed undefined arguments as NULL values and then tested whether they are NULL i.e. f1 <- function (x = NULL) { if(is.null(x)) ... } However I recently discovered the possibility of passing undefined arguments as missing i.e. f2 <- function (x) { if(missing(x)) ... } The R documentation states that Currently missing can only be used in the immediate body of the function that defines the argument, not in the body of a nested function or a local call. This may change in the future. Clearly this is one disadvantage of using missing to determine undefined

How to send multiple arguments to jQuery click function?

一个人想着一个人 提交于 2019-11-30 12:53:16
Currently I'm using something like: $('.myclass').click(function(){ var msg = $(this).attr('id'); alert(msg) }); And HTML: < a href="#" class="myclass" id="101">Link</a> If I need additional parameters how would I read them? Also is the current way I am using the proper way? Originally I was using hidden input fields so it was already a step up. :p ChaosPandion jQuery Events jQuery .click() $('.myclass').bind("click", { Param1: "", Param2: 2 }, function(event){ alert(event.data.Param2); }); you can use bind() and send additional data to the event handler as event.data this may not be the best

Best way of passing callback function parameters in C++

谁说我不能喝 提交于 2019-11-30 11:48:30
What is the best way of passing a callback function parameter in C++? I thought of simply using templates, like this: template <typename Function> void DoSomething(Function callback) This is the way used e.g. in std::sort for the comparison function object. What about passing using && ? E.g.: template <typename Function> void DoSomething(Function&& callback) What are the pros and cons of those two methods, and why does the STL uses the former e.g. in std::sort ? Cheers and hth. - Alf The template <typename Function> void DoSomething(Function&& callback) … which uses a forwarding reference to

Why use packed *args/**kwargs instead of passing list/dict?

我只是一个虾纸丫 提交于 2019-11-30 11:37:35
问题 If I don't know how many arguments a function will be passed, I could write the function using argument packing: def add(factor, *nums): """Add numbers and multiply by factor.""" return sum(nums) * factor Alternatively, I could avoid argument packing by passing a list of numbers as the argument: def add(factor, nums): """Add numbers and multiply by factor. :type factor: int :type nums: list of int """ return sum(nums) * factor Is there an advantage to using argument packing *args over passing

Optional argument in PL/pgSQL function

£可爱£侵袭症+ 提交于 2019-11-30 10:51:49
I am trying to write a PL/pgSQL function with optional arguments. It performs a query based on a filtered set of records (if specified), otherwise performs a query on the entire data set in a table. For example (PSEUDO CODE) : CREATE OR REPLACE FUNCTION foofunc(param1 integer, param2 date, param2 date, optional_list_of_ids=[]) RETURNS SETOF RECORD AS $$ IF len(optional_list_of_ids) > 0 THEN RETURN QUERY (SELECT * from foobar where f1=param1 AND f2=param2 AND id in optional_list_of_ids); ELSE RETURN QUERY (SELECT * from foobar where f1=param1 AND f2=param2); ENDIF $$ LANGUAGE SQL; What would be

Store Bash script arguments $@ in a variable

若如初见. 提交于 2019-11-30 10:32:44
How can I store $@ in a variable while keeping its properties? I want to obtain exactly the same behavior even if I use $@ or my own variable in all possible situations. The attempts below didn't work: args=$@ args2="$@" # the arguments are combined (see the last output paragraph) I tested them using the following line: s.sh A B=" " C s.sh #!/bin/bash args=$@ args2="$@" #args3 = ? - TODO echo $args echo $args2 echo $@ #echo $args3 echo echo "$args" echo "$args2" echo "$@" #echo "$args3" echo java A $args java A $args2 java A $@ #java A $args3 echo java A "$args" java A "$args2" java A "$@"

How pass variables by reference to a Scilab function

笑着哭i 提交于 2019-11-30 09:52:18
问题 I want to have a Scilab function which is able to alter its input variables, For example in C I could have void double(int* x){ *x *= 2; return; } There are intppty , funptr , addinter , istk , sadr and stk in Scilab which seem to be relevant, however I can't find any working example. Scilab does have a pointer type (i.e. 128 ). I would appreciate if you could help me figure this out. P.S.1. I have also mirrored this question here on Reddit. P.S.2. Scilab also have intersci , SWIG , fort ,

how to pass multiple parameters to a method in java reflections

白昼怎懂夜的黑 提交于 2019-11-30 09:43:58
Hi i am using reflections to achieve something. I have been given class name, method name of that class and parameter values that needs to be passed to that method in a file(Take any file. Not a constraint). I have to call that method with the parameters. This methods do not return anything. There is a huge list of methods in this classes and parameter list of each varies. E.g: method1(String, String, int, boolean) method1(String, int, boolean) and likewise i have different permutations and combinations. So how can i achieve this. I have tried hard coding things with different switch clauses

How do I print a fibonacci sequence to the nth number in Python?

≯℡__Kan透↙ 提交于 2019-11-30 09:34:24
I have a homework assignment that I'm stumped on. I'm trying to write a program that outputs the fibonacci sequence up the nth number. Here's what I have so far: def fib(): n = int(input("Please Enter a number: ")) if n == 1: return(1) elif n == 0: return(0) else: return (n-1) + (n-2) mylist = range[0:n] print(mylist) I'm thinking I could use separate functions but I can't figure out how to pass the argument that calculates the fibonacci sequence. Then the next step would be to to print out the sequence of numbers up to that number. J0HN Non-recursive solution def fib(n): cur = 1 old = 1 i = 1

How can I pass a PHP variable to javascript?

与世无争的帅哥 提交于 2019-11-30 09:30:03
问题 I want to use a PHP variable as a javascript variable - specifically I want to user the PHP variable session_id(); and use this as a javascript variable. <?php $php_var = session_id(); ?> <script language="JavaScript" type="text/javascript"> js_var = <?php echo($php_var ?>; </script> This seems like it should work for me but it doesnt can anyone suggest a better way? 回答1: The best method i can think of looks like this: <?php $php_var = session_id(); ?> <script type="text/javascript"> var js