Knowing Your Equipment


As you embark on the journey of writing SenseTalk, there are a few basics you'll need to be familiar with. Here we cover some of the fundamental equipment you'll need, from text and lists to loops and conditionals.
Working with Text
SenseTalk's text handling abilities are extensive and extremely powerful, and at the same time very readable and people oriented.
Text operators include:
&for joining (concatenating) two strings&&for joining two strings with a space in betweencontains,is infor determining if one string contains anotherbegins with,ends withfor determining if a string begins or ends with anothermatchesfor determining if a string matches a given pattern
Chunk Expressions
SenseTalk's chunk expressions let you work with text in a natural way. A chunk expression can directly identify characters, words, items (delimited by commas, by default), or lines of text, either for accessing or modifying part of a string.
put characters 3 to 9 of acctNum into branchNum
put the first 3 chars of word 2 of "library catalog" --> "cat"
A chunk of a container is also a container, meaning that it can be modified by any command that operates on variables or other containers.
set text to "my flower are beautiful"
put "s" after word 2 of text
put text --> "my flowers are beautiful"
add 1 to the last item of line 7 of file "counters.txt"
Patterns
SenseTalk's pattern language provides all the capabilities of regular expressions, but in a readable way.
set sentence to "Please use addresses of the form 42.212.86.x"
put every occurrence of <1 to 3 digits, then "."> in sentence --> ["42.","212.","86."]
Working with Lists
Lists can be created directly in a script, using ( ), [ ], or { } with items separated by commas (but square brackets are strongly encouraged for consistency).
[]— an empty list[1,3,5]— a list of 3 numbers("dog", "cat", [x,y])— a list containing 2 strings and a nested sublist
Access individual items or sublists within a list by using the same syntax as for text chunks:
put item 4 of [a,b,c,d,e,f] --> d
put the last 3 items of of [a,b,c,d,e,f] --> [d,e,f]
In addition, SenseTalk supports ranges, which will generate values as needed when treated as a list:
set scoreRange to 101..1000
put item 4 of scoreRange --> 104
put the last 3 items of scoreRange --> [998,999,1000]
List commands include:
eachexpressions to extract or operate on selected items (see Each Expressions)insertfor adding or inserting items (don't useputfor this. See the Insert Command)pushandpopfor treating a list as a stack (see the Push Command and Pop Command)pushandpullfor treating a list as a queue (see the Pull Command)shuffledto randomize the order of a list (see the Shuffle Command)sortedto get a list sorted in a particular order (see the Sort Command)
List operators include:
&&&for concatenating two listscontainsoris infor testing whether a list contains a value or sublistunique itemsto get a list with duplicate values removedintersectionto get a list of values present in both of 2 listsunionto get a list of values present in either of 2 listsexcludingto get a list of values, leaving out those that are in another list
Important Global Properties
There are dozens of global properties which control various aspects of the runtime environment. For example:
the numberFormat— controls the format of displayed numbers, including the number of decimal places displayedthe defaultStringEncoding— controls the encoding used when reading and writing text filesthe assertionBehavior— controls whether a failed assertion will throw an exception, log a warning, log an error, or pause the script executionthe itemDelimiter— specifies the character(s) used as a delimiter between text items
All global properties must be preceded by the word the and may be changed at any time during script execution. Most will affect script operation until they are changed again, however some are considered "local" properties which will revert to their default value at the end of the current handler.
For more information, see Local and Global Properties.
Survival Tip: "The" Isn't Always Optional
When using of to access a property of an object or property list, or to call a function, the word the is optional:
put the length of "time" --> 4
put length of "time" --> 4
When calling a function with no parameters, the is required if () are not used.
put parameterList() --> displays the parameters
put the parameterList --> displays the parameters
put parameterList --> displays the variable "parameterList"