Skip to content

Commit

Permalink
withMutProperties return the body's value
Browse files Browse the repository at this point in the history
  • Loading branch information
NQNStudios committed Aug 27, 2023
1 parent 41c58fe commit 8843ac5
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/kiss/Macros.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1446,9 +1446,22 @@ class Macros {
}];

var body = exps.slice(1);
b.let(Lambda.flatten(Prelude.zipThrow(uuids, savedVarList)), [
b.let(Lambda.flatten(Prelude.zipThrow(savedVarList, uuids)), body),
].concat([for (savedVar in savedVarList) b.set(savedVar, uuids.shift())]));
var resultSymbol = b.symbol();
b.begin([
// Create a variable to hold the return value of the body
b.callSymbol("localVar", [b.meta("mut", resultSymbol), b.symbol("null")]),
// Retrieve all the desired properties in gensym variables
b.let(Lambda.flatten(Prelude.zipThrow(uuids, savedVarList)), [
// Bind the gensym values BACK into their real names
b.let(Lambda.flatten(Prelude.zipThrow(savedVarList, uuids)), [
// Evaluate the body and save its result
b.set(resultSymbol, b.begin(body))
]),
// Save out the ending values of the properties
].concat([for (savedVar in savedVarList) b.set(savedVar, uuids.shift())])),
// Return the result of the body
resultSymbol
]);
};

k.doc("withFunctions", 2, null, "(withFunctions [(<funcName1> [<args...>] <body...>) <more functions...>] <body...>)");
Expand Down

0 comments on commit 8843ac5

Please sign in to comment.