arrow operator, no big deal!
Thursday, 11 September 2014 · 4 messages
RS
Rob Stapper11 Sep 2014 15:25 #
Hi,
I was playing with the arrow-operator and found that it doesn't work on anonymous functions, see example.
('A', 'B', 'C') => function( $sequence) { count( $sequence)}
No idea why you should use a construction like this but I, kind of, expected it to work.
Maybe something for a next release( together with the "apply-function";-).
Regards,
Rob Stapper
---
Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirus-bescherming actief is. http://www.avast.com
CG
Christian Grün11 Sep 2014 15:57 #
The following expression should work (you need to add parentheses around and after the anonymous function):
('A', 'B', 'C') => (function( $sequence) { count( $sequence)})()
Quoted text · Rob Stapper · 37 lines
On Thu, Sep 11, 2014 at 3:25 PM, Rob Stapper <r.stapper at lijbrandt.nl> wrote: > Hi, > > > > I was playing with the arrow-operator and found that it doesn't work on > anonymous functions, see example. > > > > ('A', 'B', 'C') => function( $sequence) { count( $sequence)} > > > > No idea why you should use a construction like this but I, kind of, > expected it to work. > > > > Maybe something for a next release( together with the "apply-function";-). > > > > Regards, > > > > Rob Stapper > > > ------------------------------ > <http://www.avast.com/> > > Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirus > <http://www.avast.com/> actief is. > >
MG
Hi Rob,
Well, it's a very nice operator when you start connecting various functions together to form a kind of pipeline.
As the 3.1 draft example shows:
tokenize((normalize-unicode(upper-case($string))),"\s+")
or,
$string=>upper-case()=>normalize-unicode()=>tokenize("\s+")Which reads better (inside to outside or sequential)? I think the latter. The required ()s even are kind of mnemonic for pipelines (if you squint a little).
"foo" ===>()===()===()===> "FOO"
--Marc
Quoted text · Rob Stapper · 37 lines
On Thu, Sep 11, 2014 at 3:25 PM, Rob Stapper <r.stapper at lijbrandt.nl> wrote: > Hi, > > > > I was playing with the arrow-operator and found that it doesn’t work on > anonymous functions, see example. > > > > ('A', 'B', 'C') => function( $sequence) { count( $sequence)} > > > > No idea why you should use a construction like this but I, kind of, > expected it to work. > > > > Maybe something for a next release( together with the “apply-function”;-). > > > > Regards, > > > > Rob Stapper > > > ------------------------------ > <http://www.avast.com/> > > Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirus > <http://www.avast.com/> actief is. > >
--
--Marc
MG
Marc van Grootel11 Sep 2014 16:58 #
... upon re-reading my comment that was probably not the construction you were wondering about. I was surprised by the extra level of parentheses as well.
Quoted text · Marc van Grootel · 70 lines
On Thu, Sep 11, 2014 at 4:45 PM, Marc van Grootel < marc.van.grootel at gmail.com> wrote: > Hi Rob, > > Well, it's a very nice operator when you start connecting various > functions together to form a kind of pipeline. > > As the 3.1 draft example shows: > > tokenize((normalize-unicode(upper-case($string))),"\s+") > > > or, > > $string=>upper-case()=>normalize-unicode()=>tokenize("\s+") > > > Which reads better (inside to outside or sequential)? I think the latter. > The required ()s even are kind of mnemonic for pipelines (if you squint a > little). > > "foo" ===>()===()===()===> "FOO" > > > --Marc > > On Thu, Sep 11, 2014 at 3:25 PM, Rob Stapper <r.stapper at lijbrandt.nl> > wrote: > >> Hi, >> >> >> >> I was playing with the arrow-operator and found that it doesn’t work on >> anonymous functions, see example. >> >> >> >> ('A', 'B', 'C') => function( $sequence) { count( $sequence)} >> >> >> >> No idea why you should use a construction like this but I, kind of, >> expected it to work. >> >> >> >> Maybe something for a next release( together with the “apply-function”;-). >> >> >> >> Regards, >> >> >> >> Rob Stapper >> >> >> ------------------------------ >> <http://www.avast.com/> >> >> Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirus >> <http://www.avast.com/> actief is. >> >> > > > -- > --Marc >
--
--Marc
Written for BaseX 7.9. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery