HyperTalk

Last updated
HyperTalk
Paradigm procedural, event-driven
Designed by Dan Winkler
Developer Apple Computer Inc.
First appeared1987 (1987)
Influenced by
Natural language programming, Pascal
Influenced
ActionScript, AppleScript, ECMAScript, JavaScript, Lingo, LiveCode, SenseTalk, SuperTalk

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.

Contents

HyperTalk supported the basic control structures of procedural languages: repeat for/while/until, if/then/else, as well as function and message "handler" calls (a function handler was a subroutine and a message handler a procedure). 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 (in later versions the "itemDelimiter" property allowed choosing an arbitrary character). 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 [1] 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. [1] The case-insensitive language was initially interpreted, but gained just-in-time compilation with HyperCard 2.0. [2]

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's put assignment command, the variable was placed at the end of the statement:

put5*4intotheResult

whereas in the more traditional BASIC programming language (and most others), 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 (of cards). 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, [lower-alpha 1] 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. [3]

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 the of 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:

putthevalueofcardfield"typehere"intotheValue

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" (the text submitted by the user) 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:

putfld"typehere"intotheValue

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:

putthefirstcardfieldintotheValue

or:

putcardfield1intotheValue

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?"putitintocardfield"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 Return or clicking OK, 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 was card 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:

repeatwithi=1tothenumberofcardfieldshidefieldiendrepeat

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 setthevisibleoffielditofalse. A similar example was the lock screen command that stopped visual updating, which was a short form for setthelockscreentotrue, 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:

putthethirdwordoftheFilesTextintocolThree

This syntax allowed the script to "walk" down the text to find particular data, as in this example:

putthefirstcharacterofthethirdwordofline5ofcardfield"sometext"intotheChar

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:

onmouseDownanswerfile"Please select a text file to open."ifitisemptythenexitmouseDownputitintofilePathifthereisafilefilePaththenopenfilefilePathreadfromfilefilePathuntilreturnputitintocdfld"some field"closefilefilePathsetthetextStyleofcharacter1to10ofcardfield"some field"toboldendifendmouseDown

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:

functionreplaceStrpattern,newStr,inStrrepeatwhilepatternis ininStrputoffset(pattern,inStr)intoposputnewStrintocharacterposto(pos+thelengthofpattern)-1ofinStrendrepeatreturninStrendreplaceStr

Lists and other collections

HyperTalk used the same chunking system to produce structures like arrays or lists. Such a structure would be created by placing multiple data items in a variable, separated by commas. Various types of data could be imported into a HyperTalk script using strings that would get parsed as required. For instance, the position of objects on the screen was defined by a pair of numbers representing the X and Y coordinates relative to the upper left corner. The following code creates a variable called pos that holds a coordinate pair, and then manipulates this to re-position all of the buttons on a card in a diagonal from top-left to bottom-right:

onmouseUpput"100,100"intoposrepeatwithx=1tothenumberofcardbuttonssetthelocationofcardbuttonxtoposadd15toitem1ofposendrepeatendmouseUp

The item chunking expression was originally based on a comma delimiter, but later versions of HyperCard changed this to the value of itemDelimiter, offering the ability to parse arbitrary lists and structures.

Messages and events

HyperTalk used an object-oriented concept for calling scripts, with objects in the stack sending "events" as messages that would be processed by handlers that declared their interest in receiving the events using the on syntax. For instance, most GUI containers would send the mouseDown message when the mouse button was clicked down, and then a mouseUp message when it was released while still on top of that container, and a script could capture these events like this:

onmouseUp-- place additional code hereendmouseUp

Messages for events were first sent to the script in the object that created the event, for instance, if the user clicked on a button the mouseUp message was first sent to that button. If the button's script object did not have a mouseUp handler (or no script at all), it was then passed to the card, the background, the stack, any stacks whose scripts had been explicitly imported using the start using command, the "home stack" (a user-selected always-open HyperCard stack), and finally to the HyperCard application itself.

For many simple events like mouse clicks on buttons the script would be placed directly within the object in question, the button itself. For instance, one might use the example code above within a button handler in this fashion:

onmouseUprepeatwithi=1tothenumberofcardfieldshidefieldiendrepeatendmouseUp

In the case where code was being called from multiple locations, or it was being used as a global handler for an event, the script could determine the original sender of the event using the target function. Likewise, scripts could send events to other containers using the send command and then using the navigational code to refer to the container holding that handler's code:

send"mouseUp"tocardbutton"OK"ofcard"Veracity"

Combining HyperTalk's string processing with the do command allowed for the construction of interactive interpreters by placing a text field on a card and then placing this code in the field's script:

onmouseUpselecttheclickLineputword2oftheclickLineintolinenumdolinelinenumofcdfld1endmouseUp

clickLine is a global property that returns the name and line number of the last field clicked, in a form like line10ofcardfield4. This code first selects all of the text on the clicked line, then extracts the line number into a local variable, then uses do to run the text as a HyperCard script.

The mouseDown message was sent to a button when the user clicked it, and mouseUp was sent when the user released the mouse inside it to trigger its action. Similarly, HyperCard sent periodic idle message, mouseEnter, mouseLeave, ... and various other messages related to navigation between different cards in a HyperCard stack, as well as user input (keyDown, functionKey, ...), and system events. As far as the scripters were concerned, there were no main event loops like in other procedural programming languages.

Controlling HyperCard

Unlike general rapid application development platforms, HyperCard stacks always looked like stacks - the menu bar was HyperCard's and not the programmer's (by default—scripting could add, delete and modify menus), the single window was a fixed size (in early versions), and in certain cases, commands that were central to the operation were part of the application itself, and not directly available in HyperTalk itself.

A good example of this was the creation of new cards, which was part of the application, not directly accessible from the HyperTalk language itself. A new card could only be created using the New Card menu item, which could be simulated in code usingdoMenu "New Card". While HyperTalk called into menu commands, menu commands also invoked handlers in HyperTalk. To run custom code when the Copy menu item was selected, one would place a script in the stack using the on doMenu itemName handler, and then examine itemName to see if it was "Copy".

HyperTalk also provided script control over the built-in drawing tools, simply by scripting the needed changes in paint tools and simulating mouse movements using the drag from start to end and the click at position commands.

Forgiving semantics

One unique distinction between HyperCard's programming language HyperTalk and seemingly similar languages like AppleScript was that HyperTalk scripts were more lenient in what input they accepted.

Apart from the above implicit declaration of variables when a value was assigned to them, and the way values were implicitly converted between types (allowing you to e.g. ask for character 2 of 1234), HyperCard would also recognize certain expressions and extract sub-values from them.

For example:

puttheselectedLineofcardfield"Listbox"intotheSelection-- gives 'line 2 to 3 of card field "Listbox"'selectline1ofcardfield"Listbox"selectline(word2oftheSelection)ofcardfield"Listbox"select(theselectedLineofcardfield"Listbox")-- parentheses added for illustrative purposes only

or

playharpsichordcegplayharpsichord"c e g"put"c e g"intotheMelodyplayharpsichordtheMelody

While the end result felt similar to scripters as a Bash script's expansion of variables before parsing, this was special-case syntax and did not have the pitfalls where data would be evaluated as code. So for example, all of the following are syntax errors in the melody, not function calls:

playharpsichord"c e g()"put"c e() g"intotheMelodyplayharpsichordtheMelody

Extending HyperTalk

Although the HyperTalk language languished just like HyperCard itself, it interest was revived through its plugin protocol, so-called External Commands (XCMDs) and External Functions (XFCNs), which were native code containers attached to stacks (as Macintosh-specific resources) with a single entry point and return value. XCMDs and XFCNs could be called just like regular message and function handlers from HyperTalk scripts, and were also able to send messages back to the HyperCard application. Some XCMD authors added advanced features like full color support (ColorizeHC, HyperTint, AddColor), multiple special-purpose windows (Prompt, Tabloid, Textoid, Listoid, ShowDialog, MegaWindows), drag and drop support and various hardware interfaces to the language.

Descendants of HyperTalk

Various scripting languages have implemented a superset of HyperTalk (collectively known as xTalk): [4]

These clones and dialects (commonly referred to under the moniker of xTalk-languages) added various features to the language that are expected from a modern programming language, like exception handling, user-defined object properties, timers, multi-threading and even user-defined objects.

There are also languages whose syntax and structure show influences from HyperTalk, such as:

Many method names first popularized by HyperTalk have been incorporated into later languages, such as the onmouseup event handler in JavaScript. [6] Although Asymetrix ToolBook is often also considered a HyperCard clone, its scripting language apparently bears little resemblance to HyperTalk.

See also

Notes

  1. Which, in turn, could be loaded from text files.

Related Research Articles

<span class="mw-page-title-main">HyperCard</span> Hypermedia system for Apple Macintosh and Apple IIGS computers

HyperCard is a software application and development kit for Apple Macintosh and Apple IIGS computers. It is among the first successful hypermedia systems predating the World Wide Web.

<span class="mw-page-title-main">Curl (programming language)</span>

Curl is a reflective object-oriented programming language for interactive web applications, whose goal is to provide a smoother transition between content formatting and computer programming. It makes it possible to embed complex objects in simple documents without needing to switch between programming languages or development platforms. The Curl implementation initially consisted of an interpreter only; a compiler was added later.

In programming languages, a closure, also lexical closure or function closure, is a technique for implementing lexically scoped name binding in a language with first-class functions. Operationally, a closure is a record storing a function together with an environment. The environment is a mapping associating each free variable of the function with the value or reference to which the name was bound when the closure was created. Unlike a plain function, a closure allows the function to access those captured variables through the closure's copies of their values or references, even when the function is invoked outside their scope.

AppleScript is a scripting language created by Apple Inc. that facilitates automated control over scriptable Mac applications. First introduced in System 7, it is currently included in all versions of macOS as part of a package of system automation tools. The term "AppleScript" may refer to the language itself, to an individual script written in the language, or, informally, to the macOS Open Scripting Architecture that underlies the language.

In object-oriented programming, the command pattern is a behavioral design pattern in which an object is used to encapsulate all information needed to perform an action or trigger an event at a later time. This information includes the method name, the object that owns the method and values for the method parameters.

<span class="mw-page-title-main">ActionScript</span> Object-oriented programming language created for the Flash multimedia platform

ActionScript is an object-oriented programming language originally developed by Macromedia Inc.. It is influenced by HyperTalk, the scripting language for HyperCard. It is now an implementation of ECMAScript, though it originally arose as a sibling, both being influenced by HyperTalk. ActionScript code is usually converted to bytecode format by a compiler.

In computing, a here document is a file literal or input stream literal: it is a section of a source code file that is treated as if it were a separate file. The term is also used for a form of multiline string literals that use similar syntax, preserving line breaks and other whitespace in the text.

<span class="mw-page-title-main">Comparison of command shells</span>

A command shell is a command-line interface to interact with and manipulate a computer's operating system.

<span class="mw-page-title-main">SK8 (programming language)</span>

SK8 was a multimedia authoring environment developed in Apple's Advanced Technology Group from 1988 until 1997. It was described as "HyperCard on steroids", combining a version of HyperCard's HyperTalk programming language with a modern object-oriented application platform. The project's goal was to allow creative designers to create complex, stand-alone applications. The main components of SK8 included the object system, the programming language, the graphics and components libraries, and the Project Builder, an integrated development environment.

A webform, web form or HTML form on a web page allows a user to enter data that is sent to a server for processing. Forms can resemble paper or database forms because web users fill out the forms using checkboxes, radio buttons, or text fields. For example, forms can be used to enter shipping or credit card data to order a product, or can be used to retrieve search results from a search engine.

Exception handling syntax is the set of keywords and/or structures provided by a computer programming language to allow exception handling, which separates the handling of errors that arise during a program's operation from its ordinary processes. Syntax for exception handling varies between programming languages, partly to cover semantic differences but largely to fit into each language's overall syntactic structure. Some languages do not call the relevant concept "exception handling"; others may not have direct facilities for it, but can still provide means to implement it.

SuperTalk is the scripting language used in SuperCard. SuperTalk is a descendant of HyperTalk.

<span class="mw-page-title-main">SenseTalk</span>

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.

This article describes the syntax of the C# programming language. The features described are compatible with .NET Framework and Mono.

This article compares a large number of programming languages by tabulating their data types, their expression, statement, and declaration syntax, and some common operating-system interfaces.

QML is a user interface markup language. It is a declarative language for designing user interface–centric applications. Inline JavaScript code handles imperative aspects. It is associated with Qt Quick, the UI creation kit originally developed by Nokia within the Qt framework. Qt Quick is used for mobile applications where touch input, fluid animations and user experience are crucial. QML is also used with Qt3D to describe a 3D scene and a "frame graph" rendering methodology. A QML document describes a hierarchical object tree. QML modules shipped with Qt include primitive graphical building blocks, modeling components, behavioral components, and more complex controls. These elements can be combined to build components ranging in complexity from simple buttons and sliders, to complete internet-enabled programs.

LiveCode is a cross-platform rapid application development runtime system inspired by HyperCard. It features the LiveCode Script programming language which belongs to the family of xTalk scripting languages like HyperCard's HyperTalk.

<span class="mw-page-title-main">Yesod (web framework)</span>

Yesod is a web framework based on the programming language Haskell for productive development of type-safe, representational state transfer (REST) model based, high performance web applications, developed by Michael Snoyman, et al. It is free and open-source software released under an MIT License.

Tcl is a high-level, general-purpose, interpreted, dynamic programming language. It was designed with the goal of being very simple but powerful. Tcl casts everything into the mold of a command, even programming constructs like variable assignment and procedure definition. Tcl supports multiple programming paradigms, including object-oriented, imperative, functional, and procedural styles.

Kotlin is a cross-platform, statically typed, general-purpose high-level programming language with type inference. Kotlin is designed to interoperate fully with Java, and the JVM version of Kotlin's standard library depends on the Java Class Library, but type inference allows its syntax to be more concise. Kotlin mainly targets the JVM, but also compiles to JavaScript or native code via LLVM. Language development costs are borne by JetBrains, while the Kotlin Foundation protects the Kotlin trademark.

References

  1. 1 2 Flynn, Laurie (1989-02-27). "Apple Ponders Standardizing on HyperTalk". InfoWorld. p. 31.
  2. Dave Kelly, "Tools of the Trade: CompileIt! 2.0!", MacTech, Vol. 7 No. 9
  3. Erland Sommarskog and Frank Kalis, "The Curse and Blessings of Dynamic SQL", 23 June 2011
  4. Roman Knöll, Vaidas Gasiunas, Mira Mezini, "Naturalistic types", Onward! 2011: Proceedings of the 10th SIGPLAN symposium on New ideas, new paradigms, and reflections on programming and software, pp. 33–48, October 2011.
  5. Eich, Brendan (1998). "Foreword". In Goodman, Danny (ed.). JavaScript Bible (3rd ed.). John Wiley & Sons. ISBN   0-7645-3188-3. LCCN   97078208. OCLC   38888873. OL   712205M.
  6. Brendan Eich, "Splash keynote 2011, slide 10"