Project

Profile

Help

fold-left on sequences of maps?

Added by Martin Honnen over 3 years ago

When I run

require('saxon-js');

var result = SaxonJS.XPath.evaluate(`
  fold-left(
    (map { 'a' : 1, 'b' : 2}, map { 'a' : 3, 'b' : 4 }, map { 'a' : 1, 'b' : 2} ),
    (), 
    function($distinct-maps, $new-map) {
      if (some $map in $distinct-maps satisfies deep-equal($map, $new-map))
      then $distinct-maps
      else ($distinct-maps, $new-map)
    }
  )
`);

console.log(result);

with Saxon-JS 2 and node on Windows I get the error

C:\Users\marti\SomeDir\node_modules\saxon-js\SaxonJS2N.js:218
{};b.currentTemplate=null;b.focus=null;b.localVars=this.closureContext.localVars.slice();b.currentComponent=this.closureContext.currentComponent;c=this.declaredArgs;for(var d=0;d<a.length;d++){var f=parseInt(c[d].slot,10);b.localVars[f]=a[d]}return Expr$$module$temp$js$source$src$Expr.evaluate(this.body,b)};var f=function(b,c,d){b=a.call(this,b,b.alphaTree.a.length)||this;b.baseFunction=c;b.fixedValues=d;return b};$jscomp.inherits(f,a);f.prototype.identify=function(){return"partially-applied "+this.baseFunction.identify()};
                                                                                 ^

TypeError: this.closureContext.localVars.slice is not a function
    at n.evaluate (C:\Users\marti\SomeDir\node_modules\saxon-js\SaxonJS2N.js:218:82)
    at u.evaluate (C:\Users\SomeDir\node_modules\saxon-js\SaxonJS2N.js:220:66)
    at C:\Users\marti\SomeDir\node_modules\saxon-js\SaxonJS2N.js:547:123
    at Array.forEach (<anonymous>)
    ...

In the browser I get a similar error

Uncaught TypeError: this.fl.Ha.slice is not a function
    at d.evaluate (SaxonJS2.rt.js:283)
    at a.evaluate (SaxonJS2.rt.js:284)
    at SaxonJS2.rt.js:508
    at Array.forEach (<anonymous>)
    at t (SaxonJS2.rt.js:508)
    at fold-left (SaxonJS2.rt.js:525)
    at SaxonJS2.rt.js:632
    at Object.a [as evaluate] (SaxonJS2.rt.js:591)
    at Object.evaluate (SaxonJS2.rt.js:789)
    at <anonymous>:1:15

Replies (3)

Please register to reply

RE: fold-left on sequences of maps? - Added by Martin Honnen over 3 years ago

The problem seem to occur with number sequences as well:

SaxonJS.XPath.evaluate(`  fold-left(
    1 to 10,
    0,
    function($sum, $number) {
      $sum + $number
    }
  )`)

RE: fold-left on sequences of maps? - Added by Debbie Lockett over 3 years ago

Sorry for the delay in responding, and thanks for letting us know. We will investigate.

RE: fold-left on sequences of maps? - Added by Debbie Lockett over 3 years ago

I've reproduced the issue running Saxon-JS 2.0. Actually, running against a current Saxon-JS 2 branch development build, we don't get an error, so it looks like some other development work has already fixed the problem. But to properly investigate and log the issue, I've opened a bug (see bug #4653).

    (1-3/3)

    Please register to reply