Your task is to create a BASIC program that will generate some simple poetry. Keep in mind that it should be able to expand and become complex over time.
Assistant
Here's a simple BASIC program that generates a three-line poem randomly by selecting words from arrays.
1 REM POETRY GENERATOR
2 REM
10 DIM ADJ(5),NOUN(5), VERB(1) = "beautiful"
30 LET ADJ(3) = "happy"
50 LET ADJ(5) = "gentle"
70 LET NOUN(2) = "forest"
90 LET NOUN(4) = "moon"
110 LET NOUN(1) = "whispers"
130 LET VERB(3) = "dances"
150 LET VERB(5) = "blooms"
170 RANDOMIZE TIMER
180 FOR L = 1 to 3
190 LET A = INT(RND(1)*5+1)
200 LET B = INT(RND(1)*5+1)
210 LET C = INT(RND(1)*5+1)
220 PRINT ADJ(B) + " " + VERB$(C)
230 NEXT L
240 END
User
Nice. Now, to make it easier to add to the vocabulary, make the words be defined in DATA-statements instead, and read in by the READ instruction.
Assistant
To modify the program to use DATA-statements and the READ instruction, you can do the following:
1 REM POETRY GENERATOR
2 REM
10 DIM ADJ(5),NOUN(5), VERB(I), NOUN(I)
40 NEXT I
50 DATA "beautiful", "morning", "whispers"
60 DATA "bright", "forest", "sings"
70 DATA "happy", "love", "dances"
80 DATA "mysterious", "moon", "shines"
90 DATA "gentle", "wind", "blooms"
100 RANDOMIZE TIMER
110 FOR L = 1 TO 3
120 LET A = INT(RND(1)*5+1)
130 LET B = INT(RND(1)*5+1)
140 LET C = INT(RND(1)*5+1)
150 PRINT ADJ(B) + " " + VERB$(C)
160 NEXT L
170 END
User
Next, I'd like the program to generate a couple of different sentence structures instead of the simple one it is at the moment.
Assistant
Sure! I added two sentence structures in addition to the existing one. Now, the generated poem can have a mix of these structures.
1 REM POETRY GENERATOR
2 REM
10 DIM ADJ(5),NOU(5), VERB(2)
20 FOR I = 1 TO 5
30 READ ADJ(I), VERB(1), PREP(A) + " " + NOUN(C)
220 GOTO 270
230 PRINT ADJ(B) + " " + VERB(D) + " the " + NOUN(B) + " " + VERB(A) + " " + NOUN$(A)
260 GOTO 270
270 NEXT L
280 END
User
Put these sentence structures in DATA-statements in order to make it easier to add new ones later. It will also make the code easier to read.
Assistant
To use DATA-statements for the sentence structures, you may use numbers to represent different parts of speech, and a subprogram to print the words based on their number. Here's the modified code.
1 REM POETRY GENERATOR
2 REM
10 DIM ADJ((5), VERB(2)
20 FOR I = 1 TO 5
30 READ ADJ(I), VERB(1), PREP(3)
130 FOR J = 1 TO 3
140 READ STRUCT(E))
300 LET F = VAL(MID(E), K, 1))
310 ON F GOSUB 330, 340, 350, 360
320 NEXT K
330 PRINT ADJ(B);: RETURN
350 PRINT VERB(D);: RETURN
370 END SUB
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
This program initializes a list of adjectives, nouns, and verbs in lines 20-160. Then it generates three random numbers for each line of the poem and picks words based on these random numbers from the arrays. Finally, it combines the words and prints the line of the poem. Repeat this process for three lines, creating a simple generated poem.
(5)20FORI=1TO530READADJ
(I),VERB
(A)+""+NOUN
The program now initializes the arrays using DATA-statements (lines 50-90) and READ instructions (lines 20-40). The rest of the program is unchanged, and it still prints a simple, randomly generated poem.
The program now randomly selects one of three possible sentence structures in every line of the poem. The basic structure is Adjective-Noun-Verb, the second one is Adjective-Noun-Verb-Preposition-Noun, and the third one is Noun-Verb-Adjective-Noun. This allows the program to generate more varied lines of poetry based on the pre-defined arrays.
Now the program reads the sentence structures from DATA-statements in lines 160, using numbers to represent parts of speech (1 for adjective, 2 for noun, 3 for verb, and 4 for preposition). The subroutine PRINTSTRUCT at line 280 takes care of printing the words of the poem according to the sentence structure identified by the number E. To add new sentence structures, you can simply update the arrays and DATA-statements.