I created Tom's JavaScript Machine in November 2009, while teaching a course about the Foundations of Informatics in the Honors Programme of the TU/e. I wanted to offer the challenge of writing a self-reproducing program,
Of course, some programming language is needed, because without concrete programming language it is too easy to fool oneself into believing that one has solved the challenge. The subset of JavaScript together with the extensions for input and output offered by Tom's JavaScript Machine seems reasonably suitable.
does not work to let c traverse the characters in string s. Apparently this use of for-in is not according to the standard. It has been replaced by (the more ugly):
For instance, will put the example program that copies input, into the machine, provide it with the input Hello, and run it.
The two most relevant actions are: _run(); and _challenge();.
<head>
section:
<link type="text/css" rel="stylesheet" href="tjsm.css">
<script type="text/javascript" src="javascript-machine.js"></script>
The first example just displays a program with a link to transfer it to the machine:
The HTML source code for this is:
The second example displays input, program, corresponding output, and a link to transfer program with input to the machine and have it executed there:
The HTML source code for this table is:
Ouput an embeddable version of the input Input: Program Output: Input: Program Output: Alternatively, developers of web pages for Tom's JavaScript Machine can enable a secret Embed button, by running the program
The Embed button generates an embeddable version of the contents of the program box and puts it into the output box. You can test the output by copying it to the input box (use the Copy to Input button), and running the program
You can hide the Embed button again by running
N.B. The embeddings in the examples and hints were produced by an older version of _embed() that used the line continuation mechanism for string literals. I abandoned this, because that makes it improssible to indent the strings. By using string concatenation through +, one can indent the string expression.