Poetry

Date: 198x
Type: Program
Platform(s): TS 2068

This program generates random four-line poems by selecting words from fifteen DATA lists, each containing fifteen entries covering nouns, verbs, adverbs, settings, and participial phrases. On each iteration it dimensions two arrays — a string array A$ of 15 rows by 12 characters and a numeric array B(15) to track actual word lengths — then randomly picks one word per category using RND*14+1 as an index. The poem is printed in a fixed grammatical template (“THE [noun] [verb] [adverb] / IN THE [setting]…”) and displayed for roughly three seconds via PAUSE 198 before cycling to the next poem, repeating 15 times before looping back. String slicing with TO B(M) trims trailing spaces from the fixed-length DIM A$ storage, avoiding padding artifacts in the output.


Program Analysis

Program Structure

The program is organized into three logical sections: initialization (lines 20–30), a word-selection subroutine (lines 40–80), and the main display loop (lines 90–180), backed by thirteen DATA blocks (lines 200–320). Line 30 seeds the random number generator with RANDOMIZE and jumps to the setup at line 90. The main loop at lines 100–180 runs 15 iterations; each calls the subroutine at line 40, prints a four-line poem, pauses, then repeats. After 15 poems, GO TO 1 at line 180 targets a non-existent line, effectively halting execution gracefully.

Array Design and Word Storage

DIM A$(15,12) allocates a two-dimensional string array: 15 slots of exactly 12 characters each. Because BASIC pads fixed-length string arrays with spaces, the actual word length for each slot is stored in the parallel numeric array B(15). During printing, every word is sliced as A$(M, TO B(M)) to strip trailing pad characters and produce clean output. This two-array pattern — one for content, one for lengths — is a standard workaround for fixed-length string array limitations.

Word Selection Subroutine (Lines 40–80)

The subroutine loops over 13 word categories (M=1 to 13). For each category, it calculates the DATA line as 190 + 10*M, which maps M=1 to line 200, M=2 to line 210, and so on through M=13 to line 320. It then performs a random skip: FOR G=1 TO RND*14+1: READ B$: NEXT G reads and discards a random number of items (1–15) from that DATA line, leaving B$ holding the last-read word. The word is stored in A$(M) and its length in B(M).

DATA Organization

Each DATA line holds exactly 15 entries (though line 290 has 16 items — a minor anomaly). The categories map to the following roles in the poem template:

MLineRole in poemExamples
1200Subject nounMAN, ROBOT, WITCH
2210Past-tense verbSANG, CRIED, FELL
3220AdverbSADLY, MADLY, QUIETLY
4230SettingWASTELAND, SWAMP, FOREST
5240Present participleLOOKING, DYING, MUTATING
6250Object nounREASON, TRUTH, DOOR
7260Infinitive verbREACH, FEEL, CHANGE
8270Object noun 2MOON, FEAR, CLOWNS
9280Present participle 2WATCHING, RANTING, ASPIRING
10290Linking wordHEART, PAST, JUST, NOW
11300Gerund/noun phraseNOTHING, FADING, ALL
12310Present participle 3CHANGING, HIDING, BUILDING
13320Closing wordGIVING, DYING, LOVING

Notable Techniques

  • RESTORE 190+10*M resets the DATA pointer to a specific line before each random skip, allowing independent random selection per category without consuming the entire DATA stream sequentially.
  • POKE 23692,0 at line 90 writes zero to the ZX Spectrum’s scroll counter system variable (SCRCT), suppressing the “scroll?” prompt so the poems display uninterrupted.
  • PAUSE VAL "198" uses the VAL string trick to store the numeric literal more compactly in tokenized form, a common memory-saving idiom.
  • Four apostrophes after line 150’s PRINT statement generate four blank lines between poems, creating visual spacing without separate PRINT statements.

Bugs and Anomalies

  • Line 180 skips from line number 180 directly to 200 — line 190 is absent. This is intentional: DATA begins at line 200, and the formula 190+10*M for M=1 correctly targets line 200.
  • Line 290 contains 16 DATA items instead of 15, meaning the 16th entry (“SIMULATING”) can never be selected, since RND*14+1 produces a maximum index of 15.
  • The subroutine iterates M=1 to 13, but DIM A$(15,12) and DIM B(15) allocate 15 slots — slots 14 and 15 are never written, which wastes a small amount of memory but causes no runtime error.
  • Line 20 uses DIM A$(15,12) with only 12 characters per slot. Several DATA words exceed 12 characters (e.g., “ROCK CONCERT” = 12, “REPUBLICAN” = 10, “ANCHORMAN” = 9) — “ROCK CONCERT” exactly fits at 12, but any longer entry would be silently truncated.

Content

Appears On

Library tape of the Indiana Sinclair Timex User’s Group.

Related Products

Related Articles

Related Content

Image Gallery

Source Code

   10 REM Poetry
   20 DIM A$(15,12): DIM B(15)
   30 RANDOMIZE : GO TO 90
   40 FOR M=1 TO 13
   50 RESTORE 190+10*M
   60 FOR G=1 TO RND*14+1: READ B$: NEXT G: LET A$(M)=B$
   70 LET B(M)=LEN B$: NEXT M
   80 RETURN 
   90 POKE 23692,0
  100 FOR H=1 TO 15
  110 GO SUB 40
  120 PRINT '"THE ";A$(1, TO B(1));" ";A$(2, TO B(2));" ";A$(3, TO B(3)),"   IN THE ";A$(4, TO B(4));","   
  130 PRINT A$(5, TO B(5));" FOR A ";A$(6, TO B(6)),"   TO ";A$(7, TO B(7));" THE ";A$(8, TO B(8));"...."
  140 PRINT A$(9, TO B(9));" ";A$(10, TO B(10));" IN ";A$(11, TO B(11))
  150 PRINT "    ....";A$(12, TO B(12));", ";A$(13, TO B(13));"."''''
  160 PAUSE VAL "198"
  180 NEXT H: GO TO 1
  200 DATA "MAN","BOY","WOMAN","CHILD","SHADOW","ECHO","GIRL","MUTANT","PROPHET","MARTYR","REPUBLICAN","ROBOT","PRINCESS","WITCH","ANCHORMAN"
  210 DATA "SANG","WAITED","SAID","SCREAMED","CRIED","PLEADED","PRAYED","STOOD","FELL","STUMBLED","READ","CURSED","CHANGED","MELTED","MOVED"
  220 DATA "SADLY","GLADLY","SLOWLY","FAINTLY","MADLY","HUMBLY","LOUDLY","BITTERLY","QUIETLY","QUICKLY","CURIOUSLY","INTENTLY","SICKLY","POINTLESSLY","REASONABLY"
  230 DATA "DARK","DOORWAY","GATEWAY","MORNING","EVENING","RUINED CITY","WASTELAND","MOTEL","CANYON","FOREST","ROCK CONCERT","ALIEN FILM","SWAMP","DESERT","FLYING SAUCER"
  240 DATA "LOOKING","SEARCHING","HOPING","DESIRING","DESPAIRING","ASKING","PLEADING","WAITING","CRYING","REACHING","INTERESTED","DYING","WISHING","EVOLVING","MUTATING"
  250 DATA "WAY","REASON","SIGN","FUTURE","WISH","BUS","DOOR","DEATH","TRUTH","LIFE","BOOK","TELEVISION","COKE","TELEPHONE","VOTER"
  260 DATA "REACH","FEEL","MOVE","STEAL","SHARE","CHANGE","TWIST","FACE","DESIRE","BLAME","TOUCH","ABUSE","MOVE","CHANGE","CONSTRAIN"
  270 DATA "MOON","MORNING","NIGHT","PAIN","FEAR","INSECTS","LIGHT","POWER","HATE","SUN","LAWYER","FISH","DEMOCRATS","RATS","CLOWNS"
  280 DATA "TAKING","WATCHING","CHANGING","BLAMING","GETTING","TREMBLING","WONDERING","HOPING","SPEAKING","CALCULATING","HALUCINATING","RANTING","LOOKING","FEELING","ASPIRING"
  290 DATA "HEART","PAST","HOW","WHY","DOWN","THROUGH","FOR","THEN","JUST","AS","NOW","WHEN","WHILST","ALMOST","LIKE","SIMULATING"
  300 DATA "NOTHING","GIVING","FADING","DARING","LAUGHING","DYING","CRYING","CHANGING","BLAMING","GRASPING","ALL","FEARING","CAMPAIGNING","SELLING","RETREADING"
  310 DATA "TAKING","WATCHING","CHANGING","BLAMING","GETTING","TREMBLING","WONDERING","HOPING","SPEAKING","CALCULATING","BORING","HIDING","BUILDING","WATCHING","FREAKING"
  320 DATA "NOTHING","GIVING","FADING","DARING","LAUGHING","DYING","CRYING","CHANGING","BLAMING","GRASPING","SCHEMING","INSENSATE","EVOLVING","HURTING","LOVING","DRINKING"
 9998 SAVE "POETRY" LINE 20

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top