SenseTalk | |
Paradigm: | People Oriented Programming, Multi-paradigm, Object-oriented |
Family: | Scripting language |
Typing: | Duck |
Designer: | Douglas Simons |
Influenced By: | xTalk, HyperTalk |
Developer: | Eggplant (software) |
Latest Release Version: | 2.18 |
License: | Proprietary |
SenseTalk is a high-level English-like scripting language in the XTalk family, that supports both procedural and object-oriented paradigms. SenseTalk scripts are intended to be largely readable by ordinary people, including those with little to no training in programming.
To this end, SenseTalk includes a number of language elements that provide functionality oriented towards human tasks rather than the underlying machine behavior. For example, to check whether a quantity is divisible by 3, the script could use the expression or, with the emphasis being on readability and a focus on the human concept of divisibility. [1] Compare this to more traditional programming languages (C, Java, Python, etc.) where the same test would typically be written as, with the focus being on the machine operations needed to determine the result. [2]
This shift in focus away from the underlying machine computation, towards an English-like description of the behavior in human terms leads to the description of SenseTalk as a “People Oriented Programming language”. [3]
As a self-styled “People Oriented Programming” language, certain aspects of SenseTalk’s design distinguish it from other programming languages, and give it a distinctive flavor. These range from mundane characteristics such as case insensitivity, to syntactic elements that enhance readability, to more subtle characteristics such as fluid variable types, to advanced features like units and the SenseTalk Pattern Language.
SenseTalk keywords and variable names are all case-insensitive. This allows people to be casual in their use of capitalization without any change of behavior.
This is also true of the names of properties in a property list (SenseTalk’s name for a dictionary or hash table).
In addition, text operations, including comparisons, searches, and so forth, are case-insensitive by default, although they can be made case-sensitive when needed.
In addition to having case-insensitive names, variables in SenseTalk are unusual in some other respects. Variables don’t need to be declared, and are typeless. A variable comes into existence when it is first used, and its type depends on the type of value that is stored in it.
This flexibility goes beyond the “duck typing” found in other languages, in which a given variable has a type which is established when a value is assigned to the variable. In SenseTalk, a variable is considered a “container” that may contain any type of value. The type of value a variable contains can change during a script run, so the same variable may start off containing a number, then later a string, and then a list of values. This “type fluidity” allows people to work in a very flexible way, manipulating values at will, and treating each value according to how it is being used at a given point in the script.
One consequence of SenseTalk’s typeless variables is that, in general, there are no “overloaded” operators — that is, operators which perform different operations depending on the type of variable they are working with. For example, in some languages, the operator will perform addition when it is used with numeric operands, and will perform string concatenation when it is used with string operands. In SenseTalk, operands are all fluid, so it is necessary to have one operator to perform addition (which will treat its operands as numbers), and another operator for string concatenation (which will treat its operands as strings).
In this example, the operator has higher priority than the operator, so the expression is equivalent to '(1 + 2) & (3 + 4)' or '3 & 7' giving “37”. If parentheses were used to perform the operator first, then '1 + (2 & 3) + 4' would become 1 + “23” + 4 giving a result of 28.
SenseTalk includes hundreds of “predefined variables”. These are variable names which can be used as ordinary variables, but which start off with a predefined value if they are used without first storing a value into them. Some of the predefined values are numbers, such as pi or zero. Many are special characters or symbols, such as euroSign, copyrightSign or hotBeverage. And a few have other types of values, such as jsonListFormat, which is a property list containing several key/value pairs that can be used for setting the listFormat global property.
Any variable that doesn’t have a predefined value, and hasn't yet been explicitly assigned a value, will evaluate either as its own name or as empty depending on the context where it is used. This allows words to be used unquoted in many cases where quotes would otherwise be required.
SenseTalk includes full support for many different types of units (length, mass, time duration, volume, frequency, etc.). Numeric values may have associated units. Unit values are converted as needed when performing arithmetic operations.
Variables may contain values with units. The units are carried along with the value and applied in subsequent calculations.
More complex units such as velocity (miles per hour, or meters/second) or acceleration (m/s^2) are also supported.
SenseTalk recognizes dates and times in a wide variety of formats, and supports date and time calculations.
Date/time values can be stored in variables, and formats are maintained through calculations.
Add 4 weeks to nextDateput nextDate --> displays "2021-04-01"
Add 4 months to nextDateput nextDate --> displays “2021-08-01”
SenseTalk’s chunk expressions come from its heritage as a member of the XTalk family of languages derived from HyperTalk. Chunk expressions allow working with chunks of text using familiar English terms: characters, words, items, lines. SenseTalk expands upon the original chunk syntax, and extends their use beyond text, to items within a list and bytes within binary data as well.
Chunk expressions can also be used to modify values. In Xtalk language terminology, a chunk of a container (such as a variable) is also a container, so any command that changes the value of a container can also be used to change a chunk.
Put “bump” into characters 7 to 12 of funnyName
put funnyName --> displays “Rumpelbumpkin”
SenseTalk includes commands for opening, reading, and writing files. A text file can be treated as a container (like a variable), so the file contents can be read by simply putting the file into a variable. Similarly, writing a file can be accomplished by putting a variable or other expression into the file.
Put "Miriam,219 Sparrow Ln,Freeburgh,MA" & return after addresses
Put addresses into file "/tmp/addressList.txt"
Because a file is a container, any command that modifies a container can be used directly on a file.
Accessing records in a database is more complex than reading a file, but SenseTalk applies the concept of containers here, too. This makes it possible to connect to a database and update a field in a specific record with very little code.
Put table “subscriptions” of custDB into subs -- makes connection to a DB table
Add 12 months to expDate of the record of subs where CustNum is “83946-d” -- updates a value in a particular record
SenseTalk’s “pattern language”[4] implements regular expressions using a readable, English-like syntax. The following example creates a pattern to identify an American Social Security number (like “999-99-9999”):
Patterns can be used in a variety of ways.
The pattern language allows patterns to be built up from other patterns. This example uses the previous ssnPattern to define a pattern that will avoid matching in cases where the immediately preceding or following character is also a digit:
The SenseTalk language first appeared in 1992 as the scripting language in HyperSense, a multimedia authoring application for the NeXTSTEP platform, modeled after HyperCard. At that time the language was little more than a copy of HyperCard's HyperTalk language. A more ambitious rethinking and redesign of the language resulted in the beginnings of the present language, with version 0.02 shipping as the scripting language in Eggplant V1.0 in 2002. The language has continued to grow and evolve, with such enhancements as the addition of support for: