Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
HyperTalk
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==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 <code>put</code> assignment command, the variable was placed at the end of the statement: <syntaxhighlight lang="applescript"> put 5 * 4 into theResult </syntaxhighlight> whereas in the more traditional [[BASIC]] programming language (and most others), the same would be accomplished by writing: <syntaxhighlight lang="basic"> theResult = 5 * 4 </syntaxhighlight> The HyperTalk code has the side-effect of creating the [[Variable (computer science)|variable]] ''theResult'' on the fly. Scripts could assign any type or value to a variable using the <code>put</code> 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 [[Concatenation|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 <code>if ... then ... else ... end if</code> structure for [[Conditional (computer programming)|conditionals]] and supporting [[Loop (computing)#Loops|loops]] based on a flexible <code>repeat ... end repeat</code> syntax. [[Comment (computer programming)|Comments]] were prefaced with two minus signs: <code>-- this is a comment</code>. ===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.<!-- this doesn't seem to be clear enough, but not worth tagging with {clarify} --> 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 <code>script</code> property available in many of the stack's containers. Scripts could access the properties of a container, corresponding to [[instance variable]]s, using the <code>get</code> and <code>set</code> 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,{{efn|Which, in turn, could be loaded from text files.}} or imported from other stacks using the <code>start using</code> command. A script could even be user-provided text typed into an on-screen text field. Arbitrary text could be executed using the <code>do</code> command, in a manner similar to Dynamic SQL.<ref>Erland Sommarskog and Frank Kalis, [http://www.sommarskog.se/dynamic_sql.html "The Curse and Blessings of Dynamic SQL"], 23 June 2011</ref> ===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 <code>of</code> 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'': <syntaxhighlight lang="applescript"> put the value of card field "typehere" into theValue </syntaxhighlight> 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: <syntaxhighlight lang="applescript"> put fld "typehere" into theValue </syntaxhighlight> 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 number|ordinal]] and [[cardinal number|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: <syntaxhighlight lang="applescript"> put the first card field into theValue </syntaxhighlight> or: <syntaxhighlight lang="applescript"> put card field 1 into theValue </syntaxhighlight> 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 <code>me</code> container which acted in the same fashion as the <code>self</code> qualifier found in most [[Object-oriented programming|object-oriented languages]], allowing simple access to the current container object. Less common was the <code>it</code> variable, which held the value of the last operation for certain built-in operators. For example: <syntaxhighlight lang="applescript"> ask "What is the value?" put it into card field "display" </syntaxhighlight> This example uses the <code>ask</code> command to display a [[dialog box]] and capture the text typed into an accompanying text field; when the dialog is completed by hitting {{keypress|Return}} or clicking {{keypress|OK}}, the value is assigned to the <code>it</code> pseudo-variable. The second line then copies that value into a card field using the <code>put</code> 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 <code>card fields</code>. These collections were themselves containers with their own properties. Key among these was the <code>number</code> 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: <syntaxhighlight lang="applescript"> repeat with i = 1 to the number of card fields hide field i end repeat </syntaxhighlight> This code exposes another common feature of HyperTalk: that a property might have several names and operators. In this case the <code>hide</code> command, and the associated <code>show</code>, act by setting the value of the container's <code>visible</code> property. Thus <code>hide field i</code> is exactly equivalent to {{code|2=applescript|1=set the visible of field i to false}}. A similar example was the <code>lock screen</code> command that stopped visual updating, which was a short form for {{code|2=applescript|1=set the lockscreen to true}}, where <code>lockscreen</code> 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 <code>parts</code>. 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: <syntaxhighlight lang="applescript"> put the third word of theFilesText into colThree </syntaxhighlight> This syntax allowed the script to "walk" down the text to find particular data, as in this example: <syntaxhighlight lang="applescript"> put the first character of the third word of line 5 of card field "sometext" into theChar </syntaxhighlight> 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: <syntaxhighlight lang="applescript"> 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 </syntaxhighlight> HyperTalk also included functions for chunking strings using a substring-find operation using the <code>in</code> operator. The following code finds all examples of a given pattern using the <code>in</code> as part of the <code>repeat</code> loop, while <code>offset</code> finds the location of that pattern within the string: <syntaxhighlight lang="applescript" highlight="1"> function replaceStr pattern,newStr,inStr repeat while pattern is in inStr put offset(pattern,inStr) into pos put newStr into character pos to (pos +the length of pattern)-1 of inStr end repeat return inStr end replaceStr </syntaxhighlight> ===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:<!-- is this really what the code does? I don't see what causes the "diagonal" aspect --> <syntaxhighlight lang="applescript"> on mouseUp put "100,100" into pos repeat with x = 1 to the number of card buttons set the location of card button x to pos add 15 to item 1 of pos end repeat end mouseUp </syntaxhighlight> The <code>item</code> chunking expression was originally based on a comma [[delimiter]], but later versions of HyperCard changed this to the value of <code>itemDelimiter</code>, 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 <code>on</code> syntax. For instance, most GUI containers would send the <code>mouseDown</code> message when the mouse button was clicked down, and then a <code>mouseUp</code> message when it was released while still on top of that container, and a script could capture these events like this: <syntaxhighlight lang="applescript"> on mouseUp -- place additional code here end mouseUp </syntaxhighlight> 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 <code>mouseUp</code> message was first sent to that button. If the button's script object did not have a <code>mouseUp</code> 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 <code>start using</code> 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: <syntaxhighlight lang="applescript"> on mouseUp repeat with i = 1 to the number of card fields hide field i end repeat end mouseUp </syntaxhighlight> 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 <code>target</code> function. Likewise, scripts could send events to other containers using the <code>send</code> command and then using the navigational code to refer to the container holding that handler's code: <syntaxhighlight lang="applescript"> send "mouseUp" to card button "OK" of card "Veracity" </syntaxhighlight> Combining HyperTalk's string processing with the <code>do</code> 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: <syntaxhighlight lang="applescript" highlight="4"> on mouseUp select the clickLine put word 2 of the clickLine into linenum do line linenum of cd fld 1 end mouseUp </syntaxhighlight> <code>clickLine</code> is a global property that returns the name and line number of the last field clicked, in a form like {{code|2=applescript|1=line 10 of card field 4}}. This code first selects all of the text on the clicked line, then extracts the line number into a local variable, then uses <code>do</code> to run the text as a HyperCard script. The <code>mouseDown</code> message was sent to a button when the user clicked it, and <code>mouseUp</code> was sent when the user released the mouse inside it to trigger its action. Similarly, HyperCard sent periodic <code>idle</code> message, <code>mouseEnter</code>, <code>mouseLeave</code>, ... and various other messages related to navigation between different cards in a HyperCard stack, as well as user input (<code>keyDown</code>, <code>functionKey</code>, ...), 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 using<code>doMenu "New Card"</code>. 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 <code>on doMenu itemName</code> handler, and then examine <code>itemName</code> 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 <code>drag from ''start'' to ''end''</code> and the <code>click at ''position''</code> 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 <code>character 2 of 1234</code>), HyperCard would also recognize certain expressions and extract sub-values from them. For example: <syntaxhighlight lang="applescript"> put the selectedLine of card field "Listbox" into theSelection -- gives 'line 2 to 3 of card field "Listbox"' select line 1 of card field "Listbox" select line (word 2 of theSelection) of card field "Listbox" select (the selectedLine of card field "Listbox") -- parentheses added for illustrative purposes only </syntaxhighlight> or <syntaxhighlight lang="applescript"> play harpsichord c e g play harpsichord "c e g" put "c e g" into theMelody play harpsichord theMelody </syntaxhighlight> 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: <syntaxhighlight lang="applescript"> play harpsichord "c e g()" put "c e() g" into theMelody play harpsichord theMelody </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)