w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to evaluate arguments of a function call inside other function in R
Lift myfun out of lowerfun and modify the eval call as below. When making a package, if you do not export myfun it will not be accessible directly from R_GlobalEnv, but it can still be called from within lowerfun. topfunction <- function(x){ lowerfunction(myfun(first=x[1], second=x[2], third=if(length(x)>2) x[3])) } lowerfunction<-function(mycall){ mc <- match.call(definition = myfun, call = match.call()[[2]]) eval(mc, envir=parent.frame()) } myfun <- function(first, second=0, third=NULL){ print(first) print(second) print(third) } Example run: > topfunction(1:3) [1] 1 [1] 2 [1] 3 Off topic: myfun can still be accessed from R_GlobalEnv by calling getFromNamespace("myfun", "mypackage") Update If you really want to keep myfun within low

Categories : R

C function call with too few arguments
EDIT: I found a stack thread C function with no parameters behavior which gives a very succinct and specific, accurate answer. PMG's comment at the end of the answer taks about UB. Below were my original thoughts, which I think are along the same lines and explain why the behaviour is UB.. Questions: is the result of a function call with missing arguments defined? I would say no... The reason being is that I think the function will operate as-if it had the second parameter, but as explained below, that second parameter could just be junk. If so, what value will the function receive for the unspecified argument? I think the values received are undefined. This is why you could have UB. There are two general ways of parameter passing that I'm aware of... (Wikiped

Categories : C

MPI call inside function and function arguments
This seems to be a fairly common misunderstanding among MPI beginners. MPI_Init() and MPI_Finalize() do not mark the start and end of parallel processing. They mark the start and end of where other MPI calls are permitted. MPI runs multiple separate instances of your entire program, each with its own separate memory space. So yes, each process has its own copy of a and i.

Categories : C

Call main function with arguments
The Haskell report specifies that the main function always has type IO t, (for some type t which will be ignored) and hence never takes normal function arguments, so this is not the right approach. You are looking for the function getArgs (for which you have to import the module System.Environment. It returns the arguments passed to your program as a list of Strings. So your code would look like: import System.Environment main = do args <- getArgs case args of [file] -> do x <- readFile file putStr x _ -> putStrLn "Wrong number of arguments"

Categories : Haskell

Call function with arguments without parenthesis in C?
That's not going to be possible in C the way you have it. §6.5.2 of the standard (C99) describes postfix expressions, and has no syntax like that. Function calls are (§6.5.2.2): A postfix expression followed by parentheses () containing a possibly empty, comma-separated list of expressions is a function call. The postfix expression denotes the called function. The list of expressions specifies the arguments to the function. Parens are not optional, and they need to wrap all the arguments so you need either a function-like macro (which requires parens at the "call" site) or two separate things (one to insert the starting paren, one to insert the closing one). You could do: #define test puts( #define end ); #define int_proc int #define proc_body { #define proc_end } #define no_ar

Categories : C

JS call function with all possible arguments permuted
Declare you function without parameters and use arguments keyword: function cartesianCall() { for (var i = 0; i < arguments.length; i++) { // do something with arguments[i] } }

Categories : Javascript

Call a function with list or splat arguments
The equivalent of JavaScript's apply() is call() in Vimscript: function! hello(...) call call('run_hello', ['foo'] + a:000) endfunction This is no typo: You :call the function named call().

Categories : Vim

Javascript call a function several times with the arguments
A simple for loop! for (var i = 1; i <= 7; ++i) { fillWebsitePlaceFiller(i); } Or, just as easily, modify fillWebsitePlaceFiller to do its own for loop: function fillWebsitePlaceFiller() { for (var i = 1; i <= 7; ++i) { document.getElementById("placefillerWebsite" + i).innerHTML = placefillerWebsite; } }

Categories : Javascript

PHP function - Call self with same (variable number) arguments
Use call_user_func_array. Example: class TestClass { private $ting = FALSE; public function test() { $args = func_get_args(); if ($this->ting) { var_dump($args); } else { $this->ting = TRUE; call_user_func_array(array($this, 'test'),$args); } } } $test = new TestClass(); //Outputs array(3) { [0]=> string(6) "apples" [1]=> string(7) "oranges" [2]=> string(5) "pears" } $test->test("apples","oranges","pears");

Categories : PHP

call function dynamically, passing arguments from variable
I suppose you could just pass $_POST['data'] as is to your dynamic method. You can have the dynamic method accept the array but initially set default values so you can easily handle and validate them. Example: class AController { public function dynamicMethod($params) { // Set default values but allow them to be overridden by $params $locals = array_merge(array( 'name' => 'John Doe', 'address' => 'Nowhere', ), $params); // Do stuffs and return result. Example: return array('nameAndAddress' => $locals['name'] . ' lives at ' . $locals['address']); } } You also opt to use extract() to convert the name and address above into real local variables. In your ajax handle: $controller = new $className; $result = $controller->$methodName($_PO

Categories : PHP

Retrieving arguments of a function call with default values in R
The first thing to note is that all of the named arguments you're after (from, to, by, etc.) belong to seq.default(), the method that is dispatched by your call to seq(), and not to seq() itself. (seq() itself only has one formal, ...). From there you can use these two building blocks ## (1) Retrieves pairlist of all formals formals(seq.default) # [long pairlist object omitted to save space] ## (2) Matches supplied arguments to formals match.call(definition = seq.default, call = quote(seq.default(1,10))) # seq.default(from = 1, to = 10) to do something like this: modifyList(formals(seq.default), as.list(match.call(seq.default, quote(seq.default(1,10))))[-1]) # $from # [1] 1 # # $to # [1] 10 # # $by # ((to - from)/(length.out - 1)) # # $length.out # NULL # # $along.with

Categories : R

Why Python’s function call semantics pass-in keyword arguments are not ordered?
Because dictionaries are not ordered by definition. I think it really is that simple. The point of kwargs is to take care of exactly those formal parameters which are not ordered. If you did know the order then you could receive them as 'normal' parameters or *args. Here is a dictionary definition. CPython implementation detail: Keys and values are listed in an arbitrary order which is non-random, varies across Python implementations, and depends on the dictionary’s history of insertions and deletions. http://docs.python.org/2/library/stdtypes.html#dict Python's dictionaries are central to the way the whole language works, so they are highly optimised. Adding ordering would impact performance and require more storage and processing overhead. You may have a case where th

Categories : Python

How do I make a button determine its table position, call a function and send arguments to it?
its easy with jquery $('button').click(function(){ var td= $(this).closest('tr').find('td'); var id=$(td[0]).html(); var name=$(td[1]).html(); var yourstring = 'id="'+id+'" name="'+name+'"'; alert(yourstring); }); Demo

Categories : PHP

Why won't template parameter pack be deduced to multiple type arguments in function call?
What is happening is that a template function with a template parameter pack class... Ts, and a parameter type (P) of foo<Ts...> is being deduced against an argument type (A) of foo<int>. 14.8.2.5/9 says of this: If P has a form that contains <T> or <i> [it does], then each argument Pi [Ts...] of the respective template argument list P is compared with the corresponding argument Ai [int] of the corresponding template argument list of A. If the template argument list of P contains a pack expansion that is not the last template argument, the entire template argument list is a non-deduced context. [the pack expansion is last, so the previous doesnt apply] If Pi is a pack expansion [Ts..., it is], then the pattern of Pi is compared with each remaining argum

Categories : C++

Building function call through a loop
Let's say you have this parameters: <?php $parameters = array( 'one' => 'a', 'two' => 'b', 'three' => 'c' ); Create object: <?php $listing = DB::table('listings'); And then, loop: <?php foreach ($parameters as $key => $value) { $listing = $listing->where($key, $value); } Of course you have to improve it to handle > and others. But I think you get it, right? At last: <?php $listing = $listing->get();

Categories : PHP

call jquery function within a php loop
Passing the data to JavaScript is exactly what I'd suggest. <script> var threads = <?php echo json_encode($threads); ?>; </script> Whenever you pass data to JavaScript, use json_encode() to make sure all the types and escaping are done for you. From there, you can handle everything you need to do in JavaScript.

Categories : PHP

For loop function call file parsing
The issue is that looping with adData causes adFile to be read, and so after the first call to matchName() the file will have been read all the way and thus adData won't be looped over as adData.next() won't result in anything (and thus the print statement will not be executed). I suggest placing adFile.seek(0) after the call to matchName(). Note that just recreating adData won't work; I discovered recently that a csv reader updates its underlying object's file position rather than keeping track of it on its own.

Categories : Python

Infinite loop function after oncomplete call - why?
At a guess, preloadMessageFadeOut() actually calls the function then and there and sets onComplete to the return value - nothing. Removing the brackets will set onComplete to the function object instead. Same for the preloadNextMessage() call.

Categories : Javascript

JS/JQuery loop chekboxes and call function by name
At its simplest I'd suggest, albeit untested: $('.filter').each(function () { var self = this; if (self.checked && self.name) { var names = self.name.match(/[(.+)]/)[1].split(']['); c1.facetFilter(names[0],names[1]); } }); JS Fiddle demo. Note, in the demo I'm, obviously, using a different function-name and also setting the checkboxes to be checked (for the purposes of demonstration). References: each(). JavaScript Regular Expressions. String.match(). String.split().

Categories : Javascript

Speed up function call inside loop
If func() always returns the same value for a given set of inputs (e.g. not time-dependent, sequence dependent etc.), then you could do the following: 1. Whenever you call func(), save the result to a cache [using values of k1...through k8 as the key to the cache-entry] 2. Before calling func(), check if you already have the required value cached The cache itself could be a Map, where you constuct the key by concatenating k1... thru ... k8 in some way that is appropriate to their data-type.

Categories : C++

Function call inside loop taking only last iteration
The code below should work, but as I commented above, please read about closure so you know why. if (ACTIVETICKETS.length > 0) { for (var m in ACTIVETICKETS) { (function(x) { if (ACTIVETICKETS.hasOwnProperty(x)) { var marker = new L.Marker(new L.LatLng(ACTIVETICKETS[x].location.x, ACTIVETICKETS[x].location.y)); createHtmlForPopUp(x, function(data){ console.log(x); marker.bindPopup( data ); // calling a function with callback tile_layer.addLayer(marker); }); } })(m); } // for loop ends here }

Categories : Javascript

How to rate limit function call in a loop in Scala
You can use Akka Throttler. Link2 import akka.actor.{Props, Actor, ActorSystem} import akka.contrib.throttle.Throttler._ import akka.contrib.throttle.TimerBasedThrottler import akka.util.Timeout import java.util.concurrent.TimeUnit import scala.concurrent.duration._ import akka.pattern.ask import Api._ import scala.concurrent.{Await, ExecutionContext, Future} import ExecutionContext.Implicits.global object Main extends App { implicit val timeout = Timeout(1 minute) val system = ActorSystem("system") val throttler = system.actorOf(Props(new TimerBasedThrottler(new Rate(3, Duration(1, TimeUnit.SECONDS))))) val worker = system.actorOf(Props(classOf[ExternalApiActor])) throttler ! SetTarget(Option(worker)) val ids = Seq(12980,2932,3441,42334,980,32,4531,7234) val listOfFuture

Categories : Scala

MySQL interprets system function call as schema function call (Error Code 1305: Function does not exist)
Make sure you are using MySQL 5.6.1 or later. ST_Contains was added in 5.6.1. From the doc you cited: As of MySQL 5.6.1, corresponding versions are available that use precise object shapes. These versions are named with an ST_ prefix. For example, Contains() uses object bounding rectangles, whereas ST_Contains() uses object shapes. Previous versions of MySQL provide a Contains function which uses the MBR of the two geometries, not their exact shape, for the test. This may work for you if you are unable to upgrade MySQL.

Categories : Mysql

Function Arguments dialog executes UDF when all non-optional arguments are filled
From my UDF page: Excel User-defined Functions To detect when a VBA UDf is being called from the function wizard you can add this code to the UDF If (Not Application.CommandBars("Standard").Controls(1).Enabled) Then Exit Function This code depends on the fact that when using the function wizard most icons in the toolbars are disabled. A solution is also possible by using the Windows API to check if the Function Wizard window is showing and has the same process ID as the current Excel process.

Categories : Excel

Best way of calling a function with different arguments passed by reference when you only need one of these arguments
Acknowledge to Mats Petersson: you can't pass nullptr as the function requires references. If the function has no warranty attached to it, then you should create temporary variables and pass them all in. It would be unsafe to pass the same variable; in case it's used in internal computation. Even if the function works with the same variable passed, there is no guarantee that someone won't change the implementation of that function in a way that causes your code to break. You could be opening yourself up to nasty bugs in the future.

Categories : C++

Jquery wait till a function with ajax call in loop is completed - Refresh after a Button Click
You're going to have to use a concept of recursion, or loops with a callback basically. (function recur(elements) { var elem = Array.prototype.shift.call(elements); if(elem) { $.ajax({ url: "/path/to/check", success: function() { recur(elements); //Success, go again } }); } else { //Done! refresh(); } })($(".radioControl:radio:checked")); What's happening here is that we first create our recur function. You might be familiar with the IIFE (Immediately Invoked Function Expression) pattern where we create an anonymous function and invoke it immediately ((function(){})()) however in this case, we name it which thus allows us to call said function within it's scope whenever we want to progr

Categories : C#

too few arguments to function even when arguments count are correct
Try and keep it simple. If the "complex" problem is failing, try a simpler approach, i.e. /* Since this doesn't work, let's try something that really should work fun_sbblink_write_OP_frame_channels (0,SBBL_FLINK,PhSlotRRH,i,0,0,0,0); */ sbblink_write_one_frame(1,2,3,4,5,6,7,8); Then, if that works try: /* Since this doesn't work, let's try something that really should work fun_sbblink_write_OP_frame_channels (0,SBBL_FLINK,PhSlotRRH,i,0,0,0,0); */ /* OK, this worked, let's go one step forward sbblink_write_one_frame(1,2,3,4,5,6,7,8); */ fun_sbblink_write_OP_frame_channels (1,2,3,4,5,6,7,8); Then try: /* OK, this silly stuff worked, let's go all the way sbblink_write_one_frame(1,2,3,4,5,6,7,8); fun_sbblink_write_OP_frame_channels (1,2,3,4,5,6,7,8); */ fun_sbblink_write_OP_fra

Categories : C

Packing an object, its method to call and arguments to call it with into a single object for invoking it later
Check out std::bind offered by C++11. It does exactly what you want. You don't even need boost for this. For example: class C { public: void Foo(int i); } C c; // Create a function object to represent c.Foo(5) std::function<void(void)> callLater=std::bind(&C::Foo,std::ref(c),5); // Then later when you want to call c.Foo(5), you do: callLater();

Categories : C++

Passing function pointer to a function + function arguments
Did you read the entire error message? You have some const- and other type mismatches (e. g. a pointer-to-struct instead of void *, etc.) in the signature of the two functions. Function types are compatible only if their signatures match exactly.

Categories : C

Passing optional arguments inside a wrapper function to a sub-function
You need to pass the ... to method.out. Then it works fine: funInFun<- function (x, method, ...) { method.out <- function(this.x, FUN, ...) { FUN <- match.fun(FUN) c <- FUN(this.x, ...) return(c) } d <- method.out(x, method, ...) # <<--- PASS `...` HERE return(d) } data<-seq(1,10) funInFun(data, mean) # Works # [1] 5.5 data<-c(NA,seq(1,10)) funInFun(data, mean, na.rm=TRUE) # Should remove the NA # [1] 5.5 funInFun(c(seq(1,10)), quantile, probs=c(.3, .6)) # 30% 60% # 3.7 6.4

Categories : R

Undefined function 'time' for input arguments of type 'double'. How do i find a function that others didn't seem to have defined in their code?
As pm89 already suspected, time in this case is a variable. Type: > help mpretrack in your command window. Amongst other information, it will say: Also, the program looks for the files "fov#times.mat" for the "time" variable and the images files "fov#fov#####.tif" from the basepath. If you don't have the specified .mat file, the variable time is unknown, which causes the error you see.

Categories : Matlab

Call Java from PHP with JSON arguments
To pass it all as a single string, put quotes around it. So it should work if you use exec("java StepRegTest.Main "" . $input . "" 2>&1", $output); //Note the added quotes The issue has nothing to do with String vs. String[], it's just an issue that, if you don't put them in quotes function arguments are delimited by whitespace. Compare: java SomeClass these are four arguments java SomeClass "this is one argument" EDIT: Originally I mentioned wrote that you had to escape the quotations within the string; just tested this, it's not the case. Example: java SomeClass "this is "still" one argument"

Categories : Java

Error in do.call(): unused arguments
Since you have xts objects , I guess you need something like : do.call(merge,args) This will create a single time series for the 4 symbols: tail(do.call(merge,args)) OpCl.x OpCl.x.1 OpCl.x.2 OpCl.x.3 2013-07-01 9.921627e-03 -0.0040837162 -0.0005574913 0.0006201166 2013-07-02 -1.063128e-02 0.0005122951 0.0008370536 0.0005585899 2013-07-03 3.314002e-04 0.0036082474 0.0076944600 0.0049850449 2013-07-05 8.468835e-05 0.0066023362 0.0019326339 0.0033852404 2013-07-08 3.526744e-03 0.0010025063 -0.0039758706 0.0005492494 2013-07-09 -1.820589e-03 0.0024888004 0.0015072623 0.0009092011

Categories : R

python subprocess.call arguments
It's telling you that bufsize must be an integer. I am going to guess that whatever value you set for preset in the script is not an integer (keep in mind that 0.0 is a float, not an integer). Do a quick check for what your argument is by printing it out in the function.

Categories : Python

Function pointers - pass arguments to a function pointer
Fix typedef to typedef void (*VFUNCV)(int , double ); as fun1 and fun2 accepts two argument of type int and double

Categories : C

getting string representation of function from a list having function name and arguments
If the function is defined as module global, you can use globals: func = globals()[list1[0]] func(list1[1]) But above code could cause any abitrary function to be called. If you don't want that, use following form. funcs = { 'dummyfunction': dummyfunction, } func = funcs[list1[0]] func(list1[1])

Categories : Python

passing arguments to a function in javascript but function not working
The reason that doesn't work is that createScript doesn't return a function, but you're expecting it to. The simplest way is just to do this: addLoadEvent(function() { createscript("https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"); }); addLoadEvent(function() { createScript("nav.js"); }); Note, though, that you're giving the same id value to each script tag created by createScript, which isn't valid. In an ES5-enabled environment, you could use Function#bind, but something about your question suggests to me you can't rely on being in an ES5-enabled environment. But for completeness: addLoadEvent(createscript.bind(undefined, "https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js")); addLoadEvent(createScript.bind(undefined, "nav.js")); Actually, no, th

Categories : Javascript

Passing processed ... arguments to plot() via do.call()
The problem are the axis labels. You are essentially doing something similar to plot(x=c(0.001111111, 0.501388889, 1.001388889, 1.501388889, 2.001388889, 2.501388889, 3.001388889, 3.501388889, 4.001388889, 0.501388889, 1.001388889, 1.501388889, 2.001388889, 2.501388889, 3.001388889, 3.501388889, 4.001388889, 0.501388889, 1.001388889, 1.501388889, 2.001388889, 2.501388889, 3.001388889, 3.501388889, 4.001388889, 0.501388889, 1.001388889, 1.501388889, 2.001388889, 2.501388889, 3.001388889, 3.501388889, 4.001388889, 0.501388889, 1.001388889, 1.501388889, 2.001388889, 2.501388889, 3.001388889, 3.501388889, 4.001388889, 0.501388889, 1.001388889, 1.501388889, 2.001388889, 2.501388889, 3.001388889, 3.501388889, 4.001388889, 0.501388889, 1.0013888

Categories : R

Subprocess call with arguments as variables python
PJust for reference. A really simple way to do something like this is simply defining the command beforehand and than transforming it into a list of arguments. command = "python npp.python -i {file} -o {file}.out -l {file}.log -e {excep} -i {ignore}".format(file=pipe.quote(fname), excep=exceptlist, ignore=ignorelist) subprocess.call(shlex.split(command)) # shlex.split is safer for shell commands than the usual split # or popen if the return code isn't needed subprocess.Popen(shlex.split(command)) This way it is harder to make mistakes when writing your command in list form.

Categories : Python

What is the purpose of type arguments in constructor call following new?
Constructors can declare type parameters too public class Main { public static class Foo<T> { public <E> Foo(T object, E object2) { } } public static void main(String[] args) throws Exception { Foo<Integer> foo = new <String> Foo<Integer>(1, "hello"); } } That's what the <String> preceding the constructor call is for. It is the type argument for the constructor. The following Foo<Integer> foo = new <String> Foo<Integer>(1, new Object()); fails with The parameterized constructor Foo(Integer, String) of type Main.Foo is not applicable for the arguments (Integer, Object) In your last Foo<Integer> t5 = new <NotDefined> Foo<Integer>(); // fails

Categories : Java



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.