Some notes on how karen.pl and miina.ml are written. These kind of program takes quite a bit of planning ^_^; 0. Target The goal is to create polyglot quine of two languages. Functionally: When program P1 is parsed with interpretor I1, it's a quine (the source of P1 is regenerated). When program P1 is parsed with interpretor I2, it generates the source for P2. P2 is analogous to P1 described above. When described as a DFA, P1 and P2 are the states, interpretors I1 and I2 are the inputs. I1 always leads to P1 from any state, I2 always leads to P2 from any state. 1. Layout The above is to be implemented in two files, one for each state (P1 and P2). The two interpretors chosen for this project were OCaml and Perl. The two languages have enough freedom in their syntax, and coexists well. Contents of each file is as follows: source 1 { ocaml code -> output source 1 perl code -> output source 2 data } source 2 { ocaml code -> output source 1 perl code -> output source 2 data } i.e. OCaml code always print source 1, and Perl code always print source 2. This means the source and data are actually identical for both sources. The data will be: data { layout for source 1 layout for source 2 decoder source } Layout is length encoded as follows: , . = newlines (44, 46) a-z = whitespace (97-122) A-Z = character (65-90) "," is the separator between the two layouts, and also acts as a newline. Decoder prints: decoded source layouts encoded source footer Decoder keeps two strings, the layout (format) string and the text string. Layout string is consumed one character at a time, and code string is used when the template requires it. 2. Implementation q0.ml, q1.ml, q0.pl, q1.pl OCaml source is written first, then Perl source. code0.ml, code1.ml, code2.ml, code3.ml Sources of the two languages are combined, then compressed (remove unnecessary operators, replace variables, inline functions, etc). OCaml source comes first because the syntax is less flexible, and needs the longer tokens available at start of template. code.txt, code.xor To encode sources to get around quoting problems (can't store '"' and $ inside double quoted strings), simple xor filter was used, with key 21. Some characters can't be used due to quoting and character set restrictions, such as '0', '1', 'j', etc. Sources were rewritten accordingly. code4.ml Proof of concept code, with simple templates. This is to debug any unseen issues with the decoder. code.txt.keep, generate.pl, template/*, karen.pl, miina.ml Final templates were generated, and code was iteratively tweaked to fit the templates' formatting (inserting code to prevent newlines inside a syntactic token, replacing template string to fit length). The programs were generated from Perl scripts, I didn't have to edit the sources directly. In creating the initial templates, image sizes were chosen so that both layouts would have the exact same number of non-whitespace characters, and the number is roughly twice the code size plus the size of the format strings. This has to be an overestimate, to leave room for tweaking the sources (easy to fudge source to increase size, impossible to decrease size). Karen and Miina were chosen as the template image very early on. There aren't that many famous twins recently ^_^ ocamlp.pl This is to allow OCaml to run scripts from stdin, to facilitate testing. test.sh This is the testing script, tests that running OCaml and Perl interpretors on any version of the source always output the correct version. design.txt Always good to have documentation :)