Starting with eXist version 3.4.0 inline functions within maps will not inherit variables declared outside its function body. The problem has been discussed on eXist-open and was confirmed by @joewiz by testing against Saxon and BaseX.
I expected all three tests to pass without errors (as they do in eXist version 3.3.0).
xquery version "3.1";
module namespace ct="http://exist-db.org/xquery/closures/test";
declare variable $ct:model := function($param) {
let $func := function() {
$param
}
return
map {
'test1' : $func,
'test2' : $func(),
'test3' : function() {
$param
}
}
};
declare %test:assertEquals('Hello World') function ct:test1-function-reference() as xs:string {
try {
$ct:model('Hello World')?test1()
}
catch * {$err:code || ' ' || $err:description}
};
declare %test:assertEquals('Hello World') function ct:test2-function-call() as xs:string {
try {
$ct:model('Hello World')?test2
}
catch * {$err:code || ' ' || $err:description}
};
declare %test:assertEquals('Hello World') function ct:test3-inline-function() as xs:string {
try {
$ct:model('Hello World')?test3()
}
catch * {$err:code || ' ' || $err:description}
};
Reviewing the details in this issue again, I notice the URL to the HoF article that Peter referenced in his exist-open post unfortunately isn’t working: http://atomic.exist-db.org/blogs/eXist/HoF...
HTTP ERROR 404
Problem accessing /exist/blogs/eXist/HoF. Reason:
Not Found
The URL http://atomic.exist-db.org/blogs/eXist/HoF does work for me … maybe just a temporary server error?
There were temporary hiccups with some pages on the server yesterday, which I fixed in the meantime.
It's best to point to http://exist-db.org/exist/apps/wiki/blogs/eXist/HoF though since http://atomic.exist-db.org is an old redirect.
While I congratulate to the 4.0 release I tentatively want to remind you of this issue. It's something that keeps me from upgrading so I'm currently stuck with version 3.3.0.
Many thanks in advance!
I had a look into this issue before 4.0 and I see where the problem is, but it's not straightforward to fix without potentially causing other regressions, so I did not want to risk it for the release.
Thanks for the reply! I was just trying to make sure it wont be forgotten ;)
Help! This is really an issue for me that prevents me from upgrading to a recent eXist version. Is a fix anywhere on the roadmap or do I have to refactor my code?
Assigning high prio for myself.
Sorry for bothering, but is there any chance this will be tackled in the near future?
not directly related, but because namespace prefixes can appear in maps, the preferred and specs compliant map syntax is
return
map {
'test1': $func,
'test2': $func(),
'test3': function() {
$param
}
}
only one ws after : in { key: value }
@peterstadler I think you will have to ask @wolfgangmm
@duncdrum shall I create a PR for the tests?
Most helpful comment
Assigning high prio for myself.