const PROG_FACTORIAL = `YOU WON'T WANT TO MISS 'Hello, World!'
DISCOVER HOW TO factorial WITH n
RUMOR HAS IT
WHAT IF n IS ACTUALLY 0
SHOCKING DEVELOPMENT 1
LIES!
SHOCKING DEVELOPMENT
n TIMES factorial OF n MINUS 1
END OF STORY
EXPERTS CLAIM result TO BE factorial OF 10
YOU WON'T WANT TO MISS 'Result is'
YOU WON'T WANT TO MISS result
PLEASE LIKE AND SUBSCRIBE`;
const PROG_FIBONACCI = `DISCOVER HOW TO fibonacci WITH a, b, n
RUMOR HAS IT
WHAT IF n SMALLER THAN 1
SHOCKING DEVELOPMENT b
LIES! RUMOR HAS IT
YOU WON'T WANT TO MISS b
SHOCKING DEVELOPMENT
fibonacci OF b, a PLUS b, n MINUS 1
END OF STORY
END OF STORY
EXPERTS CLAIM limit TO BE 10
YOU WON'T WANT TO MISS 'First 10 Fibonacci numbers'
EXPERTS CLAIM nothing TO BE fibonacci OF 0, 1, limit
PLEASE LIKE AND SUBSCRIBE`;
const PROG_DEFAULT = PROG_FIBONACCI;
const HEADLINES = [
`You Won't Believe What This Programming Language Can Do!`,
`The Best Programming Language You Haven't Heard Of (It Will Surprise You!)`,
`Shocking New Programming Language Bewilders Programmers at Google and Facebook!`,
`Programmer Who Made Everything Now Predicts the Next Big Language!`,
`The Secret Programming Language Every 10x Programmer Recommends!`,
`Programmers at Microsoft Hate This One Trick to Get Good at that Code Thing!`,
`How To Lose Brain Fat With This Programming Language!`,
`Your Friends Will Be Jealous About This New Programming Language!`,
`You Can Earn Millions With This Programming Language!`,
`The Cure For Cancer Could Be Found With The Programming Language!`
];
function randomHeadline() {
return HEADLINES[~~(Math.random() * HEADLINES.length)];
}
const {
Component,
} = window.Torus;
class Editor extends Component {
init() {
this.prog = PROG_DEFAULT;
// script appends to it
this.output = '';
this.errors = '';
this.handleRun = () => this.eval();
this.handleInput = evt => {
this.prog = evt.target.value;
this.render();
}
this.handleKeydown = evt => {
if (evt.key === 'Tab') {
evt.preventDefault();
const idx = evt.target.selectionStart;
if (idx !== null) {
const front = this.prog.substr(0, idx);
const back = this.prog.substr(idx);
this.prog = front + ' ' + back;
this.render();
evt.target.setSelectionRange(idx + 4, idx + 4);
}
}
}
this.setFactorial = () => {
this.prog = PROG_FACTORIAL;
this.output = this.errors = '';
this.render();
}
this.setFibonacci= () => {
this.prog = PROG_FIBONACCI;
this.output = this.errors = '';
this.render();
}
}
eval() {
this.output = '';
this.errors = '';
try {
const tokens = tokenize(this.prog);
const nodes = new Parser(tokens).parse();
const env = new Environment({
print: s => {
this.output += s.toString().toUpperCase() + '!\n';
this.render();
},
});
env.run(nodes);
} catch (e) {
this.errors = e.toString();
}
this.render();
}
compose() {
return jdom`
`;
}
}
class App extends Component {
init() {
this.editor = new Editor();
}
compose() {
return jdom`
${randomHeadline()}
Tabloid: The Clickbait Headline Programming Language
${this.editor.node}
What?
Tabloid is a turing-complete programming
language for writing programs in the style of clickbait news
headlines.
Here are a few things${' '}the Top Five
Most Popular Quirks and Features of the Tabloid
programming language (Number Four Will Shock You!)
Print output with the keywords YOU WON'T WANT TO MISS followed by an
expression. Everything printed by Tabloid is
automatically capitalized, and an exclamation point is
added. Why would you want anything else?
Declare a function by writing DISCOVER HOW TO ... WITH. Truly, a more
gripping way to declare a function can't possibly exist!
Similarly, assign to a variable with EXPERTS CLAIM ... TO BE. On the Internet,
anyone can be an expert, and Tabloid gives YOU the power to
wield that responsibility and declare anything you'd like!
There are no built-in constructs for looping. The news
cycle is moving too fast! Nobody has time for yesterday's
loops or last week's break statements. If you must loop,
use recursion.
To return from a function, simply write SHOCKING DEVELOPMENT! You're going
to—gasp!—return? How shocking!
Every program must end with PLEASE LIKE AND
SUBSCRIBE, because you have to grow your audience! Hashtag hustle.
But why?
Didn't want to do homework for my
database
systems class, and needed something to do to procrastinate.
Will I finish the homework? Did I get enough sleep?
Stay tuned to find out!
Does it actually work?
Yes. Tabloid is a fully functioning, turing complete
programming language with an interpreter written in
JavaScript. Tabloid currently only supports numbers, strings,
and booleans, but with these elements, you can write any
program you'd want to write. You can edit and run the program above, or
see how it works for yourself.
Before making Tabloid, I also created a more useful and
well-designed${' '}boring and unpopular
programming language, called Ink.
How much is there?
Here's the full list of standard keywords that Tabloid currently uses:
DISCOVER HOW TO...WITH declare a function
RUMOR HAS IT begin a block scope
A OF B, C call function A with arguments B, C
WHAT IF...LIES! an if-else expression
END OF STORY end a block scope
EXPERTS CLAIM...TO BE declare or assign to a variable
YOU WON'T WANT TO MISS print output
TOTALLY RIGHT true
COMPLETELY WRONG false
PLUS / MINUS / TIMES / DIVIDED BY / MODULO the obvious arithmetic operations
IS ACTUALLY is equal to
BEATS / SMALLER THAN greater than / less than
SHOCKING DEVELOPMENT return from a function
PLEASE LIKE AND SUBSCRIBE end of program
`;
}
}
const app = new App();
document.body.appendChild(app.node);