メインコンテンツまでスキップ
バージョン:23.5

SenseTalk Travel Guide

A Guidebook for Experienced Coders

SenseTalk is an "intuitive scripting language" — which is great for people new to programming, but may be disorienting (and at times even counter-intuitive) for people — perhaps you — who already know another language.

The ExpeditionThe Expedition: To cross the borders into this new territory and master the language well enough to be able to converse comfortably with the natives.
The ExplorerThe Explorer: You, an experienced traveler in other languages, well equipped with the latest coding skills and tools. You expect to quickly be speaking the lingo, but troubles await…
The ChallengeThe Challenge: SenseTalk presents new and unfamiliar terrain. Familiar operations are accomplished in unfamiliar ways. Your mastery of programming concepts is a tremendous asset, but some of the specific skills and techniques you've learned with other languages may actually hold you back. Some of your ingrained assumptions could mislead you down the wrong path toward a slippery slope that will tumble you into the ravine of frustration.
Emergency SuppliesEmergency Supplies: Our aim is to get you up to speed quickly, and point out some of the pitfalls and peculiarities that may get in your way. We'll try to guide you safely along the path to the summit.
Base CampBase Camp: We provide hints here to point you in the right direction. For the complete map of the territory, be sure to refer to the documentation.
Survival Tip

Things Are Different Here

Be alert for the unexpected, and come back to this guide whenever you need to.

Lay of the Land

Before embarking on your adventure it is helpful to have a rough idea of where you'll be traveling.

The natives here speak a strange dialect of English. That should be helpful since you may speak English conversationally at home … but never when you're traveling in the lands of code! So it may feel like a foreign language in these parts. Learn the basics of the SenseTalk dialect, though, and you'll get along just fine — for example, statements are all imperative commands that begin with a verb, each on a separate line:

sort myList
add 1 to total
delete line 3 of text

Keep in mind that SenseTalk is a People Oriented Programming language. The emphasis is on making it easy for ordinary people to accomplish a task, but what's intuitive for "people" may at times feel counterintuitive to you as an experienced coder. So relax your assumptions and shift your thinking to see it from the "people" perspective and you'll have an easier time getting along with the locals.

Things mean what they do in the world. A percent sign means percent. Quoted literal strings are exactly as they appear: "\n" is a two-character string containing a backslash and an 'n', not a newline (but see below, if you really must have escape sequences).

Survival Tip

String Literals Are Actually Literal

The string "ABC\n123" has 8 characters, and characters 4 and 5 are "\" and "n". If you want a string with "ABC" on one line and "123" on the next, that can be done in several ways:

String concatenation (&):

set text to "ABC" & return & "123"

String concatenation with embedded space (&&):

set text to "ABC" && "123" -- (ok, there's no return in this example)

Use "!" before a literal to evaluate embedded expressions in double square brackets:

set text to !"ABC[[return]]123"

Use block quoted string literals:

set text to {{
ABC
123
}}

And if you need familiar escape sequences, "@" before the string will do it:

 set text to @"ABC\n123" -- text now contains 2 lines

SenseTalk is very easy-going and forgiving. Accessing characters beyond the end of a string, or list items at an index greater than the number of items in the list is not considered an error — they simply return an empty value. The language is not case sensitive, and there are very few restricted keywords.

SenseTalk is also very dynamic. The type of a variable depends on the value it contains, which can change from one line to the next. A number can be used as a string, and a string as a date, depending on the context. Commands and functions can be called with any number of parameters, regardless of how they are defined.

SenseTalk is highly contextual. The same word can have different meanings depending on the context where it is used. There are very few restricted keywords. Most words can be used as variable names even if they are also the name of a command, operator, function, or property.

Survival Tip

Survey the Path Ahead

Because SenseTalk is very English-like, it can sometimes lead you down the wrong path. When you enter a syntactically-valid command it will colorize, letting you know the syntax is recognized. But once in a while the meaning it recognizes may be different from the one you intended. So it is wise to play with it, by running a command or a short sequence of code to be sure it's doing what you expect.

First Essentials / Basic Equipment

SenseTalk statements all begin with a command (verb) and end at the end of a line, without any terminating punctuation. There is only one command per line.

Display a value with the put command:

put "Hello World!"
--> Hello World!

put 2+3*4
--> 14

Assign a value to a variable with either the put … into or set … to commands:

put 7 into x
set y to 9
put x*y
--> 63

Variables don't need to be declared. Variable names are not case sensitive: total, Total, and TOTAL are all the same variable.

Variables are typeless. Any variable can hold any type of value, and may hold different types of values at different times.

Types of Values: numbers, strings, dates, colors, binary data, lists, ranges, property lists, trees (XML), patterns (regex).

Numbers:
-17.8
forty-two
12e6
0x7F
a million
1_000_000

Strings:
"abc"
<<Say "Hi"!>>
@"Hello\nWorld"
!"The circumference is [[2*pi*radius]]"

{{
Hello
World!
}}
ノート

An @ before a string literal evaluates backslash escapes; ! before a string evaluates embedded expressions enclosed in [[ ]]

Dates/Times:
"2020-03-13" as date
date("April 3, 1955")
"8:30 PM" as time
"January 8, 2020 13:08:56".time

ノート

Strings are also implicitly interpreted as date/time values in some contexts, without needing to specify 'as date' etc.

Colors:
color(purple)
"#00FF77".color
[127, 0, 255] as color
color("W,0.2")

Binary data:
<48656C6C6F>

Lists:
[1,2,3]
["a", 27, "cat"]
[foo, bar, [1,2,3], 97]
[]

Ranges:
1..99
50 to 100 by 5
"a".."z"
"May 5" to "June 3"

Property lists:
{x:22, y:47}
{name:"Bob", age:101, luckyNumbers:[12,33,88]}

Patterns:
<3 digits, "-", 2 digits, "-", 4 digits>
<"(", one or more characters, ")">

ノート

Lists and Property Lists can be written with any type of bracket — ( ), [ ], or { } — but [ ] are recommended for lists, and { } for property lists for readability, and compatibility with JSON and other formats.

Trees (not shown above, because they don't have a direct literal format within a script) are complex structures that combine the functionality of both Lists and Property Lists. They are displayed in text form as XML, and can be created from either XML text or from an appropriate property list using the Tree() or DocumentTree() functions.

All loops use repeat … end repeat . There are many types of repeat loops.

Conditional blocks are written using if … then … else … end if (or if … then … else with single statements all on one line). Multi-case if statements provide the functionality of switch/case statements in other languages, in a clear and readable way.

Some Key Terms To Be Familiar With

There are a number of key terms in SenseTalk you will want to be familiar with. A few of them are covered below.

empty

When something doesn't have a value, it is empty. The word empty is a constant whose value is "" — an empty string containing no characters. In SenseTalk, empty is used a lot, in situations where other languages might use null or nil or throw an exception. It is the value that is usually returned any time there is no value to return from a function or expression. For example, these expressions will all result in an empty value:

        character 9 of "hello"
        item 6 of [1,3,5,9]
        property "age" of {name:"Fred", occupation:"Zookeeper"}

put

There are 4 forms of put command. The generic put command with one or more parameters will display the value of each of its parameters on separate lines (put with no parameters will display a blank line). The put into command assigns a value to a variable. The put after command appends a string at the end of an existing string value, and put before prepends a string at the beginning of a value.

set

The set command will also assign a value to a variable or other container.

insert

The insert command is used to add values to a list.

the

The word the is required in some situations (to access a global property, and in some function calls), and optional in others (function calls and property access along with the word of).

it

The variable it is assigned a value automatically in a number of situations. This is similar to $_ in perl.

return

The term return is a constant whose value is a newline (or linefeed) character. Return is also a command used to return a value from a function.

each

Within a sort expression or within an each expression, the variable each takes on the value of each item being sorted or iterated in turn.

item

The term item refers to an item in a list. When applied to a value that is not a list, it refers to a text item delimited by commas (or by whatever the itemDelimiter is set to). Typically this works well, but to avoid any possible ambiguity you may use the terms list item and text item explicitly.