Jump to content

SenseTalk

From Wikipedia, the free encyclopedia
SenseTalk
ParadigmPeople Oriented Programming, Multi-paradigm, Object-oriented
FamilyScripting language
Designed byDouglas Simons
DeveloperEggplant (software)
First appeared1992; 32 years ago (1992)
Stable release
2.18 / June 2024; 6 months ago (2024-06)
Typing disciplineDuck
LicenseProprietary
Filename extensions
  • .script
  • .st
Websitewww.sensetalk.com
Influenced by
xTalk, HyperTalk

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 if quantity is divisible by 3 or if quantity is a multiple of 3 , 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 if (quantity % 3) == 0 , 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]

Distinctive Characteristics

[edit]

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.

Case-insensitive

[edit]

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.

Put 12 Into Apples
put 5 into Bananas
PUT "Total Pieces of Fruit: " & apples+bananas --> displays "Total Pieces of Fruit: 17"

This is also true of the names of properties in a property list (SenseTalk’s name for a dictionary or hash table).

Put {Name:"Green", HexCode:"#00FF00"} into AColor
put aColor's name --> displays "Green"
put the HEXcode of acolor --> displays "#00FF00"

In addition, text operations, including comparisons, searches, and so forth, are case-insensitive by default, although they can be made case-sensitive when needed.

Set name to "McMaster"
put name contains "master" --> displays True (case is ignored)
put name contains "master" considering case --> displays False

Fluid Types

[edit]

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).

Put 1 + 2 & 3 + 4 --> displays 37

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.

Predefined Variables

[edit]

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.

Put "Area of a circle with radius 5 is: " & pi * 5 squared

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.

Put CookieCount --> displays "CookieCount"
Add 3 dozen to CookieCount --> treated as empty, or 0
put CookieCount --> displays 36

Units

[edit]

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.

Put 5 yds + 2 ft --> displays 17 feet

Variables may contain values with units. The units are carried along with the value and applied in subsequent calculations.

Put 5 yds into length
add 2 ft to length -- the value in length is converted to a compatible unit to perform the addition
put length --> displays 17 feet
put 42 inches into width
set area to length * width
put area --> displays 59.5 square feet

More complex units such as velocity (miles per hour, or meters/second) or acceleration (m/s^2) are also supported.


Dates

[edit]

SenseTalk recognizes dates and times in a wide variety of formats, and supports date and time calculations.

Put "8:22" - "8:15" --> displays 420 seconds

Date/time values can be stored in variables, and formats are maintained through calculations.

Put "March 3" + 34 days --> displays "April 6"
Put "2021-03-04" into nextDate

Add 4 weeks to nextDate
put nextDate --> displays "2021-04-01"

Add 4 months to nextDate
put nextDate --> displays “2021-08-01”


Chunk Expressions

[edit]

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.

Put characters 7 to 11 of "Rumpelstiltskin" --> displays" stilt"
Put the first 3 chars of the second word of book catalog --> displays “cat”

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 "Rumpelstiltskin" into funnyName

Put bump into characters 7 to 12 of funnyName

put funnyName --> displays “Rumpelbumpkin”


Files

[edit]

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 file "/tmp/addressList.txt" into addresses

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.

Put return & "Earlybird,12 Elm St,Vista,NM" after line 1 of file "/tmp/addressList.txt"

Databases

[edit]

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 {type:ODBC, DSN:customers, user:admin, password:sEcrEt} into custDB

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


Pattern Language

[edit]

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”):

Set ssnPattern to <3 digits then dash then 2 digits then dash then 4 digits>

Patterns can be used in a variety of ways.

if userEntry matches ssnPattern then set validSSN to true
put every occurrence of ssnPattern in file userData into ssnList
if clientInfo doesnt contain ssnPattern then put  <SSN missing> after clientInfo


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:

set isolatedSSN to <ssnPattern not preceded by digit, not followed by digit>


History

[edit]

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:

  • each expressions (similar to "list comprehensions" in other languages) in V1.26 (2007)
  • tree data structures (native XML support) in V1.30 (2008)
  • iterators in V1.36 (2008)
  • ranges in V1.38 (2009)
  • direct support for HTTP and XML-RPC in V1.53 (2012)
  • SQL databases in V1.63 (2013)
  • units in V1.67 (in 2014)
  • the SenseTalk Pattern Language (readable regular expressions) in V1.81 (2018)
  • date formats with readable tokens in V1.91 (2019)
  • multi-case if statements in V2.00 (2020)
  • every expressions; use of each expressions for containers in V2.04 (2021)

References

[edit]
  1. ^ "SenseTalk Mathematical Operators".
  2. ^ "Check for divisibility in Python".
  3. ^ "People Oriented Programming".
  4. ^ "SenseTalk Pattern Language".
[edit]