Terrapin Resources
Putting Things Together

WORD     LIST     SENTENCE     FPUT     LPUT

This section shows you how to use commands to put words and lists together.


WORD word1 word2
(WORD word1 word2 word3 ...)


You can combine two words into one word using WORD.

WORD reports a single word made up of its inputs, which must be words.
A word is a collection of numbers, letters, or punctuation marks with no spaces in it.

Here are some examples:

WORD "HI "!
Result: HI!

WORD "COW "GIRL
Result: COWGIRL

To use the result later, create a variable:

MAKE "COMPOUND.WORD WORD "COW "GIRL
PRINT :COMPOUND.WORD
COWGIRL

If you are using numbers, you don’t need to start the inputs with a quote mark.

MAKE "ODD WORD 135 79
PRINT :ODD
13579

Beware of this, though:

MAKE "EVEN WORD 2468 10
PRINT :EVEN
246810

If you want to combine many different words into one word, place the entire command in parentheses, like this:

(MAKE "LETTERS "A "B "C "D "E "F "G)
PRINT :LETTERS
ABCDEFG

» Things to Try

Create different words using WORD.

Try creating a word make up of numbers, letters, and symbols.


LIST word-or-list1 word-or-list1
(LIST word-or-list1 word-or-list1 word-or-list1 ...)


LIST is similar to WORD, but it accepts words or other lists as inputs.

A list is a set of words or other lists inside square brackets, like the ones you use for REPEAT.

In fact, the second input to REPEAT is a list of commands.

REPEAT 4 [FD 50 RT 90]

You could write the instruction this way and the turtle will still draw a square:

REPEAT 4 (LIST "FD 50 "RT 90)

A list can contain another list, like this:

PRINT [DOG CAT BIRD [GUINEA PIG]]

Keeping both words for guinea pig together in a list keeps them from being separated.

MAKE "PETS [DOG CAT BIRD [GUINEA PIG]]
PRINT ITEM 1 :PETS
DOG
PRINT ITEM 4 :PETS
GUINEA PIG

Typing this:   MAKE "PETS [DOG CAT BIRD [GUINEA PIG]]

is the same as typing this:   MAKE "PETS LIST "DOG "CAT "BIRD [GUINEA PIG]

» Things to Try

Try creating different lists, using both words and other lists.


SENTENCE word-or-list1 word-or-list2
(SE word-or-list1 word-or-list2 word-or-list3 ...)


SENTENCE reports a list made up of its inputs. SENTENCE looks for two inputs, but you can use more if it and all of its inputs are enclosed in parentheses. If the inputs to SENTENCE are lists, their brackets are removed and combined into one list.

PRINT SENTENCE "SUNDAY "MONDAY
SUNDAY MONDAY

PRINT (SENTENCE "SUNDAY "MONDAY "TUESDAY "WEDNESDAY "THURSDAY "FRIDAY "SATURDAY)
SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY

PRINT SENTENCE [HUMPTY DUMPTY SAT ON A WALL.] [HUMPTY DUMPTY HAD A GREAT FALL.]
HUMPTY DUMPTY SAT ON A WALL. HUMPTY DUMPTY HAD A GREAT FALL.

How you could use SENTENCE in a program? Think of this conversation.

WHAT IS YOUR FAVORITE FLAVOR OF ICE CREAM?
VANILLA
VANILLA IS MY FAVORITE, TOO!

WHAT IS YOUR FAVORITE FLAVOR OF ICE CREAM?
CHOCOLATE CHIP
CHOCOLATE CHIP IS MY FAVORITE, TOO!

You don’t know in advance if the person will type a one-word flavor or more than one word.

Think about how you might write a program that would look like this. One solution is in the “Things to Try” section below.

» Things to Try

Here is one way to write a program that asks a person what their favorite ice cream flavor is and then agrees with them.

TO FLAVORS
PRINT [WHAT IS YOUR FAVORITE FLAVOR OF ICE CREAM?]
MAKE "FLAVOR READLIST
PRINT SENTENCE :FLAVOR [IS MY FAVORITE, TOO!]
END

Try it out. Does it work regardless of the number of words the user types?

READLIST is used to accept more than one word. For more information, refer to the Getting User Input section.


FPUT word word
FPUT word list
FPUT list list


FPUT reports the result of placing the first input at the beginning of the second input.
If both inputs are words, the result is a word.

FPUT "MON "DAY
Result: MONDAY

FPUT PICK [PL SK R] "ATE
Result: SKATE ; or it might be PLATE or RATE

If the inputs are either a word and a list or two lists, the result is a list.

FPUT "VANILLA [ICE CREAM]
Result: [VANILLA ICE CREAM]

FPUT [SANTA FE] [NEW MEXICO]
Result: [[SANTA FE] NEW MEXICO]

» Things to Try

Experiment with FPUT to understand how it works.

Use MAKE to create a variable with the result and think of ways to use FPUT in programs you write.


LPUT word word
LPUT word list
LPUT list list


LPUT reports the result of placing the first input after the second input.
If both inputs are words, the result is a word.

LPUT "MON "DAY
Result: DAYMON

LPUT "AST PICK [L P M F] "
Result: FAST ; or it might be LAST or PAST or MAST

If the inputs are either a word and a list or two lists, the result is a list.

LPUT "OWL [GREAT HORNED]
Result: [GREAT HORNED OWL]

LPUT [45 75 10] [15 25 35]
Result: [15 25 35 [45 75 10]]

» Things to Try

Experiment with LPUT to understand how it works.

Use MAKE to create a variable with the result and think of ways to use LPUT in programs you write.