4 ms·
Show HN: Fully-featured Nil interpreter in less than 1 line of JavaScript
- TazeTSchnitzel 13y agoExample program ("hello, world" is not traditional in the Nil community): I wandered lonely as a cloud. Outputs:
- gprasanth 13y agoSo this is the All Consuming Void the Compilers warned their creators about?
- venticco 13y agoFinally! Someone had to do this.
- joelennon 13y agoIt was only a matter of time before someone came up with a parody for the X lines of JavaScript posts. Nicely done though.
- probably_wrong 13y agoThere was also a story yesterday titled "Hello World in 1 line of Javascript" (which I think is now dead).
- guojh0570 13y agoThat script was quite easy.
- gishse 13y agoFalse, there is no JS present at all. (should be an empty file)
- nervousvarun 13y ago"no JS present" = "less than 1 line of JavaScript" No?
- deleted 13y ago[deleted]
- gishse 13y agoYou've got a point. It was a joke though.
- kijin 13y agoEasily fixed: <script type="text/javascript"></script>
- Pitarou 13y agoOr maybe this: <script type="text/javascript"/> Not quite valid HTML, but it's semantically very valid indeed.
- RankingMember 13y agoHahaha, well done. I originally expected some word-wrapped 10,000 char thing on a single line.
- brickcap 13y agoJust 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.
- TazeTSchnitzel 13y agoI'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.
- onion2k 13y agoI 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.
- ithkuil 13y agoa 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?
- chrisdevereux 13y agoIt's a metacircular evaluator. Written in Nil, surely.
- TazeTSchnitzel 13y agoYes; any JavaScript program is also valid in Nil.
- phpnode 13y agoSadly 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
- afandian 13y agoThe title is ambiguous but it's arguable that no JavaScript at all is "less than one line of JavaScript".
- shawnz 13y ago> 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.
- yread 13y agoHa 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 https://news.ycombinator.com/item?id=6759980 Still not very classy, is it?
- davidjhamp 13y agoBut it is interesting that the title change resulted in it making it to the front page.
- TazeTSchnitzel 13y agoNah, 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.
- deleted 13y ago[deleted]
- basyt 13y agoI fully endorse this, these posts were getting a bit ridiculous.
- singularity2001 13y agoit failed without throwing a NilPointer exception, how can we debug it?
- bct 13y agoIf 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.
- TazeTSchnitzel 13y agoTrue, 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.