Hacker News new | past | comments | ask | show | jobs | submit | more mcwhittemore's comments login

If Torbjörn Söderstedt would like to explain how chicken.js works - there is now an open stackoverflow question: http://stackoverflow.com/questions/17414435/how-does-chicken...


There are four statements: 1. Initialization 2. Read next character or bytecode 3. Conditional, first leg is parsing and second intepretation. 4. Return

When parsing, the function will call itself recursively as chicken(linenumber, 0). When interpreting, it calls itself as chicken(undefined, undefined). With the second parameter 0 or undefined, the initialization code will not run again. With the first parameter undefined, it will run the interpreter instead of the parser. (It is important that the line number is non-zero.)

This is where the implementation gets a bit ugly. There's no way of preventing the interpreter from running. That means the error message must form valid bytecode. It does this by setting the stack pointer to -1 and returning an array of length two. The interpretation starts at index 2, which will be read as undefined and thus interpreted as the axe instruction (halting the program). sp will have been increased to 0 by the initialization and thus points to the error message at index 0 in the array, which will be returned as the result. (The second value in the array is unused, and was only inserted to avoid using a parenthesis.)

That should hopefully clear up the big picture. Some small notes:

Comparing input and code during initialization should always be false. When negated, it produces the value 0.

The value after && that follows the comparison with "n" is always true. It was just a way to avoid a parenthesis.

CHICKEN ++- CHICKEN produces -1. The side effect isn't used.


seems stackoverflow though this question was too fowl for them and asked me to push it over to codereview -> http://codereview.stackexchange.com/questions/28015/how-does...


Been using preamp for a few days now and I'd discovered a handful of new bands. Great tool.


Recently I had to turn a bunch of notes I'd taken in markdown into a presentation. So I threw together a nodejs parser that transformed the markdown into a single file deck.js app. Figured some others might find it interesting/useful.


Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: