This commit is contained in:
gauthiier 2023-12-18 08:14:32 +01:00
parent 4a2fafc8d7
commit 5374cc530a

View File

@ -140,7 +140,7 @@ Rudimentary indeed, but there are many things we can build with this simple func
Since we access elements of an array with indices, we can generate a random index between 0 and the length of an array to select a random element in it. Since we access elements of an array with indices, we can generate a random index between 0 and the length of an array to select a random element in it.
The first problem we must solve though is that the ```random``` functions generates a "real" number (ex: 4.993319470244624, 1.9486631456631776, 7.1841821754535813, etc.) while the indices of an array are "integer" numbers (5, 2, 7, etc.). We thus need to round the "real" numbers produced by random to get an “integer” (4.993319470244624 -> 5, 1.9486631456631776 -> 2, 7.1841821754535813 -> 7). The first problem we must solve though is that the ```random``` functions generates a "real" number (ex: 4.993319470244624, 1.9486631456631776, 7.1841821754535813, etc.) while the indices of an array are "integer" (whole) numbers (5, 2, 7, etc.). We thus need to round the "real" numbers produced by random to get an “integer” (4.993319470244624 -> 5, 1.9486631456631776 -> 2, 7.1841821754535813 -> 7).
We do this with the ```floor``` function that simply rounds a number down (4.993319470244624 -> 4) to the nearest integer. Here is an example: We do this with the ```floor``` function that simply rounds a number down (4.993319470244624 -> 4) to the nearest integer. Here is an example:
@ -248,11 +248,11 @@ Karin wears a black jacket when Maaike plays chess
So now that we have a better understanding of how arrays, indices, randomness, and functions work, let's write love letters! So now that we have a better understanding of how arrays, indices, randomness, and functions work, let's write love letters!
One of the first non-scientific computer program that was ever written is Christopher Strachey's Love Letters program for the Manchester Mark I (so called [Baby](https://content.presspage.com/uploads/1369/1920_themanchestermk1computerbuiltbyextendingthebaby.jpg?10000)). In fact, this computer program (written in 1952 and making use of randomness) is arguably the first art-inspired program! One of the first non-scientific computer program that was ever written is Christopher Strachey's Love Letters program devised for the Manchester Mark I (the so called [Baby](https://content.presspage.com/uploads/1369/1920_themanchestermk1computerbuiltbyextendingthebaby.jpg?10000)). In fact, this computer program (written in 1952 and making use of randomness) is arguably the first art-inspired program!
Christopher Strachey was/is a computer programming pioneer who worked along Alan Turing in the very early days of computing at the University of Manchester. Strachey's story is fascinating. There is a great article about [him and the love letters on Rhizome's Queer History of Computing written by Jacob Gaboury](https://rhizome.org/editorial/2013/apr/9/queer-history-computing-part-three/). For those who are interested in researching Strachey's work, please have a look at his [papers and correspondences at the Bodleain library's archive](https://archives.bodleian.ox.ac.uk/repositories/2/resources/2561). Christopher Strachey was/is a computer programming pioneer who worked along Alan Turing in the very early days of computing at the University of Manchester. Strachey's story is fascinating. There is a great article about [him and the love letters on Rhizome's Queer History of Computing written by Jacob Gaboury](https://rhizome.org/editorial/2013/apr/9/queer-history-computing-part-three/). For those who are interested in researching Strachey's work, please have a look at his [papers and correspondences at the Bodleain library's archive](https://archives.bodleian.ox.ac.uk/repositories/2/resources/2561).
Strachey's Love Letters have been studied before. [David Link](http://www.alpha60.de) did a colossal reconstitution of the Love Letter program on a simulator of the Manchester Mark computer. [The works was exhibited circa 2010](http://www.alpha60.de/art/love_letters/). The program does not look at all like the code we are writing now! The picture on the right side of the image above (☝️) is from Link's simulator. Early computers did not have the compilers and interpreters we have now (remember compilers and interpreters?) and thus the code was written in a rather cryptic way (believe me, way more cryptic than what we are writing now). Strachey's Love Letters have been studied before. [David Link](http://www.alpha60.de) did a colossal reconstitution of the Love Letters program on a simulator of the Manchester Mark I computer. [The work was exhibited circa 2010](http://www.alpha60.de/art/love_letters/). Strachey's program does not look at all like the code we are writing now! The picture on the right side of the image above (☝️) is from Link's simulator. Early computers did not have the compilers and interpreters we have now (remember compilers and interpreters?) and thus the code was written in a rather cryptic way (believe me, way more cryptic than what we are writing now).
The program we are about to write in a "modern" computing language (i.e. javascript/p5js) is a modified version of [Nick Montfort](https://nickm.com)'s letter.py code written in python (another programming language). Montfort's letter.py was based on Noah Wardrip-Fruin's article ["Digital Media Archaeology."](https://www.degruyter.com/document/doi/10.1525/9780520948518-016/html) The program we are about to write in a "modern" computing language (i.e. javascript/p5js) is a modified version of [Nick Montfort](https://nickm.com)'s letter.py code written in python (another programming language). Montfort's letter.py was based on Noah Wardrip-Fruin's article ["Digital Media Archaeology."](https://www.degruyter.com/document/doi/10.1525/9780520948518-016/html)
@ -317,7 +317,7 @@ HONEY LOVE
MUC MUC
``` ```
Can you decipher certain writing patterns in the above formulations? If so, what are they? Can you decipher certain word patterns in the above formulations? If so, what are they?
Consider the following sentences: Consider the following sentences:
@ -326,11 +326,11 @@ MY YEARNING FERVENTLY LIKES YOUR AMOROUS PASSION.
MY APPETITE TENDERLY CHERISHES YOUR BEAUTIFUL WISH. MY APPETITE TENDERLY CHERISHES YOUR BEAUTIFUL WISH.
``` ```
Are there common words here? Yes, the "MY" and "YOUR". Are there common words here? Yes, the "MY" and "YOUR" right?
What about the other words, do they have something in common? Yes. They are nouns, adverbs, verbs, and adjectives. And these have indeed a particular position in each sentence. What about the other words, do they have something in common? Yes. They are sequences of nouns, adverbs, verbs, and adjectives. And these have indeed a particular position in each sentence.
We can thus devise a "code" of the sentences as follow: We can thus devise a "code" or "template" of the sentences as follow:
MY + ```noun``` + ```adverb``` + ```verb``` + YOUR + ```adjective``` + ```noun``` + . MY + ```noun``` + ```adverb``` + ```verb``` + YOUR + ```adjective``` + ```noun``` + .
@ -371,15 +371,15 @@ Also, in terms of composition or sentences sequencing we can notice that:
3. short form YOU ARE MY + ```adjective``` + ```noun``` + . is never followed by the same short form YOU ARE MY + ```adjective``` + ```noun``` + . 3. short form YOU ARE MY + ```adjective``` + ```noun``` + . is never followed by the same short form YOU ARE MY + ```adjective``` + ```noun``` + .
4. A letter comprises between 4 and 5 sentences (long or short form) 4. A letter comprises between 4 and 5 sentences (long or short form)
5. A letter is always closed with YOURS + ```adverb``` 5. A letter is always closed with YOURS + ```adverb```
6. A letter is always signed by MUC (which means Manchester University Computer Department) 6. A letter is always signed by MUC (which means Manchester University Computer)
### Reconstituting Love Letters' algorithm ### Reconstituting Love Letters' algorithm
Now that we have an idea of the structure of Strachey's letters, let's get to work in formalising it's algorithmic generation. Now that we have an idea of the structure of Strachey's letters, let's get to work in formalising their algorithmic generation.
Luckily, in terms of vocabulary, we can start with Monfort's work that gives the following arrays: Luckily, in terms of vocabulary, we can start with Monfort's archaeological work that gives the following vocabulary in an array forms:
```javascript ```javascript
// vocabulary // vocabulary
@ -417,7 +417,7 @@ function long() {
This will certainly work. Yet I would like to have more variation with the sentences the function returns. As it stands it will always follow the long form structure. Is there a way we can achieve this with injecting some randomness in the structure? This will certainly work. Yet I would like to have more variation with the sentences the function returns. As it stands it will always follow the long form structure. Is there a way we can achieve this with injecting some randomness in the structure?
How about we make ```adjective``` and ```adverb``` non mandatory, meaning they maybe there or not. What I have in mind is something like: How about we make ```adjective``` and ```adverb``` non mandatory, meaning they might be printed or not. What I have in mind is something like:
```javascript ```javascript
// function that randomly generates a long form sentence // function that randomly generates a long form sentence
@ -444,7 +444,7 @@ function maybe(array_to_choose_from) {
} }
```` ````
With this ```maybe``` function we now have a way to diversify the letter's sentences and thus create more variation on our generated long forms. With this ```maybe``` function we now have a way to diversify the letter's sentences and thus produce more variations of our generated long forms.
How about the short forms? How about the short forms?
@ -486,7 +486,11 @@ function closing() {
Great. Now we have most of the ingredients in place with the functions ```choice```, ```maybe```, ```long```, ```short```, ```opening```, ```closing``` right? Great. Now we have most of the ingredients in place with the functions ```choice```, ```maybe```, ```long```, ```short```, ```opening```, ```closing``` right?
How about sequencing ```long``` and ```short``` forms? Remember what we observed above (i.e. a letter is 4 to 5 sentences long, short form MY + ```adjective``` + ```noun``` + . always follows the other short form, etc.)? How about sequencing ```long``` and ```short``` forms? Remember what we observed above (points 2, 3, 4):
2. the short form MY + ```adjective``` + ```noun``` + . always follows the other short form YOU ARE MY + ```adjective``` + ```noun``` + . This short form never follows the long form.
3. short form YOU ARE MY + ```adjective``` + ```noun``` + . is never followed by the same short form YOU ARE MY + ```adjective``` + ```noun``` + .
4. A letter comprises between 4 and 5 sentences (long or short form)
Following these observation here is a skeleton of an algorithm doing just that: Following these observation here is a skeleton of an algorithm doing just that:
@ -494,10 +498,10 @@ Following these observation here is a skeleton of an algorithm doing just that:
// start with an empty text // start with an empty text
var text = ""; var text = "";
// did we just wrote the short form with "YOU ARE MY" // did we just wrote the short form with "YOU ARE MY" (points #2 and #3)
let YOU_ARE = false; let YOU_ARE_MY = false;
// loop 5 times to generate 5 sentences // loop 5 times to generate 5 sentences (point #4)
for(let i = 0; i < 5; i++) { for(let i = 0; i < 5; i++) {
// choose if the next sentence is a short or long // choose if the next sentence is a short or long
@ -506,30 +510,30 @@ for(let i = 0; i < 5; i++) {
if(sentence_form == 'short') { if(sentence_form == 'short') {
// there's two types of short to switch from // there's two types of short to switch from
// the short form MY + ```adjective``` + ```noun``` + . // (#2) the short form MY + ```adjective``` + ```noun``` + .
// always follows the YOU ARE MY + ```adjective``` + ```noun``` + . one // always follows the YOU ARE MY + ```adjective``` + ```noun``` + . one
// and // and
// the short form YOU ARE MY + ```adjective``` + ```noun``` + . one // (#3) the short form YOU ARE MY + ```adjective``` + ```noun``` + . one
// can never follow itself // can never follow itself
// this means we need keep track of when "YOU ARE MY" is generated // this means we need keep track of when "YOU ARE MY" is generated
// and switch to the other form next time. This is what the variable // and switch to the other form next time. This is what the variable
// YOU_ARE is doing // YOU_ARE_MY is doing
if(YOU_ARE) { if(YOU_ARE_MY) {
// the ": MY" can only follow a "YOU ARE MY" // the ": MY" can only follow a "YOU ARE MY" (point #2)
text += ": MY " + short(); text += ": MY " + short();
YOU_ARE = false; YOU_ARE_MY = false;
} else { } else {
text += "YOUR ARE MY " + short(); text += "YOUR ARE MY " + short();
// the ": MY" can only follow a "YOU ARE MY" // the "YOU ARE MY" cannot follow another "YOU ARE MY"(point #3)
YOU_ARE = true; YOU_ARE_MY = true;
} }
} }
else if(sentence_form == 'long') { else if(sentence_form == 'long') {
text += long(); text += long();
// make sure the next sentence is not ": MY" // make sure the next sentence is not ": MY"
YOU_ARE = false YOU_ARE_MY = false
} }
} }
```` ````
@ -538,7 +542,7 @@ for(let i = 0; i < 5; i++) {
### Putting it all together ### Putting it all together
Ok, let's formalise what we have sketched above and write a custom ```write_letter``` function that returns and full fleshed love letter. Ok, let's formalise what we have sketched above and write a custom ```write_letter``` function that returns and full love letter.
```javascript ```javascript
// function returning a love letter // function returning a love letter