Skip to content

Commit

Permalink
When making a lambda, remove named arguments from the scope before su…
Browse files Browse the repository at this point in the history
…bstituting
  • Loading branch information
christianp committed Dec 3, 2024
1 parent 714e33f commit 2e1caec
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions runtime/scripts/jme.js
Original file line number Diff line number Diff line change
Expand Up @@ -2689,7 +2689,12 @@ Scope.prototype = /** @lends Numbas.jme.Scope.prototype */ {
} else {
var nlambda = new types.TLambda();
nlambda.names = tok.names;
nlambda.set_expr(jme.substituteTree(tok.expr, scope, true, false));
nlambda.make_signature();
var nscope = new Numbas.jme.Scope([scope]);
nlambda.all_names.forEach(function(name) {
nscope.deleteVariable(name);
});
nlambda.set_expr(jme.substituteTree(tok.expr, nscope, true, false));
return nlambda;
}

Expand Down Expand Up @@ -3613,13 +3618,7 @@ TLambda.prototype = {
this.names = names;
},

/** Set the body of this function. The argument names must already have been set.
*
* @param {Numbas.jme.tree} expr
*/
set_expr: function(expr) {
const lambda = this;
this.expr = expr;
make_signature: function(expr) {
var all_names = [];

/** Make the signature for the given argument.
Expand All @@ -3644,6 +3643,19 @@ TLambda.prototype = {

this.all_names = all_names;

return signature;
},

/** Set the body of this function. The argument names must already have been set.
*
* @param {Numbas.jme.tree} expr
*/
set_expr: function(expr) {
const lambda = this;
this.expr = expr;

const signature = this.make_signature();

this.fn = new jme.funcObj('', signature, '?', null, {
evaluate: function(args, scope) {
var nscope = new jme.Scope([scope]);
Expand Down

0 comments on commit 2e1caec

Please sign in to comment.