const PROG_DEFAULT = `DISCOVER HOW TO factorial WITH n WE SAID WHAT IF n IS ACTUALLY 0 WE SAID SHOCKING DEVELOPMENT 1 END OF STORY LIES! WE SAID SHOCKING DEVELOPMENT n MULTIPLY factorial OF n SUBTRACT 1 END OF STORY 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 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!`, ]; 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.handleReset = () => { this.prog = PROG_DEFAULT; this.render(); } this.handleInput = evt => { this.prog = evt.target.value; 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() + '\n'; this.render(); }, }); env.run(nodes); } catch (e) { this.errors = e.toString(); } this.render(); } compose() { return jdom`
${this.prog === PROG_DEFAULT ? null : jdom``}
${this.prog.split('\n') .map(line => jdom`

${line.trim() ? line : '-'}

`)}
${this.output ? this.output .split('\n') .map(line => jdom`${line}`) : jdom`No output.`}
${this.errors ? jdom`
${this.errors.split('\n').map(line => jdom`${line}`)}
` : null}
`; } } class App extends Component { init() { this.editor = new Editor(); } compose() { return jdom`

${randomHeadline()}

Tabloid: The Clickbait Headline Programming Language

${this.editor.node}

What?

But why?

Does it actually work?

`; } } const app = new App(); document.body.appendChild(app.node);