Skip to content

Commit

Permalink
findvars on lambda: don't include boundvars
Browse files Browse the repository at this point in the history
  • Loading branch information
christianp committed Dec 3, 2024
1 parent d017e81 commit 2dd1a1d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions runtime/scripts/jme.js
Original file line number Diff line number Diff line change
Expand Up @@ -4303,8 +4303,11 @@ var findvars = jme.findvars = function(tree,boundvars,scope) {
}
} else {
var argvars = jme.findvars_args(tree.args, boundvars, scope);
if(tree.tok.type == 'function' && scope.getFunction(tree.tok.name).length == 0) {
argvars.push(tree.tok.name);
if(tree.tok.type == 'function') {
const fn_name = jme.normaliseName(tree.tok.name, scope);
if(boundvars.indexOf(fn_name)==-1 && scope.getFunction(fn_name).length == 0) {
argvars.push(fn_name);
}
}
return argvars;
}
Expand Down
1 change: 1 addition & 0 deletions tests/jme/jme-tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Numbas.queueScript('jme_tests',['qunit','jme','jme-rules','jme-display','jme-cal
deepCloseEqual(assert, Numbas.jme.findvars(Numbas.jme.compile('let(["x":z],x+y)')),['y','z'],'findvars on let with a dictionary');
deepCloseEqual(assert, Numbas.jme.findvars(Numbas.jme.compile('let([q,w],[2,3],x,z,x+y+q+w)')),['y','z'],'findvars on let with a sequence of names');
deepCloseEqual(assert, Numbas.jme.findvars(Numbas.jme.compile('x -> x+z')),['z'],'findvars on lambda');
deepCloseEqual(assert, Numbas.jme.findvars(Numbas.jme.compile('a -> a(x)')),['x'],'findvars on lambda where an argument is another lambda');
deepCloseEqual(assert, Numbas.jme.findvars(Numbas.jme.compile('[x,[y,z]] -> x+y+z+w')),['w'],'findvars on lambda with destructuring');
deepCloseEqual(assert, Numbas.jme.findvars(Numbas.jme.compile('undefined_function(x)')),['x', 'undefined_function'],'Undefined function names are presumed to be missing variables.');
});
Expand Down

0 comments on commit 2dd1a1d

Please sign in to comment.