Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: Fully-featured Nil interpreter in less than 1 line of JavaScript (ajf.me)
115 points by TazeTSchnitzel on Nov 20, 2013 | hide | past | favorite | 29 comments


I would debate whether or not this is actually Javascript. For something to be JS, surely it needs to actually call the JS interpreter when it's run. This doesn't. So it isn't.

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.


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


The title is ambiguous but it's arguable that no JavaScript at all is "less than one line of JavaScript".


> 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.


Node.js modifies globals is the issue and does other seriously interesting things[1].

[1] https://groups.google.com/forum/#!topic/nodejs/FuOB3151rPQ


It's a metacircular evaluator. Written in Nil, surely.


Yes; any JavaScript program is also valid in Nil.


a form with onsubmit="" technically executes a zero length javascript program.

Is an empty string less than one line of code? Or is it one line of zero length?


Technically, javascript already has built-in a Nil interpreter: the void keyword


Example program ("hello, world" is not traditional in the Nil community):

  I wandered lonely as a cloud.
Outputs:


It was only a matter of time before someone came up with a parody for the X lines of JavaScript posts. Nicely done though.


There was also a story yesterday titled "Hello World in 1 line of Javascript" (which I think is now dead).


Just one suggestion.I think it would improve the usability if you put the run button below the program source.

Otherwise wonderful work. I think it would be difficult to top this.


I've considered doing JIT compilation to JavaScript and adding IntelliSense, but that'd require another 0 lines of code and I'm worried it might ruin the beautiful simplicty of it.


If you're going to take cheap shots at RMS at least make them accurate. You may not agree with his reasons, but they have nothing to do with sin.


True, but he seems to have a moral conviction that proprietary software is wrong, and hence doesn't like JS much as it is a vector for automatically download and executing proprietary software. So I was exaggerating, but there is some truth to my words.


Hahaha, well done. I originally expected some word-wrapped 10,000 char thing on a single line.


So this is the All Consuming Void the Compilers warned their creators about?


Ha I wanted to shout "plagiarism" because I remember seeing it here already, but it was you who posted it yesterday:

https://news.ycombinator.com/item?id=6759980

Still not very classy, is it?


But it is interesting that the title change resulted in it making it to the front page.


Nah, I think the fact you can easily try it in your browser and the additional explanation helped it. ;)

The submitted page actually well predates this "30 lines" fad, I just realised it might be an effective parody today. The joke works better in HTML form, as it takes longer to see it.


Finally! Someone had to do this.


I fully endorse this, these posts were getting a bit ridiculous.


it failed without throwing a NilPointer exception, how can we debug it?


False, there is no JS present at all.

(should be an empty file)


"no JS present" = "less than 1 line of JavaScript"

No?


You've got a point. It was a joke though.


Easily fixed:

    <script type="text/javascript"></script>


Or maybe this:

    <script type="text/javascript"/>
Not quite valid HTML, but it's semantically very valid indeed.




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

Search: