I'm getting an error "Did not check() all arguments". But I am checking all the arguments - very strange.
This Coffeescript code throws an error when you run the method:
Meteor.methods
doSomething : ( arg={} )->
check arg, Object
The problem turns out to be the argument default. The following code works:
Meteor.methods
doSomething : ( arg )->
check arg, Match.Maybe( Object )
arg ?= {}
This only seems to be a problem when you use empty object as an argument default. Other kinds of default argument seem to work - I tested null and list.
There's also a difference between calling:
Meteor.call "doSomething"
And calling this...
Meteor.call "doSomething", undefined
In the first case the argument is implicitly undefined, and will be set to a default. This bug does NOT happen.
In the second case we explicitly pass undefined (or null) and we get this bug. If you can avoid doing this, you won't need to change your arg defaults.
Related
I have an S3 class, and I'm trying to work out how to set up a print function for it.
This part's good.
print.webglobe <- function(wg, ...){
"it worked!"
}
But, if I run devtools::check() on it, I get the following ominous message:
checking S3 generic/method consistency ... WARNING
print:
function(x, ...)
print.webglobe:
function(wg, ...)
I tried adding the additional code:
print <- function(wg, ...){
UseMethod("webglobe", wg)
}
But, with this present, print.webglobe() never seems to be accessed and my S3 class just prints as a list of some sort.
How can I set up this up correctly?
Change the wg to x. The formal arguments of a method have to match those of the generic because arguments from the generic call are passed, based upon name, to the method. That's why the print() isn't working the way you would expect because wg is being sent to the wg rather than the method's first argument.
I am trying to create a function where the default argument is given by a variable that only exists in the environment temporarily, e.g.:
arg=1:10
test=function(x=arg[3]){2*x}
> test()
[1] 6
The above works fine, as long as arg exists in the function environment. However, if I remove arg:
> rm(arg)
> test()
> Error in test() : object 'arg' not found
Is there a way such that the default argument is taken as 3, even when arg ceases to exist? I have a feeling the correct answer involves some mixture of eval, quote and/or substitute, but I can't seem to find the correct incantation.
The proper way to do it in my opinion would be:
test <- function(x=3) { 2 *x }
and then call it with an argument:
arg<-1:10
test(arg[3])
This way the default value is 3, then you pass it the argument you wish at runtime, if you call it without argument test() it will use the default.
The post above got me on the right track. Using formals:
arg=1:10
test=function(x){x*2}
formals(test)$x=eval(arg[3])
rm(arg)
test()
[1] 6
And that is what I was looking to achieve.
I can call ^methods on an object and list the method names I can call:
my $object = 'Camelia';
my #object_methods = $object.^methods;
#object_methods.map( { .gist } ).sort.join("\n").say;
^methods returns a list which I store in #object_methods, then later I transform that list of method thingys by calling gist on each one to get the human-sensible form of that method thingy.
But, the ^ in ^methods is an implied .HOW, as show at the end of the object documentation this should work too:
my $object = 'Camelia';
my #object_methods = $object.HOW.methods;
But, I get an error:
Too few positionals passed; expected 2 arguments but got 1
in any methods at gen/moar/m-Metamodel.nqp line 490
in block <unit> at...
And, for what it's worth, this is an awful error message for a language that's trying to be person-friendly about that sort of thing. The file m-Metamodel.nqp isn't part of my perl6 installation. It's not even something I can google because, as the path suggests, it's something that a compilation generates. And, that compilation depends on the version.
A regular method call via . passes the invocant as implicit first argument to the method. A meta-method call via .^ passes two arguments: the meta-object as invocant, and the instance as first positional argument.
For example
$obj.^can('sqrt')
is syntactic sugar for
$obj.HOW.can($obj, 'sqrt')
In your example, this would read
my #object_methods = $object.HOW.methods($object);
I'm trying to get the scan function to work, but it seems i'm missing something: According to the documention this should work:
var iter = new ydn.db.KeyIterator('contact');
db.scan([iter], function(keys, values)
But every time i call the function i get the following error:
Uncaught ydn.error.ArgumentException: Iterator argument must be an array.
A contact sore with the name 'contact' exists and i tried different libraries ydb-db but none of them worked.
Documentation is outdated. It should be:
db.scan(function(keys, values), [iter]
See unit test for it use case.
While working i met this annoying message
Strict Standards: Only variables should be passed by reference in G:\xampp\htdocs\MyProject\ZendSkeletonApplication\module\Admission\src\Admission\Controller\AdmissionController.php on line 107
My code
$consoldatedCities='';
array_walk_recursive($StateCityHash, function($cityName,$cityId) use(&$consoldatedCities){$consoldatedCities[$cityId] = $cityName; }); // line 107
This is to convert multidimensional array into simple array
But the code works as i expected.. can anyone tell me how to solve this problem
Here http://php.net/manual/en/language.references.pass.php it says that "There is no reference sign on a function call - only on function definitions." Try removing the '&' from your function call code there and see if that gets rid of the message.
---Edit---
Looking at this thread here "Strict Standards: Only variables should be passed by reference" error
you could try saving your callback function into a variable before passing it to the array walk function:
$consoldatedCities=array();
$callbackFcn=
function($cityName,$cityId) use(&$consoldatedCities)
{
$consoldatedCities[$cityId] = $cityName;
};
array_walk_recursive($StateCityHash, $callbackFcn);