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
Special Ordinals (Last
, Middle
, Any
, ...)
In addition to numeric ordinals, there are a number of “special ordinals” that can be used:
-
Any
selects an element at random from among all those of the indicated type. -
Middle
(orMid
) selects the element closest to the middle, based on the total number of chunk elements of that type. -
Last
(or its synonymsFinal
,End
, orUltimate
) selects the last chunk element (this is the same as specifying -1). -
Penultimate
selects the second-to-last chunk element (equivalent to specifying-2
orsecond-to-last
). -
Antepenultimate
selects the third-to-last chunk element (equivalent to specifying-3
orthird-to-last
). -
Preantepenultimate
selects the fourth-to-last chunk element (equivalent to specifying-4
or4th-to-last
). -
Propreantepenultimate
selects the fifth-to-last chunk element (equivalent to specifying-5
orfifth-to-last
).
Example:
put any item of "cow,ant,moose,goat,donkey,elephant" // selects one at random and displays it
Example:
get the middle character of "serendipity"
put it --> "d"