Re:Show HN: Fully-featured Nil interpreter in less than 1 li...
by phpnode on Wednesday November 20, 2013 @09:03AM
(#6767982)
Sadly I couldn't get this down to less than one line, but here's how you can do this to implement a proper Nil interpreter
Function.prototype.apply = Function.prototype.call = function () {};
Insert this subtly somewhere into other people's code to ruin their day/week
Re:Show HN: Fully-featured Nil interpreter in less than 1 li...
by afandian on Wednesday November 20, 2013 @09:07AM
(#6768001)
The title is ambiguous but it's arguable that no JavaScript at all is "less than one line of JavaScript".
Re:Show HN: Fully-featured Nil interpreter in less than 1 li...
by shawnz on Wednesday November 20, 2013 @09:15AM
(#6768044)
> Now, if you could override Function.prototype to just function(){}
Function.prototype is already set to an empty function by default (evaluate Function.prototype() and you get 'undefined'), so I am not sure this has the consequences you think it does.
When you call a function object, let's say f, Javascript looks for an internal method on f called [[Call]] and calls it. If one doesn't exist, an error is thrown. The internal property [[Prototype]] of f is not ever considered, although you are right that it would be equal to Function.prototype.
EDIT: Despite what I think, executing phpnode's code in my node.js REPL instantly crashes it, so I guess there is more going on here.
Re:Show HN: Fully-featured Nil interpreter in less than 1 li...
by oso2k on Wednesday November 20, 2013 @07:33PM
(#6772322)
Node.js modifies globals is the issue and does other seriously interesting things[1].
[1] https://groups.google.com/forum/#!topic/nodejs/FuOB3151rPQ
Re:Show HN: Fully-featured Nil interpreter in less than 1 li...
by chrisdevereux on Wednesday November 20, 2013 @08:54AM
(#6767938)
It's a metacircular evaluator. Written in Nil, surely.
Re:Show HN: Fully-featured Nil interpreter in less than 1 li...
by TazeTSchnitzel on Wednesday November 20, 2013 @09:31AM
(#6768137)
Yes; any JavaScript program is also valid in Nil.
Now, if you could override Function.prototype to just function(){}, then everything passed in would be ignored and you'd have a proper Nil interpreter in JS. But you can't[1], because that would be stupid.
[1] Or rather, I can't. I did just spend a few minutes trying.