Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add last evaluate result at _ variable in relp #135

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion runner/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ const memoryToString = mem => {
};

let prev = '';

function setLastEvalExp(prev, ret) {
const lastEvalExp = `let _ = ${ret != null ? ret : "undefined"};\n`;
yazaldefilimone marked this conversation as resolved.
Show resolved Hide resolved
if (/let _ = .*;\n/.test(prev)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this break after subsequent runs? If we're going with this approach it should be var not let.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t understand what you are saying.

are you referring to redeclaring the let statement? In this case, we only declare it once for each sequence (just change a assign expression)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you just do _ = instead of having to deal with let/var and check every time/etc?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, makes sense i’ve made the change...

return prev.replace(/let _ = .*;\n/, lastEvalExp);
}
return lastEvalExp + prev;
}

const run = (source, _context, _filename, callback, run = true) => {
// hack: print "secret" before latest code ran to only enable printing for new code

Expand Down Expand Up @@ -110,7 +119,7 @@ const run = (source, _context, _filename, callback, run = true) => {

// callback(null, ret);

prev = prev + ';\n' + source.trim();
prev = setLastEvalExp( prev + ';\n' + source.trim(), ret);

callback();
};
Expand Down