I don't want it all. I need just a bit of it. ( first, last, bf, bl, item )
Help Contents
Logo and Languages
I don't want it all. I need just a bit of it. ( first, last, bf, bl, item )
I don't want it all. I need just a bit of it. ( first, last, bf, bl, item )
Constructing words, lists and sets is a one-way process. To have the full power logo.eli teaches Elica not only how to build values, but also how to decompose them and to extract specific parts.
The action first asks Logo to extract the first elements of a value.
If the value is a word, then the result is a word of its first letters.
If the value is a list or a set then the result contains the first elements of the list or the set.
When extracting first elements, the default behaviour of Logo is to extract only the very first one.
If you want to extract more elements, you can force first to do so by simply adding one more argument containing the number of elements to extract.
print first "mint ; m
print (first "mint 2) ; mi
print first [a b f] ; a
print (first [a b f] 2) ; [a b]
make "myset first :myset
To make things symetrical, Logo knows not only how to extract the first elements, but how to extract the last elements with the function last.
print last "mint ; t
print (last [a b f]) ; [b f]
For convinience Logo also knows how to extract a part of a word, list or set when you define what part to ignore.
There are two functions for this: bf and bl that stand for butfirst and butlast.
What bf does is just to find all elements except the first one or more ones.
Similarily, bl returns all the elements except the last ones.
print bf "mint ; int
print (bl "mint 3) ; m
print (bf [a b f] 2) ; [f]
print bl [a b f] ; [a b]
make "myset (bf :myset 3)
All function for extractions described so far refer to elements with position relative the the begining or the end of something.
In some cases you will need to refer to a specific position - 4th, 10th, ith.
You can extract there elements by a wise use of first and bf, but Logo provides another useful function.
It is item and expects two arguments - the index of the element you want to extract, and the value from which you want to extract this element.
print item 3 [s c r e e n] ; r
print item 4 "clock ; c