2-1: Terms
Terms are the syntactic particles of BushelScript programs. Terms defined in dictionaries have names. Every term has a syntactic role, a semantic URI, and contains a dictionary which can define more terms.
See also: Quick Tutorial.
Term names#
Each term defined in a dictionary has a name used to refer to it. Syntactically, a term name consists of one or more words separated by whitespace and other word-breaking characters. Term names are automatically normalized by the parser by removing leading and trailing whitespace, and replacing any whitespace between words with a single space character. For example, the parser normalizes both term name and term name to term name.
Syntactic roles#
Each term has a syntactic role, which determines its function.
| Term role | define syntax | Syntactic function |
|---|---|---|
| Type | type | Can create a type object or a variety of specifiers. |
| Property | property | Creates a property specifier. |
| Constant | constant | Evaluates to a constant object representing itself; models symbolic constants or AppleScript "enumerators". |
| Command | command | Invokes a command. |
| Parameter | parameter | Associates an argument with a parameter in a command invocation. |
| Variable | variable | Refers to stored data; usually defined using a let expression. |
| Resource | resource | Refers to an imported resource. |
Semantic URIs#
Each term also has a semantic URI, which identifies its runtime meaning. As usual, a URI consists of scheme:identifying-data. The scheme determines which data values are allowed and how they are interpreted at runtime.
URI schemes#
| Scheme | Description | Data format | Example URIs with this scheme |
|---|---|---|---|
id | BushelScript native identifier (dervied from qualified term name) | Any number of term names separated by colons | id:variable nameid:My Library:my type:my property |
res | Resource ID | See resource types | res:library:My Libraryres:systemres:app:System Preferencesres:appid:com.apple.Safari |
ae4 | Four-byte AppleEvent code | 4 MacRoman characters | ae4:cwin |
ae8 | AE event class code, AE event ID code | 8 MacRoman characters | ae8:coresetd |
ae12 | AE event class code, AE event ID code, AE parameter code | 12 MacRoman characters | ae12:coresetddata |
asid | AppleScript user identifier | Any valid AppleScript user identifier | asid:an_applescript_handlerasid:AnAppleScriptHandler |
Term IDs#
A term ID is a combination of a term role and a semantic URI. Term IDs are used in contexts where multiple types of terms might happen to share the same URI (usually, but not always, with the ae4 scheme).
Overlapping terms#
Two or more terms overlap each other if they have the same name, ID, or both.
Synonyms#
Overlapping terms with the same ID but different names are synonyms of each other. Replacing a term with one of its synonyms yields no change in program behavior.
The result is always true because sqrt and square root have identical semantics; they are synonyms.
Homonyms#
Overlapping terms with identical names but different IDs are homonyms of each other. Such identical-looking terms with different behavior should be avoided if possible. Note that homonyms are necessarily defined in different dictionaries, since a dictionary accessibly maps a name to at most one term.
Identical terms#
Terms from different dictionaries that overlap in both name and ID are identical terms. Identical terms can be used interchangeably like synonyms, but unlike homonyms, they cause minimal confusion. However, they might not have the same dictionary.
Raw form#
Raw form is special syntax that creates an anonymous term by stating its syntactic role and semantic URI inline. Terms created this way have the same syntactic function as any other term of their role.
This example refers to a term that's already defined (displayed with its usual name at runtime):
#type [ae4:abcd] is a not typically a defined term, but raw form can construct it on the fly. This is useful to quickly fill gaps in AppleScript terminology.