Hacker News new | past | comments | ask | show | jobs | submit login

Author here: doing this in any language is probably going to depend on some implementation details of the language repl, which may require dropping down to a level where you have access to these internals - for example, I can't think of a way you could achieve it in strict mode JS.

Python may well be able to do it with just the stdlib since it has excellent debugging capabilities, but Tcl is relatively weak. You might be able to do something with `tcl::unsupported::getbytecode` and checking the frame level, but this was just a throw-away novelty so I'm not particularly motivated to find out.




Alas, for JS function.caller on a getter isn't standard but will work everywhere and should do it.


I don't think it's that easy. If the context is making javascript output something different in it's REPL for just "foo" vs "console.log(foo)", there's other pieces you would need.

Like overriding a built-in type and getting function.caller into valueOf(). As far as I can tell, JS doesn't let you just tweak valueOf(), you would have to re-implement all of, for example, the String class.


Reimplementing whole classes wouldn't have been a problem, just replace the original ones with a proxy to a copy.

Luckily console.log calls are actually excluded from the callers stack, so the only way is to change console itself. Just as evil if you also intercept console methods logging and return the original ones, but less of a mess at least.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: