HyperTalk
HyperTalk is a discontinued high-level, procedural programming language created in 1987 by Dan Winkler and used in conjunction with Apple Computer's HyperCard hypermedia program by Bill Atkinson. Because the main target audience of HyperTalk was beginning programmers, HyperTalk programmers were usually called "authors" and the process of writing programs was known as "scripting". HyperTalk scripts resembled written English and used a logical structure similar to that of the Pascal programming language.
HyperTalk supported the basic control structures of procedural languages: repeat for/while/until, if/then/else, as well as function and message "handler" calls. Data types usually did not need to be specified by the programmer; conversion happened transparently in the background between strings and numbers. There were no classes or data structures in the traditional sense; in their place were special string literals, or "lists" of "items" delimited by commas. Code execution typically began as a response to an event such as a mouse click on a UI widget.
In the late 1980s, Apple considered using HyperCard's HyperTalk scripting language as the standard language across the company and within its classic Mac OS operating system, as well as for interprocess communication between Apple and non-Apple products. The company did not oppose the development of imitations like SuperCard, but it created the HyperTalk Standards Committee to avoid incompatibility between language variants. The case-insensitive language was initially interpreted, but gained just-in-time compilation with HyperCard 2.0.
Description
Fundamental operations
For most basic operations including mathematical computations, HyperTalk favored natural-language ordering of predicates over the ordering used in mathematical notation. For example, in HyperTalk'sput assignment command, the variable was placed at the end of the statement:put 5 * 4 into theResult
whereas in the more traditional BASIC programming language, the same would be accomplished by writing:
theResult = 5 * 4
The HyperTalk code has the side-effect of creating the variable theResult on the fly. Scripts could assign any type or value to a variable using the
put command, making HyperTalk very weakly typed. Conversions between variable types were invisible and automatic: the string "3" could be multiplied by the number 5 to produce the number 15, or the number 5 concatenated onto the string "3" to produce the string "35". HyperTalk would not complain unless the types could not be automatically converted.The language's flow control and logic were generally similar to other common languages, using an
if... then... else... end if structure for conditionals and supporting loops based on a flexible repeat... end repeat syntax. Comments were prefaced with two minus signs: -- this is a comment.Objects, containers and scripts
HyperCard's primary user interface concept was the card, a display system that emulated an index card. Cards were normally used to store information, similar to a record in a conventional flat-file database. The graphical layout of the card was created using the mouse by placing various elements on the card, such as text fields and buttons. A master layout "card" known as the background was shown behind the transparent areas of each card. Objects placed on the background, such as fields and buttons, would be shared as a common layout among several cards, but with card-specific content. The collection of cards, backgrounds and the associated data stored in them were stored in a single file known as the stack. Collectively, all of these data-containing objects are referred to as containers.HyperTalk functions, or scripts, were normally stored within the
script property available in many of the stack's containers. Scripts could access the properties of a container, corresponding to instance variables, using the get and set instructions. The script property held plain text and had no special properties; scripts could be placed in, and run from, any text container, including string variables, or imported from other stacks using the start using command. A script could even be user-provided text typed into an on-screen text field. Arbitrary text could be executed using the do command, in a manner similar to Dynamic SQL.Referring to containers
A key concept in HyperTalk was the way it referred to containers through a navigational system based on the visual hierarchy of the stack. Every container in the stack was given a unique ID number when created and could also be given an optional name. Scripts could refer to objects by using either of these identifiers, along with an object type specified using theof operator. This operator used a natural language syntax making for easily readable, self-documenting code. For instance, a script stored in a button on a card might wish to take user-supplied text gathered using a text field and store the text in a variable called theValue:put card field "typehere" into theValue
Various contextual aspects of statements could be inferred by the interpreter. In the statement above, for example, because the script would be running in the context of a button on a specific card, the identifier card was understood to refer to the card the user was interacting with, even though the button itself would normally be on the background. In addition, "the value" was assumed to be the main property and to be the target of operations if not otherwise specified. Likewise, "card field" was assumed to be the target of the command, as opposed to the background field, so that information could also be omitted. Even container types had short forms that programmers could use to save typing. Thus the code above is equivalent to the shorter form:
put fld "typehere" into theValue
Objects within a given context—the card or background, for instance—were also given a runtime number based on their z-order on the screen. To assist in using their position for navigation, HyperTalk also included a variety of ordinal and cardinal referencing systems to simplify the syntax further. Assuming the field "typehere" is the only field on the card, the code above could also be written:
put the first card field into theValue
The choice of addressing style was left to the programmer; often different styles were used in different statements depending on the style of the surrounding code in order to make the code more readable.
HyperTalk included the
me container which acted in the same fashion as the self qualifier found in most object-oriented languages, allowing simple access to the current container object. Less common was the it variable, which held the value of the last operation for certain built-in operators. For example:ask "What is the value?"
put it into card field "display"
This example uses the
ask command to display a dialog box and capture the text typed into an accompanying text field; when the dialog is completed by hitting or clicking, the value is assigned to the it pseudo-variable. The second line then copies that value into a card field using the put assignment operator.Collections
Containers of a given type were also available as collections with a pluralized version of that container type as its name—the collection of the fields on a card wascard fields. These collections were themselves containers with their own properties. Key among these was the number property which was widely used during iterations and similar tasks. For instance, if one wanted to hide all the fields on a card, this could be accomplished with this code:repeat with i = 1 to the number of card fields
hide field i
end repeat
This code exposes another common feature of HyperTalk: that a property might have several names and operators. In this case the
hide command, and the associated show, act by setting the value of the container's visible property. Thus hide field i is exactly equivalent to. A similar example was the lock screen command that stopped visual updating, which was a short form for, where lockscreen is a property of HyperCard itself—also a container. Many examples of this sort of syntactic sugar were found in HyperTalk, in order to simplify the syntax and improve readability of common code.In HyperCard 2.2 and later, the collection of collections was also available as a container's
parts. This allowed a script to address all of the objects in a container with a single iterator.Handling text
A notable feature of the HyperTalk container model was its handling of text. Every collection of text, whether a literal string in a program or text typed into a text field, was itself considered a container with multiple collections of containers within it. This allowed scripts to parse text using the same navigational commands as any other container. For instance, while parsing a space-delimited data file, one might want to extract the third column, like this:put the third word of theFilesText into colThree
This syntax allowed the script to "walk" down the text to find particular data, as in this example:
put the first character of the third word of line 5 of card field "sometext" into theChar
This process of treating text as a container was known as "chunking", and the functions as "chunk expressions". These same sorts of expressions were used to handle file manipulation, along with a set of file management functions. The following code opens a known file, reads from it, extracts data, and then closes the file:
on mouseDown
answer file "Please select a text file to open."
if it is empty then exit mouseDown
put it into filePath
if there is a file filePath then
open file filePath
read from file filePath until return
put it into cd fld "some field"
close file filePath
set the textStyle of character 1 to 10 of card field "some field" to bold
end if
end mouseDown
HyperTalk also included functions for chunking strings using a substring-find operation using the
in operator. The following code finds all examples of a given pattern using the in as part of the repeat loop, while offset finds the location of that pattern within the string:function replaceStr pattern,newStr,inStr
repeat while pattern is in inStr
put offset into pos
put newStr into character pos to -1 of inStr
end repeat
return inStr
end replaceStr