| Description | Example |
|---|---|
| Constants (hardly structured!) | 3 "of" |
| Lists | "the,quick,jumped,dog" |
| Indexed elements | character i of WordForm |
put line i of bg fld j of card k into Holder
the fifth line of card field "Text" line 5 of cd fld text item 1 of line 3 of bg fld "DataList" char 14 of item 2 of word 2 of the name of this card word 2 of the short name of cd fld "My Name" word 2 of the name of cd btn 1
do statement 1 statement 2 statement 3 ... statement n enddoThe statements in a program which alter the order of execution of statements are called control statements and the use of them in a program is called flow control or control logic. conditional execution of statements
if condition then statement block else statement block end if
on mouseUp ask "Gender?" if it is "boy" then put "male" else if it is "girl" then put "female" else put "who knows!" end if end mouseUp
if ($line =~ /$exp/) {
print "$line matched: $& \n";
} else {
print "$line (pattern not found.)\n";
}
Usually, the syntax of a loop is something like:
set loop invariant loop while loop invariant is false do something reset loop invariant endloop
while ($line =) { chop($line); if ($line =~ /$exp/) { print "$line matched: $& \n"; } else { print "$line (pattern not found.)\n"; } }
on ExportCorpus ask file "Name of file to write" if it is empty then exit ExportCorpus put it into fn open file fn write bg fld "Corpus" to file fn close file fn end ExportCorpus
on ImportCorpus answer file "Name of file to load" of type text if it is empty then exit ImportCorpus else put it into fn end if put 0 into RecCount open file fn read from file fn until return repeat while it is not empty if char 1 of it = "#" then else put cleanup(it) into line RecCount of bg fld "Corpus" end if add 1 to RecCount read from file fn until return end repeat close file fn answer RecCount && "lines loaded." end ImportCorpus
function cleanup str -- remove trailing blanks. Assumes string STR has a CR at the end of it put empty into last char of str repeat while the last char of str = " " put empty into the last char of str end repeat return str
function Search target,source put offset(return & target & return,return & source & return) into ofs return (the number of lines in char 1 to ofs of source) end Search
on mouseUp -- get the possible palindrome put line 1 of cd fld 1 into p -- save a copy for later use put p into p2 -- delete punctuation etc. which might mess us up repeat with i = the number of characters in p down to 1 if " ,;.:'" contains char i of p then delete char i of p end if end repeat -- reverse the string put empty into p3 repeat with i = 1 to the number of characters in p put char i of p before p3 end repeat -- whew! hard part is over! answer p && p3 if p3 = p then put p2 && "is a palindrome" else put p2 && "is NOT a palindrome" end if end mouseUp