---
date: '2024-10-11'
description: generative poetry using rita grammar rules to create infinite variations of dog-themed verses.
id: infinite poem
modified: 2026-06-05 15:08:04 GMT-04:00
tags:
  - pattern
title: infinite poem
created: '2024-10-11'
published: '2024-10-11'
pageLayout: default
slug: infinite-poem
permalink: https://aarnphm.xyz/infinite-poem.md
generator:
  quartz: v4.6.0
  hostedProvider: Cloudflare
  baseUrl: aarnphm.xyz
full: https://aarnphm.xyz/llms-full.txt
---
<div class="notebook-runtime" data-notebook-runtime="notebook-runtime-zguoce"></div>

<div class="notebook-code-cell" data-notebook-cell-frame="code-cell-1" id="code-cell-1" data-notebook-language="javascript">

<div class="notebook-runtime-cell" data-notebook-cell="code-cell-1" data-notebook-execution-count=""><span class="notebook-execution-prompt" data-notebook-execution-label="code-cell-1" aria-live="polite">In [ ]:</span></div>

<div class="notebook-cell-actions" data-notebook-cell-actions="code-cell-1">
<span class="notebook-language-badge notebook-language-badge-javascript" data-notebook-language="javascript" title="JavaScript cell"><span class="notebook-language-icon" aria-hidden="true"><svg class="notebook-language-svg" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><rect width="18" height="18" x="3" y="3" fill="currentColor" rx="2"/><text x="12" y="16.5" text-anchor="middle" font-family="ui-monospace, SFMono-Regular, Menlo, monospace" font-size="7.5" font-weight="900" fill="var(--light)">JS</text></svg></span><span class="notebook-language-label">JavaScript cell</span></span>
<button type="button" class="notebook-icon-button" data-notebook-run-cell="code-cell-1" aria-label="Run code-cell-1" title="Run code-cell-1"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M8 5v14l11-7z"/></svg></button>
<button type="button" class="notebook-icon-button" data-notebook-edit-cell="code-cell-1" aria-label="Edit code-cell-1" title="Edit code-cell-1"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m4 16.5-.5 4 4-.5L19 8.5 15.5 5z"/><path d="m14 6.5 3.5 3.5"/></svg></button>
<button type="button" class="notebook-icon-button" data-notebook-save-cell="code-cell-1" aria-label="Save code-cell-1 locally" title="Save code-cell-1 locally" hidden><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M5 4h11l3 3v13H5z"/><path d="M8 4v6h8V4"/><path d="M8 20v-6h8v6"/></svg></button>
<button type="button" class="notebook-icon-button" data-notebook-revert-cell="code-cell-1" aria-label="Revert code-cell-1 local edit" title="Revert code-cell-1 local edit" hidden><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 0 11H11"/></svg></button>
<button type="button" class="notebook-icon-button" data-notebook-vim-cell="code-cell-1" aria-label="Enable Vim mode" title="Enable Vim mode" hidden><svg class="notebook-vim-icon" viewBox="0 0 602 734" aria-hidden="true" focusable="false"><g transform="translate(2 3)"><path class="notebook-vim-icon-left" d="M0 155.5704 155-1l-.000003 728L0 572.237919z"/><path class="notebook-vim-icon-right" d="M443.060403 156.982405 600-1l-3.181208 728L442 572.219941z" transform="translate(521 363.5) scale(-1 1) translate(-521 -363.5)"/><path class="notebook-vim-icon-cross" d="M154.986294 0 558 615.189696 445.224605 728 42 114.172017z"/></g></svg></button>
<span class="notebook-local-source-status" data-notebook-local-source-status="code-cell-1" hidden></span>
</div>

<div class="notebook-source-editor" data-notebook-source-editor="code-cell-1" hidden></div>

```js
const rules = {
  start: '$line1\n    $line2\n$line3\n  $line4\n$line5',
  line1: 'What shall a $dog_breed do?',
  line2: '$verbs through the $nature_place,',
  line3: 'Then she $verbs her $dog_feature.',
  line4: '$human_action, I $human_verb',
  line5: 'This $adj $noun of $emotion.',
  dog_breed: 'labrador (4) | terrier | shepherd | beagle | poodle',
  dog_feature: 'floppy ears | wagging tail | wet nose | playful eyes | soft fur',
  verbs: 'runs | leaps | bounds | trots | dashes',
  nature_place: 'meadow | forest | garden | park | beach',
  human_action: 'Watching | Smiling | Laughing | Wondering | Marveling',
  human_verb: 'contemplate | ponder | appreciate | cherish | admire',
  adj: 'simple | joyful | precious | fleeting | eternal',
  noun: 'moment | bond | connection | friendship | companionship',
  emotion: 'love | happiness | wonder | gratitude | peace',
}

// Generate and print the poem 5 times
for (let i = 0; i < 10; i++) {
  console.log(`Poem ${i + 1}:`)
  console.log(RiTa.grammar(rules).expand())
  console.log() // Add a blank line between poems
}
```

<div class="notebook-runtime-output" data-notebook-output="code-cell-1" hidden></div>

</div>

<script type="application/json" data-notebook-runtime-data>{"id":"notebook-runtime-zguoce","sourcePath":"infinite poem.md","language":"javascript","indexUrl":"","cells":[{"id":"code-cell-1","source":"const rules = {\n  start: '$line1\\n    $line2\\n$line3\\n  $line4\\n$line5',\n  line1: 'What shall a $dog_breed do?',\n  line2: '$verbs through the $nature_place,',\n  line3: 'Then she $verbs her $dog_feature.',\n  line4: '$human_action, I $human_verb',\n  line5: 'This $adj $noun of $emotion.',\n  dog_breed: 'labrador (4) | terrier | shepherd | beagle | poodle',\n  dog_feature: 'floppy ears | wagging tail | wet nose | playful eyes | soft fur',\n  verbs: 'runs | leaps | bounds | trots | dashes',\n  nature_place: 'meadow | forest | garden | park | beach',\n  human_action: 'Watching | Smiling | Laughing | Wondering | Marveling',\n  human_verb: 'contemplate | ponder | appreciate | cherish | admire',\n  adj: 'simple | joyful | precious | fleeting | eternal',\n  noun: 'moment | bond | connection | friendship | companionship',\n  emotion: 'love | happiness | wonder | gratitude | peace',\n}\n\n// Generate and print the poem 5 times\nfor (let i = 0; i \u003c 10; i++) {\n  console.log(`Poem ${i + 1}:`)\n  console.log(RiTa.grammar(rules).expand())\n  console.log() // Add a blank line between poems\n}","language":"javascript","executionIndex":null}],"toolbar":false,"debug":true,"vimMode":true}</script>

