ux-wise, you can achieve the same with a helper-function debugInline
(used in this real-world example);
inline-debugging becomes trivial as follows:
#!/bin/sh
node -e '
// this inline-debugger can be safely copy-pasted into any script
// init debugInline
if (!globalThis.debugInline) {
let consoleError;
consoleError = console.error;
globalThis.debugInline = function (...argList) {
/*
* this function will both print <argList> to stderr and
* return <argList>[0]
*/
consoleError("\n\ndebugInline");
consoleError(...argList);
consoleError("\n");
return argList[0];
};
}
function randInt(min, max) {
// return Math.floor(
// min +
// Math.random() * (max - min)
// );
return Math.floor(
debugInline( min, "min" ) +
debugInline( Math.random() * (max - min), "random*scale ")
);
}
randInt(0, 10);
'
# stderr:
#
#
# debugInline
# 0 min
#
#
#
#
# debugInline
# 0.9995644826073868 random*scale
#
#