Terrapin Resources
Taking Things Apart

FIRST     LAST     BUTFIRST     BUTLAST     ITEM     MEMBER     REMOVE

This section shows you how to use commands to take apart words and lists.


FIRST word
FIRST list


FIRST reports the first element of its input, which is either a word (which includes numbers) or a list.

FIRST 2025
Result: 2

FIRST DRAGON
Result: D

FIRST [SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY]
Result: SUNDAY

You can use MAKE (see the Putting Things Together section to learn how to use MAKE) if you want to store the result for future use.

MAKE "MONTH FIRST [JANUARY 31, 2025]
PRINT :MONTH
JANUARY

» Things to Try

Experiment with FIRST to see how it works.

What happens if you give FIRST an empty word (“) or list ([ ]) as input?


LAST word
LAST list


LAST is the opposite of FIRST. It reports the last item of its input.

LAST [GEORGE WASHINGTON]
Result: WASHINGTON

LAST "CITY
Result: Y

LAST [OF THE MOHICANS]
Result: MOHICANS

You can use MAKE (see the Putting Things Together section to learn how to use MAKE) if you want to store the result for future use.

MAKE "YEAR LAST [JANUARY 31, 2025]
PRINT :YEAR
2025

» Things to Try

Experiment with LAST to see how it works with different types of inputs.


BUTFIRST word-or-list
BF word-or-list


BUTFIRST reports everything but the first element of its input, which can be a word (including a number) or list,

BUTFIRST "HELLO
Result: ELLO

BUTFIRST "HELLO = BUTFIRST "JELLO
Result: ALSE

Did this result surprise you? Sometimes you need to use parentheses to keep key parts together.
The result was ALSE because Logo started by finding the BUTFIRST of the result of everything that followed.
It though you meant this:

BUTFIRST ("HELLO = BUTFIRST "JELLO)

Try this instead to make things clear:

(BUTFIRST "HELLO) = (BUTFIRST "JELLO)
Result: TRUE

This works much better! It never hurts to include parentheses, and sometimes they are required.

BUTFIRST 3.14159
Result: .14

Because the value of Logo’s built-in :PRECISION variable is 2, the result does not contain all the digits you specify.
To change the value, use MAKE "PRECISION 10. Now try BUTFIRST 3.14159 again.

BUTFIRST [FOUR SCORE AND SEVEN YEARS AGO]
Result: [SCORE AND SEVEN YEARS AGO.]

» Things to Try

Experiment with BUTFIRST using different types of inputs.

Remember, you can also use its abbreviation, BF.


BUTLAST word-or-list
BL word-or-list


BUTLAST reports everything but the first element of its input, which can be a word (including a number) or list,

BUTLAST "BYE
Result: BY

BUTLAST 12345678910
Result: 1234567891

BUTLAST [JANUARY 31, 2025]
Result: [JANUARY 31]

You can use MAKE (see the Putting Things Together section to learn how to use MAKE) if you want to store the result for future use.

MAKE "DATE BUTLAST [JANUARY 31, 2025]
PRINT :DATE
JANUARY 31,

But how do you remove the comman at the end of the date?

MAKE "DATE [JANUARY 31, 2025]
LIST FIRST :DATE BUTLAST LAST BUTLAST :DATE
Result: [JANUARY 31]

Do you see how that works?

FIRST :DATE is JANUARY
BUTLAST :DATE is [JANUARY 31,]
LAST BUTLAST :DATE is 31,
BUTLAST LAST BUTLAST :DATE is 31

So, you make list out of FIRST :DATE and BUTLAST LAST BUTLAST :DATE to get JANUARY 31.

Is your head spinning? Take a few minutes to think about how this actually works!

» Things to Try

Experiment with BUTFIRST using different types of inputs.

Remember, you can also use its abbreviation, BF.


ITEM number word
ITEM number list


ITEM reports a specified element of a word or list.

ITEM 1 is the first element of the word or list, which would be equivalent to using FIRST.

ITEM 1 "LOGO
Result: "L
FIRST "LOGO
Result: L

ITEM 3 "ABCDEFG
Result: C

ITEM 4 [SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY]
Result: WEDNESDAY

ITEM 7 ITEM 4 [SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY]
Result: D

In the last example, you are asking Logo to find the seventh element of the four element in the list. So, the seventh letter of WEDNESDAY is D.

» Things to Try

Remember that COUNT tells you how many letters are in a word or how many words in are in a list?
(Check out the Fun with Math section to learn more about COUNT.)

So, typing this:

ITEM COUNT [SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY] [SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY]

would be the same as typing LAST [SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY].

See how you can use ITEM in so many ways! It can be very useful.

You can use it in programs you write.


MEMBER? word-or-list1 word-or-list2
(MEMBER? word-or-list1 word-or-list2 TRUE)


`MEMBER? reports TRUE if the first input is an element of the second input.
It reports FALSE if it is not.

MEMBER? "K "PARAKEET
Result: TRUE

MEMBER? "PARAKEET [DOG CAT BIRD HAMSTER]
Result: FALSE

If you add TRUE as a third input to `MEMBER?” it checks sublists (a list within a list) in the second input, like this:

(MEMBER? "PIG [DOG CAT BIRD HAMSTER [GUINEA PIG]] TRUE)
Result: TRUE

» Things to Try

Experiment with MEMBER?

Think how you could use it in a program.


REMOVE word word
REMOVE word list
REMOVE list list


REMOVE reports the second input with all occurrences of the first input removed.

REMOVE "X "ABCDEFGHIJKLMNOPQRSTUVWXYZ
Result: ABCDEFGHIJKLMNOPQRSTUVWYZ

REMOVE "SNAKE [DOG CAT PARAKEET SNAKE FISH]
Result: [DOG CAT PARAKEET FISH]

REMOVE "| | "|Let's remove all the spaces in this sentence!|
Result: Let'sremoveallthespacesinthissentence!

» Things to Try

Experiment with REMOVE and think of how you could use it in programs you write.