Skip to content

Commit

Permalink
a function invocation followed by a predicate in a lambda is NOT a ta…
Browse files Browse the repository at this point in the history
…il-call (#149)
  • Loading branch information
andrew-coleman authored Feb 15, 2018
1 parent ee0d8b1 commit 247e94d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jsonata.js
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ var jsonata = (function() {
// This enables tail-recursive functions to be written without growing the stack
var tail_call_optimize = function(expr) {
var result;
if(expr.type === 'function') {
if(expr.type === 'function' && !expr.predicate) {
var thunk = {type: 'lambda', thunk: true, arguments: [], position: expr.position};
thunk.body = expr;
result = thunk;
Expand Down
6 changes: 6 additions & 0 deletions test/test-suite/groups/lambdas/case012.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"expr": "( $median := λ($x){$sort($x)[$count($x)/2]}; $median([5,4,3,2,1,6,7,8,1]) )",
"dataset": null,
"bindings": {},
"result": 4
}

0 comments on commit 247e94d

Please sign in to comment.