# The Boston Diaries

The ongoing saga of a programmer who doesn't live in Boston, nor does he even like Boston, but yet named his weblog/journal “The Boston Diaries.”

Go figure.

## Tuesday, November 07, 2017

### Love is … a freaking wall of text

And so I implemented my idea in about all of an hour. The code itself is pretty straightforward:

```require "org.conman.math".randomseed()

local fixcase = Cs(
(R"az" / function(c) return c:upper() end + P(1))
* P(1)^0
)

local function lookup(term)
local list

if dict[term] then
list = dict[term]
else
local l = fixcase:match(term)
if dict[l] then
list = dict[l]
else
return term
end
end

return list[math.random(#list)]
end

local word   = R("''","--","AZ","az")^1
local term   = word / lookup
+ P(1)
local corpus = Cs(term^1)

local count  = Cf(
Cc(0) * (word * Cc(1) + P(1) * Cc(0))^1,
function(acc,count)
return acc + count
end
)

local text = "Love"
local num
local loop = 0

repeat
loop = loop + 1
text = corpus:match(text)
num  = count:match(text)
until num >= 50000

print(string.format([[

Love is ...

A Definitional Novel
in %d expansions and %d words

]],loop,num))

print(wrap(text))
```

The first line initializes the random number generator, then an LPeg expression to uppercase the leading character of a word (that's how most of the terms in the dictionary I used appear). Then we have a function that returns either a random defintion of a given term, or if no definition exists, the term itself. Next is the definition of a “word” with the expression `word`—one or more letters, dashes or apostrophes. The next expression, `term`, either finds a “word” and does the definition lookup via `lookup()` or just whatever non-word text it finds (punctuation marks mostly). The expression `corpus` will run `term` multiple times, replacing the input with the translated output (this is a “substitution capture as it's called in LPeg).

The `count` expression just counts words—it's a folding capture which accumulates a single result. In this case, we start with 0 (`Cc(0)`), then for each “word” in the input it returns a 1; otherwise a 0 (```word * Cc(1) + P(1) * Cc(0)```), which is added to our accumulator using the given anonymous function.

Then it's a matter of starting with “Love” and running this a few times until we get over 50,000 words.

What I didn't expect (but should have) is the “Wall Of Text” that is generated:

To denote having as a possession or an appendage; as, the firmament with its stars; a bride with a large fortune. One of whom inquires can be made as to the integrity, capacity, and the like, of another. Apposition; connection; antithesis; opposition; as, they engaged hand to hand. a That which terminates, circumscribes, restrains, or confines; the bound, border, or edge; the utmost extent; as, the limit of a walk, of a town, of a country; the limits of human knowledge or endeavor. Denoting nearness or distance, either in space or time; from; as, within a league of the town; within an hour of the appointed time. The period at which any definite event occurred, or person lived; age; period; era; as, the Spanish Armada was destroyed in the time of Queen Elizabeth; – often in the plural; as, ancient times; modern times.; as, With privilege or possession; – used to denote a holding, possession, or seisin; as, in by descent; in by purchase; in of the seisin of her husband. an A measure of distance traveled.; As a substance for any noun of the neuter gender; as, here is the book, take it home. happened One who is in office; – the opposite of out. See Thee. A wooden block shaped like the human foot, on which boots and shoes are formed. A division of the Roman people formed according to their property, for the purpose of voting for civil officers.; To inclose; to take in; to harvest. all Of or belonging to me; – used always attributively; as, my body; my book; – mine is used in the predicate; as, the book is mine. See Mine. The potential principle, or force, by which the organs of animals and plants are started and continued in the performance of their several and cooperative functions; the vital force, whether regarded as physical or spiritual‥ A Freely; licentiously. Yellow or gold color, – represented in drawing or engraving by small dots. Worthy of consideration; requiring to be observed, borne in mind, or attended to. A numeral; a word or character denoting a number; as, to put a number on a door‥ phrases, and To denote a connection of friendship, support, alliance, assistance, countenance, etc.; hence, on the side of. That which refers to something; a specific direction of the attention; as, a reference in a text-book. Extent; limit; degree of comprehension; inclusion as far as; as, they met us to the number of three hundred. a The space or thing defined by limits. Denoting the agent, or person by whom, or thing by which, anything is, or is done; by. To measure, as in music or harmony.; as, With reference to circumstances or conditions; as, he is in difficulties; she stood in a blaze of light. an Fixed or appointed time; conjuncture; a particular time or occasion; as, the hour of greatest peril; the man for the hour.; As a substitute for such general terms as, the state of affairs, the condition of things, and the like; as, how is it with the sick man? happened With reference to circumstances or conditions; as, he is in difficulties; she stood in a blaze of light. A word placed before nouns to limit or individualize their meaning. A wooden block shaped like the human foot, on which boots and shoes are formed. A division of the Roman people formed according to their property, for the purpose of voting for civil officers.; The specific signification of in is situation or place with respect to surrounding, environment, encompassment, etc. It is used with verbs signifying being, resting, or moving within limits, or within circumstances or conditions of any kind conceived of as limiting, confining, or investing, either wholly or in part. In its different applications, it approaches some of the meanings of, and sometimes is interchangeable with, within, into, on, at, of, and among. all Of or belonging to me; – used always attributively; as, my body; my book; – mine is used in the predicate; as, the book is mine. See Mine. Figuratively: The potential or animating principle, also, the period of duration, of anything that is conceived of as resembling a natural organism in structure or functions; as, the life of a state, a machine, or a book; authority is the life of government‥ (usually Relating to, or containing, more than one; designating two or more; as, a plural word.) an acquaintance Ere; before; sooner than. acquaintances Originally, an interrogative pronoun, later, a relative pronoun also; – used always substantively, and either as singular or plural. See the Note under What, pron., 1. As interrogative …

Love is …

and so on for another 12,856 lines.

A literal “Wall Of Text.”

It also overshot the 50,000 words by 120,007 words. Yes, there are a total of 170,007 words (minus the title) in this “novel.” And what was totally surprising to me is the number of times through the expansion loop—only four.

From “Love” to “To denote having as a possession or an appendage; as, the firmament …” in four steps.

I found the “ending” to be somewhat amusing:

… Denoting identity or equivalence; – used with a name or appellation, and equivalent to the relation of apposition; as, the continent of America; the city of Rome; the Island of Cuba. To work, as raw or partly wrought materials, into suitable forms for use; as, to manufacture wool, cotton, silk, or iron… adventures.

Love is …

Apparantly, love contains tourist hotspots, industrial production and adventures. Who knew?

## Obligatory Miscellaneous

You have my permission to link freely to any entry here. Go ahead, I won't bite. I promise.

The dates are the permanent links to that day's entries (or entry, if there is only one entry). The titles are the permanent links to that entry only. The format for the links are simple: Start with the base link for this site: https://boston.conman.org/, then add the date you are interested in, say 2000/08/01, so that would make the final URL:

https://boston.conman.org/2000/08/01

You can also specify the entire month by leaving off the day portion. You can even select an arbitrary portion of time.

You may also note subtle shading of the links and that's intentional: the “closer” the link is (relative to the page) the “brighter” it appears. It's an experiment in using color shading to denote the distance a link is from here. If you don't notice it, don't worry; it's not all that important.

It is assumed that every brand name, slogan, corporate name, symbol, design element, et cetera mentioned in these pages is a protected and/or trademarked entity, the sole property of its owner(s), and acknowledgement of this status is implied.