anonymous-function

Why does this wildcarded function tells me it has the wrong number of parameters?

孤街浪徒 提交于 2019-12-01 12:35:22
The offending code was: <console>:47: error: wrong number of parameters; expected = 2 terms.foldLeft(r.unitA)(r.add(_, _.eval(x))) I solved my problem by writing: terms.foldLeft(r.unitA)((a,b) => r.add(a, b.eval(x))) But I'd still like to know what prevented my initial attempt? Here is the section of the SLS 6.23: http://iainmcgin.github.io/scala-ref-markdown/#placeholder-syntax-for-anonymous-functions Updated link: http://www.scala-lang.org/files/archive/spec/2.11/06-expressions.html#placeholder-syntax-for-anonymous-functions Daniel Sobral's post says: "When you use "_" as a place holder for

Is there any way to call XSLT templates inline

笑着哭i 提交于 2019-12-01 09:24:05
How to call XSLT templates inline? For instance, instead of : <xsl:call-template name="myTemplate" > <xsl:with-param name="param1" select="'val'" /> </xsl:call-template> Can I use XSLT built-in function-call style, like this: <xls:value-of select="myTeplate(param1)" /> In XSLT 2.0 you can define your own custom functions using xsl:function An article on XML.com describing how to write your own functions in XSLT 2.0: http://www.xml.com/pub/a/2003/09/03/trxml.html <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:foo="http://whatever"> <!-- Compare two strings

Accessing private/protected properties of an object in anonymous function in PHP

青春壹個敷衍的年華 提交于 2019-12-01 06:05:13
I'm trying to dump elements of an object's private property through an anonymous function - of course I could achieve this in any number of other ways, but this highlights a PHP conundrum I can't solve off the top of my head, short of $foo = $this and using $foo - but THAT won't give me the private stuff, so... suggestions ? Sample code: class MyClass { private $payload = Array( 'a' => 'A element', 'b' => 'B element'); static $csvOrder = Array('b','a'); public function toCSV(){ $values = array_map( function($name) use ($this) { return $this->payload[$name]; }, self::$csvOrder ); return implode

Is there any way to call XSLT templates inline

こ雲淡風輕ζ 提交于 2019-12-01 05:36:03
问题 How to call XSLT templates inline? For instance, instead of : <xsl:call-template name="myTemplate" > <xsl:with-param name="param1" select="'val'" /> </xsl:call-template> Can I use XSLT built-in function-call style, like this: <xls:value-of select="myTeplate(param1)" /> 回答1: In XSLT 2.0 you can define your own custom functions using xsl:function An article on XML.com describing how to write your own functions in XSLT 2.0: http://www.xml.com/pub/a/2003/09/03/trxml.html <xsl:stylesheet version=

How do I convert an anonymous function to a symbolic function in MATLAB?

与世无争的帅哥 提交于 2019-12-01 04:05:06
Say I have a anonymous function f = @(x) x^2 and I want to convert this to a symbolic function. Is there a built in command for that? You could just pass it to SYM: f = @(x) x^2; g = sym(f) But then most of the symbolic functions do that automatically when they receive a function handle ( subs , int , etc...) 来源: https://stackoverflow.com/questions/11322295/how-do-i-convert-an-anonymous-function-to-a-symbolic-function-in-matlab

PHP: function arguments' names

你。 提交于 2019-12-01 03:06:02
问题 I need to get anonymous function arguments' names. E.g.: $func = function ( $param1, $param2 ) { ... }; $names = DO_SOMETHING($func); // after this $names should become something like array('param1', param2') Theoretically, it is possible because var_dump($func) says that $func is the object of Closure class and have parameter property which is array('param1', 'param2') . Official documentation at php.net describes no methods of Closure class, which can help me. I've tried to access this

Func / Action delegates with reference arguments/parameters or anonymous functions

我与影子孤独终老i 提交于 2019-12-01 01:47:39
问题 I just wondered, how the exact syntax is for ref and out parameters for delegates and inline lambda functions. here is an example if a function is defined as public void DoSomething(int withValue) { } a delegate in a function can be created by public void f() { Action<int> f2 = DoSomething; f2(3); } how is that syntax, if the original function would be defined as public void DoSomething(ref int withValue) { withValue = 3; } 回答1: You need to define a new delegate type for this method signature

Javascript 'this' overwriting in Z combinator and every other recursive function

£可爱£侵袭症+ 提交于 2019-12-01 01:42:38
Background: I have a recursive function implemented by a Z-combinator as is shown here and here so it makes no use of arguments.callee since it will be deprecated in upcoming ES6 . Issue The main issue with the Z-combinator and all recursive anonymous functions I've seen so far is that they updates de this value to the inner function scope (the self-returned at the return clause), so the this that references the top level is lost, and I want to maintain it through all the inner functions. Is there a way to maintain the top level this without passing it as an additional function argument, which

How do I convert an anonymous function to a symbolic function in MATLAB?

依然范特西╮ 提交于 2019-12-01 00:57:52
问题 Say I have a anonymous function f = @(x) x^2 and I want to convert this to a symbolic function. Is there a built in command for that? 回答1: You could just pass it to SYM: f = @(x) x^2; g = sym(f) But then most of the symbolic functions do that automatically when they receive a function handle ( subs , int , etc...) 来源: https://stackoverflow.com/questions/11322295/how-do-i-convert-an-anonymous-function-to-a-symbolic-function-in-matlab

Automatically call hash values that are subroutine references

风格不统一 提交于 2019-11-30 22:04:13
I have a hash with a few values that are not scalar data but rather anonymous subroutines that return scalar data. I want to make this completely transparent to the part of the code that looks up values in the hash, so that it doesn't have to be aware that some of the hash values may be anonymous subroutines that return scalar data rather than just plain old scalar data. To that effect, is there any way to have the anonymous subroutines executed when their keys are accessed, without using any special syntax? Here's a simplified example that illustrates the goal and the problem: #!/usr/bin/perl