Chunk Syntax
Single Chunks
Syntax:
chunk number of expression
In this and the following syntax descriptions, chunk is used to represent any of the chunk types: character
(or its abbreviation, char
), word
, line
, item
, text item
, or list item
. Similarly, chunks represents the plural version of these terms. number is a factor which evaluates to a positive or negative number, and expression is the source or destination value which the chunk refers to. Wherever the word "of" is shown, you may use either “of” or “in”, whichever seems natural to you at the time.
Chunk expressions for all types of chunks can be expressed in several different ways. You can describe a single chunk element:
put item 17 of scores into quiz3
put word 4 of "Mary had a little lamb" --> "little"
Negative numbers can be used to count backwards from the end of the source, with -1 indicating the last chunk element, -2 for the next-to-last, and so forth:
put item -2 of "apple,banana,pear,orange" --> "pear"
Ordinal Chunks
Syntax:
{the} ordinal chunk of expression
Chunk elements can also be referred to by their ordinal number (first
, second
, ... , millionth
, or 1st
, 2nd
, ... , 1000000th
):
get the third item of [9,12,13,42]
put it --> 13
You can use the form ordinal-to-last to count back from the end of the value (instead of using a negative number):
get the third-to-last item of [9,12,13,42]
put it --> 12