News for hackers. Stuff that matters.
Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by onion2k on Wednesday November 20, 2013 @08:46AM (#6767892)
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.

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.
Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by ithkuil on Wednesday November 20, 2013 @11:11AM (#6768847)
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?

Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by lhorie on Wednesday November 20, 2013 @10:43AM (#6768637)
Technically, javascript already has built-in a Nil interpreter: the void keyword
Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by TazeTSchnitzel on Wednesday November 20, 2013 @07:55AM (#6767696)
Example program ("hello, world" is not traditional in the Nil community):

  I wandered lonely as a cloud.
Outputs:
Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by joelennon on Wednesday November 20, 2013 @08:19AM (#6767768)
It was only a matter of time before someone came up with a parody for the X lines of JavaScript posts. Nicely done though.
Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by probably_wrong on Wednesday November 20, 2013 @08:33AM (#6767830)
There was also a story yesterday titled "Hello World in 1 line of Javascript" (which I think is now dead).
Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by brickcap on Wednesday November 20, 2013 @08:39AM (#6767858)
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.

Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by TazeTSchnitzel on Wednesday November 20, 2013 @09:27AM (#6768111)
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.
Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by bct on Wednesday November 20, 2013 @10:32AM (#6768557)
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.
Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by TazeTSchnitzel on Wednesday November 20, 2013 @01:16PM (#6769817)
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.
Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by RankingMember on Wednesday November 20, 2013 @08:37AM (#6767847)
Hahaha, well done. I originally expected some word-wrapped 10,000 char thing on a single line.
Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by gprasanth on Wednesday November 20, 2013 @08:12AM (#6767746)
So this is the All Consuming Void the Compilers warned their creators about?
Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by yread on Wednesday November 20, 2013 @08:50AM (#6767908)
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?

Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by davidjhamp on Wednesday November 20, 2013 @09:03AM (#6767984)
But it is interesting that the title change resulted in it making it to the front page.
Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by TazeTSchnitzel on Wednesday November 20, 2013 @09:44AM (#6768244)
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.

Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by venticco on Wednesday November 20, 2013 @08:19AM (#6767767)
Finally! Someone had to do this.
Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by basyt on Wednesday November 20, 2013 @09:27AM (#6768113)
I fully endorse this, these posts were getting a bit ridiculous.
Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by singularity2001 on Wednesday November 20, 2013 @09:50AM (#6768281)
it failed without throwing a NilPointer exception, how can we debug it?
Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by gishse on Wednesday November 20, 2013 @08:35AM (#6767841)
False, there is no JS present at all.

(should be an empty file)

Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by nervousvarun on Wednesday November 20, 2013 @08:39AM (#6767856)
"no JS present" = "less than 1 line of JavaScript"

No?

Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by gishse on Wednesday November 20, 2013 @09:11AM (#6768024)
You've got a point. It was a joke though.
Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by kijin on Wednesday November 20, 2013 @08:42AM (#6767865)
Easily fixed:

    <script type="text/javascript"></script>
Re:Show HN: Fully-featured Nil interpreter in less than 1 li... by Pitarou on Wednesday November 20, 2013 @09:12AM (#6768030)
Or maybe this:

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