1 #LyX 1.5.3 created this file. For more info see http://www.lyx.org/
10 \font_typewriter default
11 \font_default_family default
18 \paperfontsize default
26 \paperorientation portrait
31 \paragraph_separation skip
33 \quotes_language english
36 \paperpagestyle default
37 \tracking_changes false
46 The Slate Programmer's Reference Manual
51 Rice, Lee Salzman, Timmy Douglas
54 \begin_layout Standard
55 \begin_inset LatexCommand tableofcontents
62 \begin_layout Standard
63 \begin_inset FloatList figure
70 \begin_layout Standard
80 \begin_layout Standard
81 Slate is a member of the Smalltalk
82 \begin_inset LatexCommand index
87 family of languages which supports an object model in a similar prototype-based
89 \begin_inset LatexCommand index
95 \begin_inset LatexCommand cite
100 , extended and re-shaped to support multiple-dispatch methods.
101 However, unlike Self, Slate does not rely on a literal syntax that combines
102 objects and blocks, using syntax more akin to traditional Smalltalk.
103 Unlike a previous attempt at providing prototype-based languages with multiple
105 \begin_inset LatexCommand cite
111 \begin_inset LatexCommand index
116 , Slate is dynamic and more free-form in style, supporting the simplicity
117 and flexibility of syntax and environment of the Smalltalk family.
118 It is intended that both Smalltalk and Self styles of programs can be ported
119 to Slate with minimal effort.
120 Finally, Slate contains extensions
121 \begin_inset LatexCommand index
126 including optional keywords, optional type-declarations, subjective dispatch
127 and syntactic macros, that can be used to make existing programs and environmen
128 t organizations much more powerful than in traditional object-based programming.
131 \begin_layout Subsection
135 \begin_layout Standard
136 Throughout this manual, various terms will be highlighted in different ways
137 to indicate the type of their significance.
138 If some concept is a certain programming utility in Slate with a definite
139 implementation, it will be formatted in a
144 If a term is technical with a consistent definition in Slate, but cannot
145 have a definite implementation, it will be set in
147 small capital letters
150 Emphasis on its own is denoted by
155 When expression/result patterns are entered, typewriter-style text will
160 prompt before the statement and its result will be set in
163 italicized typewritten text
169 \begin_layout Subsection
173 \begin_layout Standard
174 Slate is an object-oriented language, and as such works with some terms
175 worth describing initially for clarity.
176 These are primarily inspired by the metaphor of computational entities
177 which communicate via messages, as follows:
180 \begin_layout Description
182 \begin_inset LatexCommand index
183 name "object (terminology)"
187 is some thing in the system that can be identified.
190 \begin_layout Description
192 \begin_inset LatexCommand index
193 name "method (terminology)"
197 is some behavior or procedure that is defined on some objects or class
201 \begin_layout Description
203 \begin_inset LatexCommand index
204 name "message (terminology)"
208 is the act of requesting a behavior or procedure from some objects, the
214 The requestor is known as the
221 \begin_layout Description
223 \begin_inset LatexCommand index
224 name "answer (terminology)"
228 is the response to a message; a value that expressions evaluate into or
229 return to the message's sender.
232 \begin_layout Description
234 \begin_inset LatexCommand index
235 name "selector (terminology)"
239 is the name of a method or a message-send.
242 \begin_layout Description
244 \begin_inset LatexCommand index
245 name "inheritance (terminology)"
249 is a relationship between objects that confers one object's (the parent)
250 behavior on another (the child).
253 \begin_layout Description
255 \begin_inset LatexCommand index
256 name "dispatch (terminology)"
260 is the process of determining, from a message-send, what method is appropriate
261 to invoke to implement the behavior.
262 This is also referred to as
269 \begin_layout Section
273 \begin_layout Subsection
277 \begin_layout Standard
280 \begin_inset LatexCommand index
287 are fundamental in Slate; everything in a running Slate system consists
289 Slate objects consist of a number of slots and roles: slots
290 \begin_inset LatexCommand index
299 s to other objects, and roles
300 \begin_inset LatexCommand index
305 are a means of organizing code that can act on the object.
306 Slots themselves are accessed and updated by a kind of message-send which
307 is not distinguishable from other message-sends syntactically, but have
308 some important differences.
311 \begin_layout Standard
312 Objects in Slate are created by
315 \begin_inset LatexCommand index
322 existing objects, rather than instantiating a class.
323 When an object is cloned, the created object has the same slots and values
325 The new object will also have the access and update methods for those slots
326 carried over to the new object.
327 Other methods defined on the object will propagate through an analogue
328 of a slot called a role, explained in section
329 \begin_inset LatexCommand ref
330 reference "sub:Methods"
337 \begin_layout Standard
338 Both control flow and methods are implemented by specialized objects called
340 \begin_inset LatexCommand index
345 , which are code closures
346 \begin_inset LatexCommand index
352 These code closures contain their own slots and create activation objects
353 to handle run-time context when invoked.
354 They can also be stored in slots and sent their own kinds of messages.
357 \begin_layout Subsubsection
361 \begin_layout Standard
362 \begin_inset LatexCommand label
363 name "sub:Block-Closures"
368 \begin_inset LatexCommand index
373 is an object representing an encapsulable context of execution, containing
374 local variables, input variables, the capability to execute expressions
375 sequentially, and finally answers a value to its point of invocation.
376 The default return value for a block is the last expression's value; an
382 \begin_inset LatexCommand vref
383 reference "sub:Early-Returns"
388 \begin_inset LatexCommand index
396 \begin_layout Standard
397 Blocks have a special syntax for building them up syntactically.
398 Block expressions are delimited by square brackets.
399 The block's optional header can specify input and local slots between vertical
404 ), and then a sequence of expressions which comprises the block's body.
405 The input syntax allows specification of the slot names desired at the
410 \begin_layout LyX-Code
411 Slate> [| :arg num | num: 4.
419 \begin_layout Standard
420 creates and returns a new block.
421 Within the header, identifiers that begin with a colon such as
425 above are parsed as input slots
426 \begin_inset LatexCommand index
432 The order in which they are specified is the order that arguments matching
433 them must be passed in later to evaluate the block.
434 If the block is evaluated later, it will return the expression after the
435 final stop (the period) within the brackets,
446 is an input slot, and
451 \begin_inset LatexCommand index
456 which is assigned to and then used in a following expression.
457 The order of specifying the mix of input and local slots does not affect
458 the semantics, but the order of the input slots directly determines what
459 order arguments need to be passed to the block to assign them to the correct
463 \begin_layout Standard
464 Using the term "slot" for local and input variables is not idle: the block
465 is an actual object with slots for each of these variables, and accessors
466 defined on them which are even callable from outside the block, considering
470 \begin_layout Standard
471 \begin_inset LatexCommand index
472 name "block invocation"
476 In order to invoke a block, the caller must know how many and in what order
477 it takes input arguments.
478 Every block responds to
481 \begin_inset LatexCommand index
482 name "applyTo: (message)"
488 , which takes an array of the input values as its other argument.
489 The block is immediately evaluated, and the result of the evaluation is
490 the block's execution result.
494 \begin_layout LyX-Code
495 Slate> [| :x :y | x quo: y] applyWith: 17 with: 5.
503 Slate> [| :a :b | (a raisedTo: 2) - (4 * b)]
513 \begin_layout Standard
514 Arguments can also be passed in using some easier messages.
515 Blocks that don't expect any inputs respond to
520 \begin_inset LatexCommand index
528 \begin_layout LyX-Code
529 Slate> [| a b | a: 4.
538 \begin_layout Standard
539 Blocks that take one, two, or three inputs, each have special messages
544 \begin_inset LatexCommand index
545 name "applyWith: (message)"
554 \begin_inset LatexCommand index
555 name "applyWith:with: (message)"
562 \begin_inset LatexCommand index
563 name "applyWith:with:with: (message)"
569 which pass in the inputs in the order they were declared in the block header.
572 \begin_layout Standard
574 \begin_inset LatexCommand index
579 , contains an empty body, or the final expression is terminated with a period
580 \begin_inset LatexCommand index
581 name "block, termination with a period"
592 \begin_layout LyX-Code
601 Slate> [| :a :b |] applyTo: {0.
618 \begin_layout Standard
619 \begin_inset LatexCommand index
620 name "variable arguments"
625 \begin_inset LatexCommand index
626 name "rest parameter"
630 If more arguments are passed than the block expects as inputs, an error
631 is raised unless the block specifies a single
632 \begin_inset Quotes eld
636 \begin_inset Quotes erd
639 argument parameter, using an asterisk prefix for the argument identifier
645 ), in which case the slot is bound to an array of the inputs not otherwise
649 \begin_layout Standard
650 Blocks furthermore have the property that, although they are a piece of
651 code and the values they access may change between defining the closure
652 and invoking it, the code will
653 \begin_inset Quotes eld
657 \begin_inset Quotes erd
660 what objects it depends on, regardless of what context it may be passed
662 It is called a lexical closure
663 \begin_inset LatexCommand index
664 name "lexical closure"
669 \begin_inset LatexCommand index
670 name "closure, lexical"
675 \begin_inset Quotes eld
679 \begin_inset Quotes erd
682 the environment and variables used in its definition, the lexical context
684 This is critical for implementing good control structures in Slate, as
686 Basically a block is an activation of its code composed with an environment
687 that can be saved and invoked (perhaps multiple times) long after it is
688 created, and always do so in the way that it reads where it was defined.
691 \begin_layout Subsubsection
695 \begin_layout Standard
696 \begin_inset LatexCommand index
697 name "slot properties"
702 \begin_inset LatexCommand index
703 name "slot mutability"
708 \begin_inset LatexCommand index
709 name "slots, delegation"
713 Slots may be mutable or immutable, and explicit slots or delegation (inheritance
715 These four possibilities are covered by primitive methods defined on all
719 \begin_layout Standard
720 Slate provides several primitive messages to manage
731 \begin_layout Description
734 \begin_inset LatexCommand index
735 name "addSlot: (message)"
740 addSlot:\InsetSpace ~
743 adds a slot using the
747 as its name, initialized to
754 \begin_layout Description
757 \begin_inset LatexCommand index
758 name "addSlot:valued: (message)"
763 addSlot:\InsetSpace ~
764 slotSymbol\InsetSpace ~
768 adds a slot under the given name and initializes its value to the given
772 \begin_layout Description
773 \begin_inset LatexCommand index
774 name "addImmutableSlot:valued: (message)"
780 addImmutableSlot:valued:
782 performs the same as the above method, only without installing a mutator
786 \begin_layout Description
789 \begin_inset LatexCommand index
790 name "removeSlot: (message)"
795 removeSlot:\InsetSpace ~
798 removes the slot with the given name on the object directly and returns
799 whatever value it had.
802 \begin_layout Standard
803 The effect of all of the slot addition methods when a slot of the same name
804 is present is to update the value and attributes of the slot rather than
805 duplicate or perform nothing.
808 \begin_layout Subsubsection
812 \begin_layout Standard
813 \begin_inset LatexCommand index
818 Slate's means of sharing and conferring behavior involves the use of a
822 , whereby each object can name and access each object it inherits from.
826 \begin_layout Standard
827 The delegates' inheritance role involves a precedence order which affects
828 the lookup of messages; from the object's perspective, the delegate slot
829 array goes from least important to most important.
831 \begin_inset LatexCommand vref
832 reference "sub:Lookup-Semantics"
836 explains the details of lookup semantics.
839 \begin_layout Standard
840 The relevant primitives specific to delegation slots are:
843 \begin_layout Description
846 \begin_inset LatexCommand index
847 name "addDelegate: (message)"
852 \begin_inset LatexCommand index
853 name "addDelegate:valued: (message)"
858 addDelegate:\InsetSpace ~
865 insertDelegate:\InsetSpace ~
870 The delegates array for an object is stored in the object's map.
873 \begin_layout Description
874 \begin_inset LatexCommand index
875 name "delegates (message)"
880 \begin_inset LatexCommand index
881 name "delegates: (message)"
891 \begin_layout Standard
910 \begin_layout Standard
924 allow for finer control over manipulating delegates, since they explicitly
925 set the delegate array.
929 \begin_layout Subsection
933 \begin_layout Standard
934 \begin_inset LatexCommand index
939 Expressions in Slate mainly consist of messages sent to argument objects.
940 The left-most argument is not considered an implicit receiver as it is
941 with most message-passing languages, however.
942 This means that when identifying a variable, it is really a message that
943 is being sent to the context or argument.
946 \begin_layout Standard
947 \begin_inset LatexCommand index
948 name "case sensitivity"
953 \begin_inset LatexCommand index
954 name "whitespace sensitivity"
958 An important issue is that every message selector (and slot name) is
962 in Slate, that is, there is a definite distinction between what
974 denote even in the same context.
975 Furthermore, the current implementation is
979 as well, in the sense that whitespace must be used to separate messages
980 in order for them to be considered separate.
985 will be treated as one message, but
991 is a send of a binary message.
994 \begin_layout Standard
995 \begin_inset LatexCommand index
996 name "messages, types"
1000 There are three basic types of messages, with different syntaxes and associativi
1001 ties: unary, binary, and keyword messages.
1005 \begin_inset LatexCommand index
1006 name "messages, precedence"
1011 \begin_inset LatexCommand index
1012 name "precedence, messages"
1018 is determine entirely by the syntactic form of the expression, but it can
1019 of course be overridden by enclosing expressions in parentheses.
1020 An implicit left-most argument can be used with all of them.
1021 The default precedence for forms is as follows:
1024 \begin_layout Enumerate
1025 Literal syntax: arrays, blocks, block headers, statement sequences.
1028 \begin_layout Enumerate
1032 \begin_layout Enumerate
1036 \begin_layout Enumerate
1040 \begin_layout Standard
1041 \begin_inset LatexCommand index
1046 A concept that will be often used about message-sends is that of the name
1056 used to refer to the message or the name of a method that matches it.
1057 Slate uses three styles of selectors, each with a unique but simple syntax.
1060 \begin_layout Subsubsection
1061 \begin_inset LatexCommand label
1062 name "sub:Unary-Message-sends"
1069 \begin_layout Standard
1070 \begin_inset LatexCommand index
1071 name "unary messages"
1076 \begin_inset LatexCommand index
1077 name "messages, unary"
1085 does not specify any additional arguments.
1086 It is written as a name following a single argument; it has a post-fix
1090 \begin_layout Standard
1091 Some examples of unary message-sends to explicit arguments include:
1094 \begin_layout LyX-Code
1103 Slate> 'Slate' clone.
1110 \begin_layout Standard
1111 Unary sends associate from left to right.
1112 So the following prints the factorial of 5:
1115 \begin_layout LyX-Code
1116 Slate> 5 factorial print.
1123 \begin_layout Standard
1124 Which works the same as:
1127 \begin_layout LyX-Code
1128 Slate> (5 factorial) print.
1135 \begin_layout Standard
1136 Unary selectors can be most any alpha-numeric identifier, and are identical
1137 lexically to ordinary identifiers of slot names.
1138 This is no coincidence, since slots are accessed via a type of unary selector.
1141 \begin_layout Subsubsection
1145 \begin_layout Standard
1146 \begin_inset LatexCommand index
1147 name "messages, binary"
1152 \begin_inset LatexCommand index
1153 name "binary messages"
1161 is named by a special non-alphanumeric symbol and 'sits between' its two
1162 arguments; it has an infix form.
1163 Binary messages are also evaluated from left to right; there is no special
1168 difference between any two binary message-sends.
1172 \begin_layout Standard
1173 This removes a source of grammatical complexity in a language where anyone
1174 can add new binary selectors or implementations.
1175 It is our policy that conventional mathematical notation and visual convenience
1176 belong in user interface libraries.
1184 \begin_layout Standard
1185 These examples illustrate the precedence and syntax:
1188 \begin_layout LyX-Code
1220 \begin_layout Standard
1221 Binary messages have lower
1225 than unary messages.
1226 Without any grouping notation, the following expression's unary messages
1227 will be evaluated first and then passed as arguments to the binary message:
1230 \begin_layout LyX-Code
1231 Slate> 7 factorial + 3 negated.
1239 Slate> (7 factorial) + (3 negated).
1247 Slate> (7 factorial + 3) negated.
1254 \begin_layout Standard
1255 Binary selectors can consist of one or more of the following characters:
1258 \begin_layout LyX-Code
1263 \begin_layout Standard
1277 \begin_layout Standard
1278 However, these characters are reserved:
1281 \begin_layout LyX-Code
1286 \begin_layout Subsubsection
1290 \begin_layout Standard
1291 \begin_inset LatexCommand index
1292 name "keyword messages"
1297 \begin_inset LatexCommand index
1298 name "messages, keyword"
1306 is an alternating sequence of keywords and expressions, generally being
1307 a continued infix form.
1308 Keywords are identifiers beginning with a letter and ending with a colon.
1309 Keyword messages start with the left-most argument along with the longest
1310 possible sequence of keyword-value pairs.
1312 \begin_inset LatexCommand index
1313 name "selector, of keyword message"
1321 of the message is the joining-together of all the keywords into one
1333 \begin_layout LyX-Code
1334 Slate> 5 min: 4 max: 7.
1341 \begin_layout Standard
1342 is a keyword message-send named
1346 which has 3 arguments: 5, 4, and 7.
1350 \begin_layout LyX-Code
1351 Slate> 5 min: (4 max: 7).
1358 \begin_layout Standard
1359 is a different kind of expression.
1364 keyword message-sends are made, the first being
1368 sent to 4 and 7, and
1372 sent to 5 and the first result.
1373 Note however, that even though the first expression evaluates to the same
1377 \begin_layout LyX-Code
1378 Slate> (5 min: 4) max: 7.
1385 \begin_layout Standard
1386 that this is still a distinct expression from the first one, with two message-se
1387 nds of one keyword each instead of one send with two keywords.
1388 Actually, this expresses the definition of
1392 , although this is perhaps one of the most trivial uses of method names
1393 with multiple keywords.
1396 \begin_layout Standard
1397 Keywords have the lowest
1401 of message-sends, so arguments may be the results of unary or binary sends
1402 without explicit grouping required.
1403 For example, the first expression here is equivalent to the latter implicitly:
1406 \begin_layout LyX-Code
1407 Slate> 5 + 4 min: 7 factorial max: 8.
1415 Slate> (5 + 4) min: (7 factorial) max: 8.
1422 \begin_layout Subsubsection
1423 Implicit-context Messages
1426 \begin_layout Standard
1427 \begin_inset LatexCommand index
1428 name "sends, implicit-context"
1433 \begin_inset LatexCommand index
1434 name "implicit-context sends"
1439 \begin_inset LatexCommand index
1440 name "lexical scope"
1445 \begin_inset LatexCommand index
1446 name "scope, lexical"
1450 Within methods, blocks, and even at the top-level, some expressions may
1451 take the surrounding context as the first argument.
1452 There is an order for the determination of which object becomes the first
1453 argument, which is entirely based on lexical scoping.
1454 So, within a block, an implicit send will take the block's run-time context
1456 The next outer contexts follow in sequence, up to the top-level and what
1457 it inherits from, which generally turns out to be the global object that
1458 roots the current session.
1461 \begin_layout Standard
1462 Specifically, any non-literal expression following a statement-separator
1463 or starting an expression within parentheses or other grouping is an implicit-c
1467 \begin_layout Standard
1468 There are some very common uses of implicit-context sends.
1469 In particular, accessing and modifying local variables of a block or method
1470 is accomplished entirely this way, as well as returns.
1474 \begin_layout LyX-Code
1481 j < k ifTrue: [| m |
1495 \begin_layout Standard
1496 is a block which, when invoked, takes one argument and has another two to
1498 Notice that the local slot
1502 is available within the enclosed block that also has a further slot
1507 Local blocks may also
1511 the slots of their outer contexts with their input and local slots.
1512 In this case, the identifiers
1520 , for example, are automatically-generated accessing and update methods
1526 is a keyword message, if the assigned value is a keyword message-send result,
1527 it must be enclosed in parentheses to distinguish the keyword pattern.
1532 raisedTo:\InsetSpace ~
1536 \begin_inset LatexCommand index
1541 causes the context to exit prematurely, returning as its value the result
1542 of the right-hand argument.
1543 All methods have this method defined on them, and it will return out to
1544 the nearest named block or to the top-level.
1547 \begin_layout Standard
1548 The way this is currently implemented is that the compiler will detect when
1549 a local slot is read or modified and it will turn the command into a
1558 If the a read or write is done to a variable in a parent block, it will
1567 which will get the value from the current closure's lexical window array.
1570 \begin_layout Subsection
1571 Sequencing Expressions
1574 \begin_layout Standard
1575 \begin_inset LatexCommand index
1576 name "expression sequences"
1581 \begin_inset LatexCommand index
1587 \begin_inset LatexCommand index
1592 Statements are the overall expressions between stop-marks, which are periods.
1593 In an interactive evaluation context, expressions aren't evaluated until
1594 a full (top-level) statement is expressed.
1595 The stop mark also means that statement's expression results aren't directly
1596 carried forward as an argument to the following expression; side-effects
1597 must be used to use the results.
1598 More specifically, each expression in the sequence must be evaluated in
1599 order, and one expression's side-effects must effectively occur before
1600 the next expression begins executing and before any of its side-effects
1604 \begin_layout Standard
1605 \begin_inset LatexCommand index
1611 \begin_inset LatexCommand index
1612 name "() (parentheses)"
1616 Slate provides for a bare expression sequence syntax that can be embedded
1617 within any grouping parentheses, as follows:
1620 \begin_layout LyX-Code
1628 \begin_layout LyX-Code
1629 Slate> (7 factorial.
1639 \begin_layout Standard
1640 The parentheses are used just as normal grouping, and notably, the
1645 expression wraps over a line, but still evaluates that way.
1649 \begin_layout Standard
1650 We do not consider this expression good style, but it illustrates the nature
1656 If the parentheses are empty, or the last statement in a sequence is followed
1657 by a period before ending the sequence, an
1658 \begin_inset LatexCommand index
1659 name "empty expression"
1664 \begin_inset Quotes eld
1668 \begin_inset Quotes erd
1671 value is returned, which is
1674 \begin_inset LatexCommand index
1684 \begin_layout Subsection
1688 \begin_layout Standard
1691 \begin_inset LatexCommand index
1697 \begin_inset LatexCommand index
1703 \begin_inset LatexCommand index
1709 \begin_inset LatexCommand label
1716 in Slate are basically annotated code blocks (documented in
1717 \begin_inset LatexCommand ref
1718 reference "sub:Block-Closures"
1722 ), coupled with annotations of the objects' roles that dispatch to them.
1725 \begin_layout Subsubsection
1729 \begin_layout Standard
1730 A relatively unique concept in the language is that objects relate to their
1736 \begin_inset LatexCommand index
1746 A role is an association between an object and a method that applies to
1747 it that is similar to a slot, but not directly a slot as it is in
1748 \begin_inset LatexCommand index
1754 Instead of simply being a storage reference, a role associates the object
1759 in the signature of a method.
1760 This is a way of stating that the object
1761 \begin_inset Quotes eld
1765 \begin_inset Quotes erd
1768 in a certain behavior, reinforcing the idea that behavior arrives through
1770 Furthermore, the behavior is shared among the cooperators, so methods are
1772 \begin_inset Quotes eld
1776 \begin_inset Quotes erd
1779 by particular objects; they are not properties.
1782 \begin_layout Standard
1783 However, because dispatch can happen on many combinations of arguments,
1784 a method name plus the object's position is not sufficient to identify
1785 a single method; instead, a group of methods of the same name may be associated
1786 via a role with an object at a certain signature position.
1787 During method lookup, the appropriate method is found through knowing all
1788 of the objects in the signature and knowing which take precedence over
1790 So a specific role consists of a triple-association between an object,
1791 its position in a signature for a method, and the method itself.
1794 \begin_layout Standard
1795 When referring to an object's
1796 \begin_inset Quotes eld
1800 \begin_inset Quotes erd
1803 in general, it usually means the collection of these associations as a
1804 whole; what relates the object to the behaviors it participates in.
1807 \begin_layout Subsubsection
1811 \begin_layout Standard
1812 \begin_inset LatexCommand index
1813 name "method definition"
1818 \begin_inset LatexCommand index
1819 name "method template"
1823 Method definition syntax is handled relatively separately from normal precedence
1825 It essentially revolves around the use of the reserved character
1826 \begin_inset Quotes eld
1834 \begin_inset Quotes erd
1838 \begin_inset LatexCommand index
1839 name "\\char `\\@ (at)"
1844 If any identifier in a message-send argument position is found to contain
1845 the character, the rest of the same send is examined for other instances
1850 , and the whole send-expression is treated as a template.
1851 The parser treats the expression or identifier to the right of the
1855 characters as dispatch targets
1856 \begin_inset LatexCommand index
1857 name "dispatch targets"
1861 for the method's argument positions; the actual objects returned by the
1862 expressions are annotated with a role for their positions.
1865 \begin_layout Standard
1866 After the message-send template, there is expected a block expression of
1867 some kind, whether a literal or an existing block.
1868 Whichever is specified, the parser creates a new block out of it with adjustmen
1869 ts so that the identifiers in the dispatching message-send become input
1870 slots in the closure.
1871 The block should be the final expression encountered before the next stop
1873 \begin_inset LatexCommand index
1879 \begin_inset LatexCommand index
1885 \begin_inset LatexCommand index
1893 \begin_layout Standard
1894 \begin_inset LatexCommand index
1900 \begin_inset LatexCommand index
1901 name "\\_ (underscore)"
1905 There is a further allowance that an input slot-name specifier may be solely
1906 an underscore (but not an underscore followed by anything else), in which
1907 case the argument to the method at that position is
1911 passed in to the block closure.
1914 \begin_layout Standard
1915 This syntax is much simpler to recognize and create than to explain.
1916 For example, the following are a series of message definitions adding to
1917 boolean control of evaluation:
1920 \begin_layout LyX-Code
1921 _@True ifTrue: block ifFalse: _ [block do].
1923 _@False ifTrue: _ ifFalse: block
1928 bool@(Boolean traits) ifTrue: block
1930 "Some sugaring for ifTrue:ifFalse:.
1935 bool ifTrue: block ifFalse: []
1940 \begin_layout Standard
1941 The first two represent good uses of dispatching on a particular individual
1942 object (dispatching the ignored argument named
1943 \begin_inset Quotes eld
1951 \begin_inset Quotes erd
1962 , respectively) as well as the syntax for disregarding its value.
1963 Within their blocks,
1967 refers to the named argument to the method.
1968 What's hidden is that the block given as the code is re-written to include
1969 those arguments as inputs in the header.
1970 Also, the objects given to the dispatch annotation are configured to install
1971 this method in appropriate roles; because this is hidden, roles are normally
1972 an implicit concept and should not concern the user except as an explanation
1976 \begin_layout Standard
1977 The latter method appears to have a slightly-different syntax, but this
1978 is an illusion: the parentheses are just surrounding a Slate expression
1979 which evaluates to an object, much as
1987 evaluate to particular objects; really, any Slate expression can be placed
1988 there, assuming that the result of it is what is wanted for dispatch.
1989 As a side note, this last method is defined in terms of the first two and
2000 Boolean\InsetSpace ~
2003 (the object carrying the common behavior of the boolean objects).
2006 \begin_layout Subsubsection
2007 Expression-based Definitions
2010 \begin_layout Standard
2011 \begin_inset LatexCommand index
2012 name "methods, dynamic generation"
2017 \begin_inset LatexCommand index
2018 name "asMethod:on: (message)"
2022 The specialized syntax using the
2023 \begin_inset Quotes eld
2031 \begin_inset Quotes erd
2034 special has an equivalent in regular Slate syntax which is often useful
2035 for generating new methods dynamically in a non-ambiguous way.
2036 This is a reflective call on the evaluator to compile a method using a
2037 certain symbolic name and a sequence of objects that are used for dispatching
2042 \begin_layout LyX-Code
2043 [| :x :y | Nil] asMethod: #+ on: {True.
2047 \begin_layout Standard
2051 \begin_layout LyX-Code
2052 _@True + _@False [Nil].
2055 \begin_layout Standard
2056 are equivalent (while not recommendable) expressions.
2057 This raises the question of a place-filler for an argument position which
2059 In that case, Slate provides a unique primitive
2062 \begin_inset LatexCommand index
2063 name "NoRole (object)"
2069 for this purpose, which provides an analogous role to
2077 cannot be dispatched upon.
2078 Essentially, this means that the following method definition:
2081 \begin_layout LyX-Code
2082 c@(Set traits) keyAt: index
2091 \begin_layout Standard
2092 is semantically equivalent to:
2095 \begin_layout LyX-Code
2096 c@(Set traits) keyAt: index@NoRole
2105 \begin_layout Standard
2109 \begin_layout LyX-Code
2110 [| :c :index | c array at: index] asMethod: #keyAt:
2117 \begin_layout Subsubsection
2118 \begin_inset LatexCommand label
2119 name "sub:Lookup-Semantics"
2126 \begin_layout Standard
2127 \begin_inset LatexCommand index
2128 name "dispatch, message"
2133 \begin_inset LatexCommand index
2134 name "message dispatch"
2139 \begin_inset LatexCommand index
2140 name "lookup semantics"
2144 Message dispatch in Slate is achieved by consulting all of the arguments
2145 to that message, and considering what roles they have pertaining to that
2146 message name and their position within the message-send.
2147 Slate's dispatch semantics are termed
2148 \begin_inset LatexCommand index
2149 name "multiple dispatch"
2154 \begin_inset LatexCommand index
2155 name "dispatch, multiple"
2160 \begin_inset Quotes eld
2164 \begin_inset Quotes erd
2168 \begin_inset Quotes eld
2172 \begin_inset Quotes erd
2175 which is typical of most languages based on objects and messages.
2176 Whereas most languages designate on object as the receiver of a message,
2177 Slate considers all objects involved cooperating participants.
2178 During the dispatch process, more than one method can be discovered as
2179 a potential candidate.
2184 candidate is chosen as soon as its place in the order is determined.
2187 \begin_layout Standard
2188 The algorithm achieves a full ordering of arguments: the specificity of
2189 the first argument counts more than the second, the second more than the
2191 However, where normal multiple dispatch looks at each argument and uses
2192 the most specific supertype to determine specificity (or rather, the most
2193 specific parameter type of which the argument is a subtype), Slate instead
2194 interprets specificity as
2198 in the directed graph of delegations, starting from the particular argument
2199 in question as the root.
2202 \begin_layout Standard
2207 notion has the following properties:
2210 \begin_layout Itemize
2211 It is determined by a depth-first traversal over the delegate slots, considering
2212 delegates at a higher index in the array before lower ones.
2215 \begin_layout Itemize
2216 Delegations that lead to cycles are not traversed.
2219 \begin_layout Itemize
2220 Repeated finds of a same method do not alter the distance value for it;
2221 the first one found is retained.
2224 \begin_layout Itemize
2225 The closer (smaller) the
2229 of the role to the argument, the more specific it is.
2232 \begin_layout Standard
2233 So, Slate's lookup algorithm visits each argument in turn, determining candidate
2234 applicable methods as ordered by the
2238 notion, and traverses further to look for other possible candidates, unless
2239 it rules out the possibility of a more applicable method than a singly-identifi
2243 \begin_layout Standard
2244 The resulting dispatched method satisfies the property that: for any of
2245 the arguments, we can find the method on some role reachable by traversing
2246 delegations, and that is the closest such method we can find, where former
2247 arguments count as being
2248 \begin_inset Quotes eld
2252 \begin_inset Quotes erd
2255 than any subsequent arguments, and
2260 \begin_inset Quotes eld
2264 \begin_inset Quotes erd
2267 , as far away as possible.
2270 \begin_layout Subsubsection
2271 Optional Keyword Arguments
2274 \begin_layout Standard
2275 \begin_inset LatexCommand index
2276 name "arguments, optional keyword"
2281 \begin_inset LatexCommand index
2282 name "optional keyword arguments"
2287 \begin_inset LatexCommand index
2288 name "keyword arguments, optional"
2292 The mechanism in Slate for specifying optional input arguments uses
2297 They can be added to a method definition, a message-send, or a block header
2299 Also, optional keywords can apply to unary, binary, and keyword message
2301 However, optional arguments cannot affect dispatch, can be provided in
2302 any order, and when not provided will start with a
2306 value, due to their being incidental to the core semantics of the given
2310 \begin_layout Paragraph
2311 In Method Definitions
2312 \begin_inset LatexCommand index
2313 name "optional keywords (in a method definition)"
2320 \begin_layout Standard
2321 \begin_inset LatexCommand index
2327 \begin_inset LatexCommand index
2328 name "\\& (ampersand)"
2332 Method definitions may be annotated with optionals that they support by
2333 extending the signature with keyword-localname pairs in arbitrary order
2335 \begin_inset Quotes eld
2340 &keywordName:\InsetSpace ~
2344 \begin_inset Quotes erd
2348 This compiles the method to support
2352 as a local, with optional input.
2355 \begin_layout Paragraph
2357 \begin_inset LatexCommand index
2358 name "optional keywords (in a message send)"
2365 \begin_layout Standard
2366 An optional keyword argument is passed to a method by forming keyword-value
2368 \begin_inset Quotes eld
2373 &keywordName:\InsetSpace ~
2377 \begin_inset Quotes erd
2380 after the main selector and arguments as normal.
2381 Following keywords that have the
2385 -prefix will be collected into the same message-send.
2386 A following non-optional keyword will be treated as beginning a new surrounding
2387 message-send, but in general, optional keywords raise the precedence of
2388 the basis message signature to a keyword level, instead of just unary or
2390 Again, the order of the keyword-value pairs is ignored.
2393 \begin_layout Paragraph
2395 \begin_inset LatexCommand index
2396 name "optional keywords (in a block header)"
2403 \begin_layout Standard
2404 A block can declare optional input keywords in its block header in any order,
2406 \begin_inset Quotes eld
2414 \begin_inset Quotes erd
2417 as an input variable declaration, called with the normal convention (when
2418 using the block with
2426 /etc.), whenever the block is invoked with a message-send.
2429 \begin_layout Subsubsection
2430 Resending messages or Dispatch-overriding
2434 \begin_layout Standard
2443 \begin_layout Standard
2444 \begin_inset LatexCommand index
2445 name "messages, resending"
2450 \begin_inset LatexCommand index
2451 name "resending messages"
2456 \begin_inset LatexCommand index
2457 name "overriding, dispatch"
2462 \begin_inset LatexCommand index
2463 name "dispatch-overriding"
2467 Because Slate's methods are not centered around any particular argument,
2468 the resending of messages is formulated in terms of giving the method activatio
2470 The following are the various primitive protocols involved in resends:
2473 \begin_layout Description
2477 \begin_inset LatexCommand index
2478 name "resend (message)"
2484 is the simplest form of resending.
2485 It acts on the context to find the next-most-applicable method and invokes
2486 it with the exact same set of arguments (including optional parameters
2487 passed) as an expression.
2492 message is the returned result of that method, just like calling any other
2496 \begin_layout Description
2499 \begin_inset LatexCommand index
2500 name "findOn: (message)]"
2504 methodName\InsetSpace ~
2505 findOn:\InsetSpace ~
2508 locates and answers the method for the given
2512 name and group of argument objects.
2515 \begin_layout Description
2518 \begin_inset LatexCommand index
2519 name "findOn:after: (message)"
2523 methodName\InsetSpace ~
2524 findOn:\InsetSpace ~
2525 argumentArray\InsetSpace ~
2529 locates and answers the method following the given one with the same type
2530 of arguments as above.
2533 \begin_layout Description
2536 \begin_inset LatexCommand index
2537 name "sendTo: (message)"
2541 methodName\InsetSpace ~
2542 sendTo:\InsetSpace ~
2545 is an explicit application of a method, useful when the
2549 name of the method needs to be provided at run-time.
2550 It returns the result of the method.
2553 \begin_layout Description
2556 \begin_inset LatexCommand index
2557 name "sendWith: (message)"
2562 \begin_inset LatexCommand index
2563 name "sendWith:with: (message)"
2568 \begin_inset LatexCommand index
2569 name "sendWith:with:with: (message)"
2587 take one, two, and three arguments respectively as above without creating
2588 an array to pass the arguments in.
2589 It returns the result of the method.
2592 \begin_layout Description
2595 \begin_inset LatexCommand index
2596 name "sendTo:through: (message)"
2600 methodName\InsetSpace ~
2601 sendTo:\InsetSpace ~
2602 argumentArray\InsetSpace ~
2603 through:\InsetSpace ~
2606 is an extra option to specify a different signature (the
2610 , where the new lookup starts) for the method than that of the actual argument
2612 It returns the result of the method.
2615 \begin_layout Standard
2628 optional keyword which is passed an
2632 of the alternating keyword
2636 s (not the names of the locals: those are defined per method) and values
2640 \begin_layout Subsubsection
2641 Subjective Dispatch (currently disabled)
2645 \begin_layout Standard
2654 \begin_layout Standard
2655 \begin_inset LatexCommand index
2656 name "dispatch, subjective"
2661 \begin_inset LatexCommand index
2662 name "subjective dispatch"
2666 The multiple dispatch system has an extended dynamic signature form which
2667 can be used to give a
2668 \begin_inset Quotes eld
2672 \begin_inset Quotes erd
2676 \begin_inset Quotes eld
2680 \begin_inset Quotes erd
2683 customization of the Slate environment.
2684 This is an implementation and slight modification of the Us
2685 \begin_inset LatexCommand index
2690 language features conceived of by the Self authors
2691 \begin_inset LatexCommand cite
2699 \begin_layout Paragraph
2703 \begin_layout Enumerate
2704 Slate dispatch signatures are
2705 \begin_inset Quotes eld
2709 \begin_inset Quotes erd
2712 to support two implicit endpoints: one before the first argument and one
2713 after the last argument.
2714 We refer to the first role as an
2715 \begin_inset Quotes eld
2719 \begin_inset Quotes erd
2727 \begin_inset LatexCommand index
2728 name "Layer (object)"
2732 , and to the second as a
2735 \begin_inset LatexCommand index
2736 name "Subject (object)"
2743 \begin_inset Quotes eld
2747 \begin_inset Quotes erd
2751 The layer role, being
2752 \begin_inset Quotes eld
2756 \begin_inset Quotes erd
2759 of the explicit argument positions, has higher precedence than any of them;
2760 the subject role has a correspondingly opposite role: it has the lowest
2764 \begin_layout Enumerate
2765 \begin_inset LatexCommand index
2766 name "seenFrom: (message)"
2770 Two primitive context-handling methods were added to support invoking code
2771 with a different object used for one of these new roles.
2772 What happens is that you execute a block
2775 seenFrom:\InsetSpace ~
2778 in order to make all methods defined within dispatched with that object
2779 as the subject, and all methods looked up in that context (or any other
2781 \begin_inset Quotes eld
2785 \begin_inset Quotes erd
2788 that object) used with that subject in the dispatch.
2791 \begin_layout Standard
2792 The effect of combining these two mechanisms is that there is a means for
2793 the user to dynamically (and transparently) extend existing libraries.
2799 \begin_inset Quotes eld
2803 \begin_inset Quotes erd
2806 power to override, since without dispatching on any other arguments, a
2807 method defined in a layer will match a message before any other can.
2812 usage has a more fine-tuned (or weaker, in another sense) ability to override,
2813 since without any other dispatching, a method defined with a certain subject
2814 will never be called.
2815 However, taking an existing method's signature and defining a customized
2816 version with a subject will allow customizing that specific method without
2817 affecting any other method with that selector.
2820 \begin_layout Paragraph
2824 \begin_layout Itemize
2825 Methods defined with a special subject or layer
2829 with those objects, since they are just dispatch participants accessible
2833 \begin_layout Itemize
2834 Resending messages works just the same within subjective methods as in normal
2835 methods; the same dispatch mechanism is in effect, so the ability to combine
2836 or extend functionality is available.
2839 \begin_layout Itemize
2840 Nesting subjective scopes has a
2844 effect: the actions taken within have run-time scope instead of corresponding
2845 exactly to how code is lexically defined.
2846 This gives the compositional effect that should be apparent when viewing
2847 nested subjective scopes.
2850 \begin_layout Itemize
2851 Methods defined in non-subjective contexts have no subject or layer rather
2853 \begin_inset Quotes eld
2857 \begin_inset Quotes erd
2860 subject: they are for most purposes,
2861 \begin_inset Quotes eld
2865 \begin_inset Quotes erd
2871 \begin_layout Paragraph
2875 \begin_layout Description
2879 \begin_inset LatexCommand index
2880 name "subject (terminology)"
2886 the type of object which provides an appropriate handle for subjective
2887 interleaving behavior in dynamically overriding or extending other methods'
2891 \begin_layout Description
2895 \begin_inset LatexCommand index
2896 name "layer (terminology)"
2902 the type of object which provides an appropriate handle for subjective
2903 layering behavior in dynamically overriding or extending other methods'
2907 \begin_layout Description
2910 \begin_inset LatexCommand index
2911 name "seenFrom: (message)"
2916 seenFrom:\InsetSpace ~
2919 executes the contents of the block with the given
2923 dynamically affecting the execution of the expressions.
2926 \begin_layout Description
2929 \begin_inset LatexCommand index
2930 name "layering: (message)"
2935 layering:\InsetSpace ~
2938 executes the contents of the block with the given
2942 dynamically affecting the execution of the expressions.
2945 \begin_layout Description
2948 \begin_inset LatexCommand index
2949 name "withoutSubject (message)"
2956 executes the contents of the block without any subject.
2959 \begin_layout Description
2962 \begin_inset LatexCommand index
2963 name "withoutLayers (message)"
2970 executes the contents of the block without any layer.
2973 \begin_layout Subsection
2977 \begin_layout Standard
2978 \begin_inset LatexCommand index
2979 name "type annotations"
2983 Input and local slots' types can be specified statically for performance
2984 or documentation reasons, if desired.
2985 The special character
2986 \begin_inset LatexCommand index
2987 name "bang character"
2992 \begin_inset LatexCommand index
2993 name "exclamation mark"
2998 \begin_inset LatexCommand index
2999 name "\\char `\\! (exclamation mark)"
3004 \begin_inset Quotes eld
3012 \begin_inset Quotes erd
3015 is used in the same manner as the dispatch annotation
3016 \begin_inset Quotes eld
3024 \begin_inset Quotes erd
3027 , but type-annotations can occur anywhere.
3028 The type system and inference system in Slate is part of the standard library,
3029 and so is explained later in
3030 \begin_inset LatexCommand vref
3031 reference "sub:Types"
3039 \begin_layout Subsection
3043 \begin_layout Standard
3044 \begin_inset LatexCommand index
3045 name "macro message-sends"
3050 \begin_inset LatexCommand index
3051 name "message-sends, macro"
3055 In order to manipulate syntax trees or provide annotations on source code,
3056 Slate provides another form of message-send called a
3061 Sends of this sort have as their arguments the objects built for the expression
3063 Furthermore, the results of evaluation of macro-sends are placed in the
3064 syntax tree in the same location as the macro-send occupied.
3067 \begin_layout Standard
3068 \begin_inset LatexCommand index
3069 name "` (back-tick)"
3074 \begin_inset LatexCommand index
3079 Preceding any selector with a back-tick (
3083 ) will cause it to be sent as a macro.
3084 This means that the message sent will be dispatched on Slate's
3087 \begin_inset LatexCommand index
3088 name "Syntax Node (object)"
3095 objects, which are produced by the parser and consumed by the compiler.
3096 Macros fit into the process of compiling in this order: the text is processed
3100 \begin_inset LatexCommand index
3101 name "Lexer (object)"
3107 into a stream of tokens, which are consumed by the
3110 \begin_inset LatexCommand index
3111 name "Parser (object)"
3117 to produce a (tree-)stream of
3123 Before being passed to the compiler, the
3126 \begin_inset LatexCommand index
3127 name "macroexpand (message)"
3133 method is recursively called on these syntax trees, which invokes every
3134 macro-level message-send and performs the mechanics of replacing the macro-send
3135 with the result of the method invoked.
3136 With this in mind, the Slate macro system is offered as a flexible communicatio
3137 n system between the code-writer and the compiler or other tools or even
3138 other users, using parse trees as the medium.
3141 \begin_layout Standard
3142 As an example of the expressiveness of this system, we can express the type
3143 annotation and comment features of the Slate language in terms of macros:
3146 \begin_layout Itemize
3148 \begin_inset Quotes eld
3156 \begin_inset Quotes erd
3159 could be replaced by
3160 \begin_inset Quotes eld
3165 someExpression `type: assertedTypeExpression
3168 \begin_inset Quotes erd
3175 macro simply sets the
3179 slot for the expression object.
3182 \begin_layout Itemize
3183 Comments could be applied specifically to particular expressions.
3184 For example, following a syntax element with a comment could be implemented
3186 \begin_inset Quotes eld
3191 theExpression `comment: commentString
3194 \begin_inset Quotes erd
3197 , wrapping the syntax node with a comment annotation.
3200 \begin_layout Itemize
3201 Compile-time evaluation of any expression can be accomplished by calling
3207 This also subsumes the
3211 -prefix for array literals and expression sequences which accomplishes that
3212 for those syntax forms.
3215 \begin_layout Subsubsection
3216 Defining new Macro-methods
3219 \begin_layout Standard
3220 Macros must be dispatched (if at all) upon the traits of expressions' syntactic
3222 This introduces a few difficulties, in that some familiarity is needed
3223 with the parse node types in order to name them.
3224 However, only two things need to be remembered:
3227 \begin_layout Enumerate
3228 The generic syntax node type is
3234 , and this is usually all that is necessary for basic macro-methods.
3237 \begin_layout Enumerate
3238 Syntax node types of various objects and specific expression types can be
3239 had by simply quoting them and asking for their traits, although this might
3240 be too specific in some cases.
3247 is suitable for dispatching on Integers, but not Numbers in general, or
3256 will help dispatch on binary message-sends, but not all message-sends.
3263 works for blocks as well as methods.
3266 \begin_layout Subsubsection
3267 Quoting and Unquoting
3270 \begin_layout Standard
3271 \begin_inset LatexCommand index
3277 \begin_inset LatexCommand index
3283 \begin_inset LatexCommand index
3284 name "`quote (message)"
3289 \begin_inset LatexCommand index
3290 name "`unquote (message)"
3294 A fundamental application of the macro message-send system is the ability
3295 to obtain syntax trees for any expression at run-time.
3296 The most basic methods for this are
3300 , which causes the surrounding expression to use its quoted value as the
3301 input for even normal methods, and
3305 results in an inversion of the action of
3309 , so it can only be provided within quoted expressions.
3312 \begin_layout Standard
3313 An abbreviated form of quotation may be used by surrounding an expression
3318 which has the same effect as sending
3323 The parentheses may be omitted if the inner expression cannot be interpreted
3324 as a message-send (applicable to literal blocks, arrays, numbers, and so
3329 \begin_layout Standard
3330 Lisp macro system users will note that this effectively makes
3334 the same as quasi-quotation.
3342 \begin_layout Paragraph
3346 \begin_layout Standard
3347 \begin_inset LatexCommand index
3348 name "quotation, labelled"
3353 \begin_inset LatexCommand index
3354 name "labelled quotation"
3358 In experience with Lisp macros, nested quotation is often found necessary.
3359 In order to adequately control this, often the quotation prefix symbols
3360 have to be combined in non-intuitive ways to produce the correct code.
3361 Slate includes, as an alternative, two operations which set a label on
3362 a quotation and can unquote within that to the original quotation by means
3363 of referencing the label.
3366 \begin_layout Standard
3367 Most users need time to develop the understanding of the need for higher-order
3368 macros, and this relates to users who employ them.
3369 For reference, a Lisp book which covers the subject of higher-order macros
3370 better than any other is
3375 \begin_inset LatexCommand cite
3381 However, it's also been said that Lisp's notation and the conceptual overhead
3382 required to manage the notation in higher-order macros keeps programmers
3383 from entering the field, so perhaps this new notation will help.
3386 \begin_layout Standard
3387 \begin_inset LatexCommand index
3388 name "`quote: (message)"
3393 \begin_inset LatexCommand index
3394 name "`unquote: (message)"
3401 `quote:\InsetSpace ~
3406 expr2\SpecialChar \-
3408 `unquote:\SpecialChar \-
3412 , and in order for this to work syntactically, the labels must be equal
3413 in value and must be literals.
3414 As well, the unquoting expression has to be a sub-expression of the quotation.
3415 The effect is that nesting an expression more deeply does not require altering
3416 the quotation operators to compensate, and it does indicate better what
3417 the unquoting is intended to do\SpecialChar \@.
3421 \begin_layout Subsubsection
3425 \begin_layout Standard
3426 \begin_inset LatexCommand index
3427 name "cascade, message"
3432 \begin_inset LatexCommand index
3433 name "message cascading"
3438 \begin_inset LatexCommand index
3443 Many object-oriented code idioms involve repeated message-sends to the same
3445 This is common in creating and setting up a new object, or activating many
3446 behaviors in sequence on the same thing (used in a lot of UI code - or
3447 more generally with objects that have many variables or are "facade" objects).
3448 Take notice of the period after the last message in the block.
3449 If you forget, you'll return the last result instead of the original object
3450 your cascading into.
3453 \begin_layout Standard
3454 Smalltalk-80 included a syntax feature to elide the first argument when
3455 repeating message-sends.
3456 In Slate, the first argument of a message send is not a special "receiver",
3457 so support in the basic syntax does not make sense.
3458 The solution is a macro-method which takes an expression (well, its result)
3459 and a block, and enhances the block so that the result of the expression
3460 becomes the implicit context for statement-level (top-level) message expression
3465 \begin_layout LyX-Code
3466 Slate> (addPrototype: #Something derivedFrom: {Cloneable})
3474 \begin_layout LyX-Code
3478 \begin_layout LyX-Code
3479 ("Something traitsWindow" bar: Nil.
3483 \begin_layout Standard
3484 In this expression, a prototype is created and returned by the first expression,
3485 and the block is evaluated with that object substituted for the context,
3490 calls apply to it directly.
3491 We recommend you don't define things this way.
3494 namespace define: #Something &parents: {Cloneable} &slots: {#foo -> Nil.
3498 \begin_layout Standard
3499 There is an additional possibility that it takes care of by allowing the
3500 user to specify an input variable to the block, which will also allow the
3501 code within to refer to the object explicitly.
3502 Also, the default return value for empty-last-statements is modified to
3503 be this object instead of the usual
3508 Without such features, a method which returns its only argument is needed;
3509 in Smalltalk-80, the
3513 method performs this role at the end of a cascade.
3514 To see the effect this would have on Slate library code, take a collection
3515 creation method as an example:
3518 \begin_layout LyX-Code
3519 set@(Set traits) new &capacity: n
3526 contents: (set contents new &capacity: ((n ifNil: [0]) max: 1)).
3536 \begin_layout Standard
3540 \begin_layout LyX-Code
3541 set@(Set traits) new &capacity: n
3545 [contents: (set contents
3546 new &capacity: ((n ifNil: [0]) max: 1)).
3554 \begin_layout Standard
3555 So in this new method, an object is made by cloning the argument
3559 , and then the contents and tally are assigned as before, but not needing
3560 to refer to the object explicitly, and then returning the object (if the
3561 ending period is left off, it'll return the value of the last explicit
3562 expression, just as normal blocks).
3563 However, the message-sends which are not leading a statement do not (and
3564 cannot) use the object as implicit context.
3565 This is intentional, as the results of this kind of pervasive change are
3566 more drastic and would be an entirely different kind of idiom.
3567 If a reference to the implicit context argument is needed in the block,
3568 an input argument may be specified in the block header, and the macro method
3569 will bind it to that object.
3570 A notable property of the
3574 method, since it returns resulting values and has a binary selector, is
3575 composability in a data-flow manner.
3578 \begin_layout Subsubsection
3579 Slots as Block Variables
3582 \begin_layout Standard
3583 \begin_inset LatexCommand index
3584 name "`withSlotsDo: (macro)"
3588 Another macro allows for the slots of an object to appear as local variables
3589 in a method, responding both to accessors and mutators in the appropriate
3590 way (by modifying the object's slots).
3593 \begin_layout Standard
3594 So, the following expression names some slots in the first argument which
3595 should be available as inputs to the second argument, a block.
3596 This is analogous to having Smalltalk's direct slot reference syntax (or
3597 Self's, for that matter), or to Lisp's with-slots macro.
3598 (Again, you shouldn't generally shouldn't create objects this way.)
3601 \begin_layout LyX-Code
3602 Slate> Cloneable clone
3604 `>> [addSlot: #x valued: 2.
3605 addSlot: #y valued: 2]
3607 `withSlotsDo: [| :x :y | x + y].
3613 \begin_layout Subsubsection
3614 Expression Substitution (Not Yet Implemented)
3618 \begin_layout Standard
3619 Expression Substitution
3627 \begin_layout Standard
3630 \begin_inset LatexCommand index
3631 name "`with:as: (message)"
3637 is a proposed protocol for transparent substitution of temporary or locally-pro
3638 vided proxies for environment values and other system elements.
3639 This should provide an effective correspondent of the functionality of
3647 \begin_layout Subsubsection
3648 Source Pattern-matching (Not Yet Implemented)
3652 \begin_layout Standard
3653 Source Pattern Matching
3661 \begin_layout Standard
3662 \begin_inset LatexCommand index
3663 name "pattern-matching"
3667 A future framework for expansion will involve accommodating the types of
3668 source-level pattern-matching used in tools for manipulating code for developme
3669 nt, as in the Smalltalk Refactoring Browser.
3672 \begin_layout Subsection
3677 \begin_layout Standard
3684 \begin_inset LatexCommand index
3685 name "literal syntax"
3690 \begin_inset LatexCommand index
3691 name "syntax, literal"
3698 \begin_layout Subsubsection
3702 \begin_layout Paragraph
3706 \begin_layout Standard
3707 Integers are read in as an arbitrary-precision sequence of digits, without
3711 \begin_layout Paragraph
3715 \begin_layout Standard
3716 Floats are read in as an arbitrary-precision sequence of digits, with a
3717 period noting the decimal position.
3720 \begin_layout Paragraph
3724 \begin_layout Standard
3725 Integers or Floats may be entered with radix up to 36, using the digits
3726 0 to 9 and then A to Z in order, by prefixing the literal with the radix
3727 (numeric base) and '
3745 Case is disregarded for the extra-decimal digits.
3746 The Float radix notation is always read in as a Float, and not an infinite-prec
3750 \begin_layout Subsubsection
3754 \begin_layout Standard
3755 \begin_inset LatexCommand index
3761 \begin_inset LatexCommand index
3767 \begin_inset LatexCommand index
3768 name "\\$ (dollar sign)"
3772 Slate's default support for character literals uses the
3793 are all Character object literals for
3810 Printable and non-printable characters require backslash escapes as shown
3812 \begin_inset LatexCommand vref
3813 reference "cap:Character-Literal-Escapes"
3820 \begin_layout Standard
3822 \begin_inset LatexCommand index
3823 name "characters, special"
3828 \begin_inset LatexCommand index
3829 name "special characters"
3834 \begin_inset LatexCommand index
3835 name "escape (character literal)"
3840 \begin_inset LatexCommand index
3841 name "newline (character literal)"
3846 \begin_inset LatexCommand index
3847 name "carriage return (character literal)"
3852 \begin_inset LatexCommand index
3853 name "tab (character literal)"
3858 \begin_inset LatexCommand index
3859 name "backspace (character literal)"
3864 \begin_inset LatexCommand index
3865 name "null (character literal)"
3870 \begin_inset LatexCommand index
3871 name "bell (character literal)"
3876 \begin_inset LatexCommand index
3877 name "form feed (character literal)"
3882 \begin_inset LatexCommand index
3883 name "vertical feed (character literal)"
3888 \begin_inset LatexCommand index
3889 name "space (character literal)"
3894 \begin_inset LatexCommand index
3895 name "backslash (character literal)"
3900 \begin_inset Float table
3906 \begin_layout Standard
3908 \begin_inset Tabular
3909 <lyxtabular version="3" rows="12" columns="2">
3911 <column alignment="center" valignment="top" leftline="true" width="0pt">
3912 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
3913 <row topline="true" bottomline="true">
3914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3917 \begin_layout Standard
3923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3926 \begin_layout Standard
3933 <row topline="true">
3934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3937 \begin_layout Standard
3943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3946 \begin_layout Standard
3957 <row topline="true">
3958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3961 \begin_layout Standard
3967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3970 \begin_layout Standard
3981 <row topline="true">
3982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3985 \begin_layout Standard
3991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3994 \begin_layout Standard
4005 <row topline="true">
4006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4009 \begin_layout Standard
4015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4018 \begin_layout Standard
4029 <row topline="true">
4030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4033 \begin_layout Standard
4039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4042 \begin_layout Standard
4053 <row topline="true">
4054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4057 \begin_layout Standard
4063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4066 \begin_layout Standard
4077 <row topline="true">
4078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4081 \begin_layout Standard
4087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4090 \begin_layout Standard
4101 <row topline="true">
4102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4105 \begin_layout Standard
4111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4114 \begin_layout Standard
4125 <row topline="true">
4126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4129 \begin_layout Standard
4135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4138 \begin_layout Standard
4149 <row topline="true">
4150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4153 \begin_layout Standard
4159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4162 \begin_layout Standard
4173 <row topline="true" bottomline="true">
4174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4177 \begin_layout Standard
4183 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4186 \begin_layout Standard
4206 \begin_layout Standard
4207 \begin_inset Caption
4209 \begin_layout Standard
4210 \begin_inset LatexCommand label
4211 name "cap:Character-Literal-Escapes"
4215 Character Literal Escapes
4228 \begin_layout Subsubsection
4232 \begin_layout Standard
4233 \begin_inset LatexCommand index
4239 \begin_inset LatexCommand index
4240 name "quotes, single"
4245 \begin_inset LatexCommand index
4246 name "single quotes"
4251 \begin_inset LatexCommand index
4252 name "' (single quote)"
4256 Strings are comprised of any sequence of characters surrounded by single-quote
4258 Strings can include the commenting character (double-quotes) without an
4260 Embedded single-quotes can be provided by using the backslash character
4268 Slate's character literal syntax also embeds into string literals, omitting
4274 All characters that require escapes in character literal syntax also require
4275 escapes when used within string literals, with the exception of double-quote
4276 marks and the addition of single-quote marks.
4279 \begin_layout Standard
4280 The following are all illustrative examples of Strings in Slate:
4283 \begin_layout LyX-Code
4284 'a string comprises any sequence of characters, surrounded by single quotes'
4287 \begin_layout LyX-Code
4288 'strings can include the "comment delimiting" character'
4291 \begin_layout LyX-Code
4292 'and strings can include embedded single quote characters by escaping
4297 \begin_layout LyX-Code
4298 'strings can contain embedded
4301 \begin_layout LyX-Code
4305 \begin_layout LyX-Code
4311 \begin_layout LyX-Code
4316 \begin_layout Standard
4323 ' "and don't forget the empty string"
4326 \begin_layout Subsubsection
4330 \begin_layout Standard
4331 \begin_inset LatexCommand index
4337 \begin_inset LatexCommand index
4343 \begin_inset LatexCommand index
4344 name "\\# (pound sign)"
4352 literal syntax starts with the pound sign character (
4356 ) and consists of all following characters up to the next non-escaped whitespace
4357 or reserved character (whichever comes first), unless the pound sign is
4358 followed exactly by a string literal (in single quotes), in which case
4359 the string's contents become the identifier for the
4364 So, for example, the following are all valid
4375 \begin_layout LyX-Code
4379 \begin_layout LyX-Code
4383 \begin_layout LyX-Code
4387 \begin_layout LyX-Code
4388 #key:word:expression:
4391 \begin_layout LyX-Code
4392 #something_with_underscores
4395 \begin_layout LyX-Code
4396 #'A full string with a
4401 \begin_layout LyX-Code
4405 \begin_layout Standard
4410 and their literals is that any literal with the same value as another also
4419 literal with that value in a Slate system.
4420 This allows fast hashes and comparisons by identity rather than value hashes.
4421 In particular, as with Slate identifiers, a
4425 's value is case-sensitive, so
4436 \begin_layout Standard
4437 Internally, Slate currently keeps one global table for
4441 s, and uses individual context objects to hold local bindings.
4445 \begin_layout Standard
4446 Future, bootstrapped releases may provide for partitioning of the global
4455 \begin_layout Subsubsection
4459 \begin_layout Standard
4460 \begin_inset LatexCommand index
4466 \begin_inset LatexCommand index
4467 name "literal arrays"
4472 \begin_inset LatexCommand index
4478 \begin_inset LatexCommand index
4479 name "\\{\\} (curly braces)"
4483 Arrays can be literally and recursively specified by curly-brace notation
4484 using stops as separators.
4486 \begin_inset LatexCommand index
4487 name "array indices"
4492 \begin_inset LatexCommand index
4493 name "indices, array"
4497 Array indices in Slate are 0-based.
4501 \begin_layout LyX-Code
4508 \begin_layout Standard
4509 returns an array with 4 in position 0, 5 at 1, and an array with objects
4518 inserted into it at position 2.
4521 \begin_layout Standard
4522 \begin_inset LatexCommand index
4523 name "array syntax, immediate"
4528 \begin_inset LatexCommand index
4529 name "immediate array syntax"
4534 \begin_inset LatexCommand index
4540 \begin_inset LatexCommand index
4541 name "\\# (pound sign)"
4545 Immediate array syntax -
4552 - is provided as an alternative to create the array when the method is
4553 compiled, instead of creating a new array on each method invocation.
4554 The syntax is identical except that the first opening brace is preceded
4556 The disadvantage is that no run-time values will be usable.
4559 \begin_layout Standard
4560 \begin_inset LatexCommand index
4561 name "array syntax, literal"
4566 \begin_inset LatexCommand index
4567 name "literal array syntax"
4572 \begin_inset LatexCommand index
4573 name "() (parentheses)"
4578 \begin_inset LatexCommand index
4584 \begin_inset Quotes eld
4588 \begin_inset Quotes erd
4591 syntax is also provided, in the manner of Smalltalk-80,
4592 \begin_inset LatexCommand index
4597 in which all tokens within are treated symbolically, evaluating to an array
4598 of literals as read (but not evaluated) by Slate.
4599 Naturally, these are all evaluated when the surrounding context is compiled.
4603 \begin_layout LyX-Code
4624 Slate> #(quux: a :bar).
4645 \begin_layout Subsubsection
4649 \begin_layout Standard
4650 \begin_inset LatexCommand index
4656 \begin_inset LatexCommand index
4657 name "square brackets"
4662 \begin_inset LatexCommand index
4663 name "[] (square brackets)"
4667 Block syntax basics were covered in
4668 \begin_inset LatexCommand ref
4669 reference "sub:Block-Closures"
4673 ; the precise, full specification includes more features and outlines some
4674 necessary logical rules.
4675 Primarily, blocks are square-bracket-delimited statement sequences with
4676 an optional header that specifies input and local slots (input slots being
4684 \begin_layout Standard
4685 \begin_inset LatexCommand index
4686 name "colon character"
4691 \begin_inset LatexCommand index
4696 Slot names must be valid unary message selectors (see
4697 \begin_inset LatexCommand ref
4698 reference "sub:Unary-Message-sends"
4703 Inputs are distinguished by a prefix colon character (
4707 ), and must occur in the same positional order that the invocation will
4708 use or expect, although they can be interspersed among other slot declarations
4712 \begin_layout Standard
4713 \begin_inset LatexCommand index
4714 name "optional keyword arguments"
4719 \begin_inset LatexCommand index
4720 name "arguments, optional keyword"
4725 \begin_inset LatexCommand index
4726 name "keyword arguments, optional"
4731 \begin_inset LatexCommand index
4732 name "\\& (ampersand)"
4737 \begin_inset LatexCommand index
4742 Optional keyword arguments are specified with an ampersand prefix character
4747 ), and may occur in any order.
4750 \begin_layout Standard
4754 \begin_layout LyX-Code
4758 \begin_layout Standard
4759 evaluates to a block which takes inputs
4767 in that order, has locals
4775 ), and takes an optional parameter to specify
4779 's value when called.
4782 \begin_layout Standard
4783 \begin_inset LatexCommand index
4784 name "rest arguments"
4789 \begin_inset LatexCommand index
4790 name "arguments, rest"
4795 \begin_inset LatexCommand index
4796 name "\\* (asterisk)"
4801 \begin_inset LatexCommand index
4807 \begin_inset Quotes eld
4811 \begin_inset Quotes erd
4814 parameter which becomes an array containing all extra positional (non-keyword)
4815 arguments passed may be specified once in the header in any position relative
4816 to the other parameters, prefixed with an asterisk (e.g.
4824 \begin_layout Standard
4825 \begin_inset LatexCommand index
4826 name "compile-time blocks"
4831 \begin_inset LatexCommand index
4832 name "blocks, compile-time"
4837 \begin_inset LatexCommand index
4838 name "\\#[] (pound-square brackets)"
4842 Blocks may be used to perform arbitrary compile-time calculations, using
4847 -prefix as used for literal arrays and strings.
4858 in the resulting code for the surrounding context (perhaps a method or
4859 top-level expression), as though the block were never there.
4862 \begin_layout Section
4866 \begin_layout Subsection
4867 Overall Organization
4870 \begin_layout Subsubsection
4874 \begin_layout Standard
4875 \begin_inset LatexCommand index
4876 name "lobby (object)"
4881 \begin_inset LatexCommand index
4882 name "objects, global"
4887 \begin_inset LatexCommand index
4888 name "global objects"
4896 is the root namespace object for the Slate object system; it is the
4897 \begin_inset Quotes eld
4901 \begin_inset Quotes erd
4904 by which objects enter the Slate world.
4906 \begin_inset Quotes eld
4910 \begin_inset Quotes erd
4913 objects are really only globally accessible because the lobby is delegated
4914 to by lexical contexts, directly or indirectly.
4915 The lobby in turn may (and often does) delegate to other namespaces which
4916 contain different categorized objects of interest to the applications programme
4917 r, and this can be altered at run-time.
4920 \begin_layout Standard
4921 Every object reference which is not local to a block closure is sent to
4922 the enclosing namespace for resolution, which by default is the root namespace,
4927 (nested closures refer first to their surrounding closure).
4929 \begin_inset LatexCommand index
4938 contains a loopback slot referring to itself by that name.
4939 To add or arrange globals, either implicit sends or explicit references
4940 to the lobby can be made.
4941 (Consider it good style to directly reference it.)
4944 \begin_layout Standard
4945 The lobby is essentially a threading context, and in the future bootstrap
4946 will be instantiable in that sense.
4949 \begin_layout Subsubsection
4953 \begin_layout Standard
4958 provides access to the major
4963 \begin_inset LatexCommand index
4964 name "Namespace (object)"
4968 , which are objects suitable for organizing things (for now, they are essentiall
4974 The most important one is
4979 \begin_inset LatexCommand index
4980 name "prototypes (object)"
4984 , which contains the major kinds of shared behavior used by the system.
4985 Objects there may be cloned and used directly, but they should not themselves
4986 be manipulated without some design effort, since these are global resources,
4987 having a name-path identifier which can be freely shared.
4992 is inherited by the lobby, so it is not necessary to use the namespace
4993 path to identify, for example,
5002 However, without explicitly mentioning the path, adding slots will use
5003 the lobby or the local context by default.
5004 To use the current namespace, an implicit-context message
5007 \begin_inset LatexCommand index
5008 name "here (message)"
5014 is provided which will answer the nearest surrounding namespace object
5015 in the context, which is the
5019 by default, but is polymorphic to namespace shifts.
5022 \begin_layout Standard
5027 namespace further contains inherited namespaces for, by example, collections,
5028 and can be otherwise enhanced to divide up the system into manageable pieces.
5031 \begin_layout Subsection
5035 \begin_layout Standard
5036 \begin_inset Float figure
5042 \begin_layout Standard
5043 \begin_inset VSpace defskip
5049 \begin_layout Standard
5051 \begin_inset Graphics
5052 filename core-web.eps
5059 \begin_layout Standard
5060 \begin_inset VSpace defskip
5066 \begin_layout Standard
5067 \begin_inset Caption
5069 \begin_layout Standard
5070 \begin_inset LatexCommand label
5071 name "cap:Core-delegation"
5075 Core Object Inheritance
5088 \begin_layout Standard
5089 Slate defines several subtle variations on the core behavior of objects:
5092 \begin_layout Description
5096 \begin_inset LatexCommand index
5097 name "Root (object)"
5103 The "root" object, upon which all the very basic methods of slot manipulation
5107 \begin_layout Description
5111 \begin_inset LatexCommand index
5112 name "Oddball (object)"
5122 representing non-cloneable objects.
5123 These include built-in 'constants' such as the
5127 s, as well as literals (value-objects) such as
5143 \begin_inset LatexCommand index
5144 name "clone (message)"
5150 method, but that method will only work once, in that you can clone
5154 but not objects made by cloning
5161 \begin_layout Description
5165 \begin_inset LatexCommand index
5180 representing "no-object".
5183 \begin_layout Description
5187 \begin_inset LatexCommand index
5188 name "NoRole (object)"
5202 representing a non-dispatching participant in a method definition.
5203 Methods cannot be defined directly on
5210 \begin_layout Description
5214 \begin_inset LatexCommand index
5215 name "Derivable (object)"
5228 \begin_inset LatexCommand index
5229 name "derive (message)"
5235 , which means they can be readily used for extension.
5238 \begin_layout Description
5242 \begin_inset LatexCommand index
5243 name "Cloneable (object)"
5260 \begin_layout Description
5264 \begin_inset LatexCommand index
5265 name "Method (object)"
5275 object with attributes for supporting execution of blocks (with closure
5276 semantics, notably) and holding compiled code and its attributes.
5279 \begin_layout Subsubsection
5280 Default Object Features
5283 \begin_layout Description
5285 \begin_inset LatexCommand index
5286 name "identity (terminology)"
5291 \begin_inset LatexCommand index
5297 \begin_inset LatexCommand index
5298 name "\\~{}== (message)"
5306 returns whether the two arguments are identical, i.e.
5307 the same object, and
5313 \begin_layout Standard
5335 \begin_layout Standard
5349 \begin_layout Description
5351 \begin_inset LatexCommand index
5359 \begin_inset LatexCommand index
5360 name "printString (message)"
5366 returns a printed (string) representation of the object.
5370 \begin_inset LatexCommand index
5371 name "printOn: (message)"
5377 places the result of printing onto a designated
5382 \begin_inset LatexCommand index
5383 name "Stream (object)"
5390 \begin_inset LatexCommand index
5391 name "print (message)"
5406 This should be overridden for clarity.
5409 \begin_layout Description
5411 \begin_inset LatexCommand index
5412 name "delegation testing"
5417 \begin_inset LatexCommand index
5418 name "testing, delegation"
5425 \begin_inset LatexCommand index
5426 name "isReally: message"
5432 returns whether the first object has the second (or its traits object if
5437 ) as one of its delegated objects, directly or indirectly.
5440 \begin_layout Description
5442 \begin_inset LatexCommand index
5443 name "testing, kind"
5448 \begin_inset LatexCommand index
5456 \begin_inset LatexCommand index
5457 name "is: (message)"
5463 returns whether the first object has the same kind as the second object,
5464 or some derived kind from the second object's kind.
5473 ; overrides can allow the user to adapt or abuse this notion where delegation
5474 isn't appropriate but kind-similarity still should hold.
5478 \begin_inset LatexCommand index
5479 name "isSameAs: (message)"
5485 answers whether the arguments have the same traits object.
5488 \begin_layout Description
5490 \begin_inset LatexCommand index
5495 A quick way to sort by object value that makes searching collections faster
5499 \begin_inset LatexCommand index
5500 name "hash (message)"
5506 method, which by default hashes on the object's identity (available separately
5512 \begin_inset LatexCommand index
5513 name "identityHash (message)"
5517 ), essentially by its birth address in memory.
5518 More importantly, this is how value-equality
5519 \begin_inset LatexCommand index
5520 name "equality, value"
5525 \begin_inset LatexCommand index
5526 name "value equality"
5530 is established for collections; if an object type overrides =
5531 \begin_inset LatexCommand index
5532 name "= (equal sign)"
5537 \begin_inset LatexCommand index
5542 , it must also override the
5546 method's algorithm so that
5553 \begin_inset Formula $\Rightarrow$
5567 \begin_layout Description
5569 \begin_inset LatexCommand index
5577 \begin_inset LatexCommand index
5578 name "clone (message)"
5584 method is fundamental for Slate objects.
5585 It creates and returns a new object identical in slot names and values
5586 to the argument object, but with a new unique identity.
5587 As such, it has a very specific meaning and should only be used that way.
5590 \begin_layout Description
5592 \begin_inset LatexCommand index
5600 \begin_inset LatexCommand index
5601 name "copy (message)"
5607 method makes a value-equal (
5611 ) object from the argument and returns the new object.
5612 This should be overridden as necessary where
5617 The default case is to clone the original object.
5620 \begin_layout Description
5622 \begin_inset LatexCommand index
5628 \begin_inset LatexCommand index
5636 \begin_inset LatexCommand index
5637 name "as: (message)"
5643 protocol provides default conversion methods between types of objects in
5645 Some primitive types, such as
5654 method has a default implementation on root objects: if no converter is
5655 found or if the objects are not of the same type, the failure will raise
5657 Precisely, the behavior of
5663 is to produce an object based on
5667 which is as much like
5674 \begin_layout Subsubsection
5678 \begin_layout Standard
5679 \begin_inset LatexCommand index
5688 s in the system, and they are non-cloneable in general.
5693 itself may be cloned, for extension purposes.
5696 \begin_layout Subsection
5700 \begin_layout Subsubsection
5704 \begin_layout Standard
5705 Objects may be queried directly for various attributes that they have.
5706 These should not be used in ordinary
5707 \begin_inset Quotes eld
5711 \begin_inset Quotes erd
5714 code, only in specific uses which need to operate on arbitrary object-slot
5715 structures or inside of accessor methods.
5718 \begin_layout Description
5721 \begin_inset LatexCommand index
5722 name "atSlotNamed: (message)"
5728 answers the value of the slot with the given name.
5731 \begin_layout Description
5734 \begin_inset LatexCommand index
5735 name "atSlotNamed:put: (message)"
5741 fills the delegate slot with the given name.
5742 It answers the object modified.
5745 \begin_layout Description
5748 \begin_inset LatexCommand index
5749 name "slotNames (message)"
5759 of the names of the object's direct slots.
5762 \begin_layout Description
5765 \begin_inset LatexCommand index
5766 name "delegates (message)"
5774 \begin_layout Standard
5790 of the names of the object's direct delegate slots.
5793 \begin_layout Description
5796 \begin_inset LatexCommand index
5797 name "slotsDo: (message)"
5803 applies a block to each slot's value.
5806 \begin_layout Description
5809 \begin_inset LatexCommand index
5810 name "delegatesDo: (message)"
5816 applies a block to each delegate slot's value.
5819 \begin_layout Description
5822 \begin_inset LatexCommand index
5823 name "addAccessorFor: (message)"
5829 defines a default accessor (aka
5830 \begin_inset Quotes eld
5834 \begin_inset Quotes erd
5837 ) method for the slot with the given name.
5840 \begin_layout Description
5843 \begin_inset LatexCommand index
5844 name "addMutatorFor: (message)"
5850 defines a default mutator (aka
5851 \begin_inset Quotes eld
5855 \begin_inset Quotes erd
5858 ) method for the slot with the given name.
5861 \begin_layout Description
5864 \begin_inset LatexCommand index
5865 name "addAccessor:for: (message)"
5871 installs the given method as accessor for the slot with the given name.
5874 \begin_layout Description
5877 \begin_inset LatexCommand index
5878 name "addMutator:for: (message)"
5884 installs the given method as mutator for the slot with the given name.
5887 \begin_layout Subsubsection
5891 \begin_layout Standard
5892 Slate includes a protocol for common query operations on
5899 \begin_layout Description
5902 \begin_inset LatexCommand index
5903 name "selector (message)"
5917 if it has been defined and installed under some objects' roles, or
5921 if it is unnamed (an ordinary block).
5924 \begin_layout Description
5927 \begin_inset LatexCommand index
5928 name "isNamed (method)"
5938 is a named method; that is, whether it is installed with a dispatch signature
5942 \begin_layout Description
5945 \begin_inset LatexCommand index
5946 name "arity (message)"
5952 answers the number of arguments expected as input to the
5957 This excludes any optional keyword arguments or rest arguments that it
5959 This also applies to the quoted form of a literal method.
5962 \begin_layout Description
5965 \begin_inset LatexCommand index
5966 name "acceptsAdditionalArguments (message)"
5970 acceptsAdditionalArguments
5976 takes a rest parameter.
5979 \begin_layout Description
5982 \begin_inset LatexCommand index
5983 name "allSelectorsSent (message)"
5997 s that the block directly (in its defining source) sends.
5998 This also applies to the quoted form of a literal method.
6001 \begin_layout Description
6004 \begin_inset LatexCommand index
6005 name "methodsNamed: (message)"
6011 answers all distinct
6015 objects with the given name stored in roles on the given object.
6018 \begin_layout Description
6021 \begin_inset LatexCommand index
6022 name "methodsAt: (message)"
6028 answers all distinct
6032 objects stored in the role position given on the given object.
6035 \begin_layout Description
6038 \begin_inset LatexCommand index
6039 name "methodsNamed:at: (message)"
6045 answers all distinct
6049 objects stored in roles on the given object with the given name and at
6050 the given role position.
6053 \begin_layout Description
6056 \begin_inset LatexCommand index
6057 name "methodsCalling: (message)"
6063 answers all distinct
6067 objects stored in roles on the given object which send the given selector.
6070 \begin_layout Description
6073 \begin_inset LatexCommand index
6074 name "signature (message)"
6078 signature\InsetSpace ~
6085 object (roles plus selector) corresponding to the given (named)
6090 This currently involves a search and takes a variable amount of time.
6093 \begin_layout Description
6096 \begin_inset LatexCommand index
6097 name "implementations (message)"
6121 optional parameter restricts the search to one object (as namespace).
6124 \begin_layout Description
6127 \begin_inset LatexCommand index
6128 name "callers (message)"
6143 s which send the argument selector.
6148 optional parameter restricts the search to one object (as namespace).
6151 \begin_layout Description
6154 \begin_inset LatexCommand index
6155 name "macroCallers (message)"
6170 s which send the argument selector.
6175 optional parameter restricts the search to one object (as namespace).
6178 \begin_layout Subsection
6182 \begin_layout Standard
6183 \begin_inset LatexCommand index
6188 Slate objects, from the root objects down, all respond to the message
6193 \begin_inset LatexCommand index
6194 name "traits (message)"
6198 , which is conceptually shared behavior but is not as binding as a class
6200 It returns an object which is, by convention, the location to place shared
6202 Most Slate method definitions are defined upon some object's
6207 This is significant because cloning an object with a traits delegation
6208 slot will result in a new object with the same object delegated-to, so
6209 all methods defined on that traits object apply to the new clone.
6210 There is one core method which drives derivation:
6213 \begin_layout Description
6216 \begin_inset LatexCommand index
6217 name "derive (message)"
6221 myObject\InsetSpace ~
6223 &mixins:\InsetSpace ~
6226 will return a new clone of the
6230 object with a traits object which is cloned from the original's traits
6231 object, and an immutable delegation slot set between the traits objects.
6232 If mixins are given, it will include more immutable delegation links between
6233 the new traits and the traits of the array's objects, in the given order,
6234 which achieves a structured, shared behavior of static multiple delegation.
6235 Note that the delegation link addition order makes the right-most delegation
6236 target override the former ones in that order.
6237 One interesting property of this method is that the elements of the mixins
6245 \begin_layout Standard
6246 In practice, the following wrapper is the appropriate method to use in common
6247 situations, since it handles the installation of the prototype in a cleaner
6251 \begin_layout Description
6254 \begin_inset LatexCommand index
6255 name "addPrototype:derivedFrom:"
6260 addPrototype:\InsetSpace ~
6262 derivedFrom:\InsetSpace ~
6265 will perform the effects of
6269 using all the elements of the
6273 in the same order as
6278 It also assigns the name to the traits object's name attribute (which should
6283 ) as well as using the name for the attribute between the surrounding object
6284 and the new prototype.
6285 Finally, it will compare the delegation pattern of the new object with
6286 the old, and only replace the old if they differ.
6287 In either case, the installed object is what is returned, and the existing
6288 traits object will be re-used if there is one.
6291 \begin_layout Description
6294 \begin_inset LatexCommand index
6295 name "define: (message)"
6300 define:\InsetSpace ~
6302 &parents:\InsetSpace ~
6303 parentsArray\InsetSpace ~
6304 &slots:\InsetSpace ~
6307 performs the effects of
6311 using all the elements of the
6315 in the same order as
6320 The default parent is just
6325 It also assigns the name to the traits object's name attribute (which should
6330 ) as well as using the name for the attribute between the surrounding object
6331 and the new prototype.
6336 needs to be an array with either
6348 s to values, to specify (mutable) state-slots and their attributes.
6349 Finally, it will compare the delegation pattern of the new object with
6350 the old, and only replace the old if they differ.
6351 In either case, the installed object is what is returned, and the existing
6352 traits object will be re-used if there is one.
6357 form is also provided which takes a block and uses its resulting value
6362 can be used in conjuction with
6370 , as no derivation is relevant.
6373 \begin_layout Standard
6374 As with any method in Slate, these may be overridden to provide additional
6375 automation and safety in line with their semantics.
6378 \begin_layout Paragraph
6382 \begin_layout Standard
6383 Beneath this simple system is a level of indirection which allows for greater
6388 over the combination of parent behaviors; for most purposes, they may be
6390 What is actually the case is that each object points to an object in a
6400 is defined to be the first delegate in an object's delegates array and
6405 is defined to be the last delegate in an object's
6412 \begin_layout Standard
6413 Because the delegates of an object are easily changed, there is a great
6414 deal of control over the order of precedence This means that nearly all
6415 of the problems of precedence in a multiple inheritance graph may be resolved
6420 \begin_layout Standard
6421 The classical illustration of multiple inheritance issues is the
6422 \begin_inset Quotes eld
6426 \begin_inset Quotes erd
6429 problem where one parent is inherited via two different paths indirectly.
6430 Solutions that involve choosing inheritance graph traversal orders for
6431 the whole language are insufficiently flexible in dealing with multiple
6432 inheritance confusion, since various protocols need to interact independently.
6437 There is also a hint to the lookup procedure in the
6441 objects that a meta-level has been reached.
6442 Once one meta-transition has occurred during lookup, the algorithm will
6443 not traverse such a transition again; thus Slate avoids a lookup confusion
6444 between methods meant for regular objects and those meant for the traits
6448 \begin_layout Subsection
6449 Blocks, Booleans, and Control-Flow
6453 \begin_layout Standard
6462 \begin_layout Subsubsection
6466 \begin_layout Standard
6467 \begin_inset LatexCommand index
6468 name "boolean logic"
6472 Slate's evaluator primitively provides the objects
6475 \begin_inset LatexCommand index
6476 name "True (object)"
6487 \begin_inset LatexCommand index
6488 name "False (object)"
6492 , which are clones of
6497 \begin_inset LatexCommand index
6498 name "Boolean (object)"
6504 Boolean\InsetSpace ~
6508 Logical methods are defined on these in a very minimalistic way.
6510 \begin_inset LatexCommand vref
6511 reference "cap:Basic-Logical-Operators"
6515 shows the non-lazy logical methods and their meanings.
6518 \begin_layout Standard
6519 \begin_inset LatexCommand index
6520 name "boolean messages"
6525 \begin_inset LatexCommand index
6531 \begin_inset LatexCommand index
6532 name "\\char `\\/\\char `\\\\ (message)"
6537 \begin_inset LatexCommand index
6543 \begin_inset LatexCommand index
6544 name "\\char `\\\\\\char `\\/ (message)"
6549 \begin_inset LatexCommand index
6550 name "not (message)"
6555 \begin_inset LatexCommand index
6556 name "eqv: (message)"
6561 \begin_inset LatexCommand index
6562 name "xor: (message)"
6567 \begin_inset Float table
6572 \begin_layout Standard
6574 \begin_inset Tabular
6575 <lyxtabular version="3" rows="6" columns="2">
6577 <column alignment="center" valignment="top" leftline="true" width="0pt">
6578 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
6579 <row topline="true" bottomline="true">
6580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
6583 \begin_layout Standard
6589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
6592 \begin_layout Standard
6599 <row bottomline="true">
6600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
6603 \begin_layout Standard
6609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
6612 \begin_layout Standard
6624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
6627 \begin_layout Standard
6637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
6640 \begin_layout Standard
6651 <row topline="true">
6652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
6655 \begin_layout Standard
6661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
6664 \begin_layout Standard
6673 <row topline="true">
6674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
6677 \begin_layout Standard
6683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
6686 \begin_layout Standard
6695 <row topline="true" bottomline="true">
6696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
6699 \begin_layout Standard
6705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
6708 \begin_layout Standard
6724 \begin_layout Standard
6725 \begin_inset Caption
6727 \begin_layout Standard
6728 \begin_inset LatexCommand label
6729 name "cap:Basic-Logical-Operators"
6733 Basic Logical Operators
6746 \begin_layout Subsubsection
6747 Basic Conditional Evaluation
6750 \begin_layout Standard
6751 \begin_inset LatexCommand index
6752 name "conditional evaluation"
6757 \begin_inset LatexCommand index
6758 name "evaluation, conditional"
6762 Logical methods are provided which take a block as their second argument
6792 By accepting a block as the second argument, they can and do provide conditiona
6793 l evaluation of the second argument only in the case that the first does
6794 not decide the total result automatically
6798 \begin_layout Standard
6799 However, support for blocks in the second argument position may be incorporated
6800 into the non-lazy selectors as different methods in the future, making
6801 some of these obsolete.
6808 \begin_inset LatexCommand index
6809 name "evaluation, lazy"
6814 \begin_inset LatexCommand index
6815 name "lazy evaluation"
6819 Blocks that evaluate logical expressions can be used lazily in these logical
6824 \begin_layout LyX-Code
6830 \begin_layout Standard
6831 only evaluates the right-hand block argument if the first argument turns
6839 \begin_layout LyX-Code
6845 \begin_layout Standard
6846 only evaluates the right-hand block argument if the first argument turns
6854 \begin_layout Standard
6855 In general, the basic of booleans to switch between code alternatives is
6861 \begin_inset LatexCommand index
6862 name "ifTrue: (message)"
6871 \begin_inset LatexCommand index
6872 name "ifFalse: (message)"
6879 \begin_inset LatexCommand index
6880 name "ifTrue:ifFalse: (message)"
6886 for the various combinations of binary branches.
6890 \begin_layout LyX-Code
6891 x isNegative ifTrue: [x: x negated].
6894 \begin_layout Standard
6899 is positive by optionally executing code to assign a positive form if it's
6901 Of course if only the result is desired, instead of just the side-effect,
6902 the entire expression's result will be the result of the executed block,
6903 so that it can be embedded in further expressions.
6906 \begin_layout Standard
6907 Conditional evaluation can also be driven by whether or not a slot has been
6908 initialized, or whether a method returns
6913 There are a few options for conditionalizing on
6920 \begin_layout Description
6923 \begin_inset LatexCommand index
6924 name "ifNil: (message)"
6929 \begin_inset LatexCommand index
6930 name "ifNotNil: (message)'"
6942 ifNotNil:\InsetSpace ~
6946 execute their blocks based on whether the expression evaluates to Nil,
6947 and returns the result.
6950 \begin_layout Description
6953 \begin_inset LatexCommand index
6954 name "ifNil:ifNotNil: (message)"
6960 nilBlock\InsetSpace ~
6961 ifNotNil:\InsetSpace ~
6964 provides both options in one expression.
6967 \begin_layout Description
6970 \begin_inset LatexCommand index
6971 name "ifNotNilDo: (message)"
6976 \begin_inset LatexCommand index
6977 name "ifNil:ifNotNilDo: (message)"
6982 ifNotNilDo:\InsetSpace ~
6985 applies the block to the expression's result if it turns out to be non-
6989 , so the block given must accept one argument.
6996 is also provided for completeness.
6999 \begin_layout Standard
7001 \begin_inset Quotes eld
7005 \begin_inset Quotes erd
7011 \begin_layout Description
7014 \begin_inset LatexCommand index
7015 name "caseOf: (message)"
7020 \begin_inset LatexCommand index
7021 name "caseOf:otherwise: (message)"
7026 caseOf:\InsetSpace ~
7028 otherwise:\InsetSpace ~
7031 takes the result of the first argument and the
7043 ) from objects to blocks and executes the first block associated with a
7044 value equal to the expression.
7045 If none match, the last argument is executed; the otherwise: clause may
7046 be omitted, to just do / return nothing.
7049 \begin_layout Subsubsection
7050 \begin_inset LatexCommand label
7051 name "sub:Early-Returns"
7058 \begin_layout Standard
7059 \begin_inset LatexCommand index
7065 \begin_inset LatexCommand index
7066 name "return, early"
7070 Control-flow within methods can be skipped with a return value using the
7075 message to the context.
7080 takes its second argument and exits the nearest surrounding lexical scope
7081 that is a named method (and not an anonymous code block) with that value.
7082 This message is a real binary message with no special precedence, so disambigua
7083 tion is often needed.
7087 \begin_layout LyX-Code
7091 \begin_layout LyX-Code
7095 \begin_layout Standard
7096 return the expressions on the left as a whole, but
7099 \begin_layout LyX-Code
7103 \begin_layout LyX-Code
7107 \begin_layout LyX-Code
7108 ^ set collect: [| :each | each name]
7111 \begin_layout LyX-Code
7112 ^ (set collect: [| :each | each name])
7115 \begin_layout Standard
7116 represent expression variations where a lack of disambiguation results in
7117 returning an unintended answer.
7120 \begin_layout Subsubsection
7122 \begin_inset LatexCommand label
7130 \begin_layout Standard
7131 \begin_inset LatexCommand index
7136 Slate includes various idioms for constructing basic loops.
7137 These are all built from ordinary methods which work with code blocks,
7138 and any ordinary code may define similar idioms rather quickly.
7141 \begin_layout Description
7144 \begin_inset LatexCommand index
7145 name "loop (message)"
7151 executes the block repeatedly, indefinitely
7155 \begin_layout Standard
7156 This is currently implemented through a compiler rule.
7164 \begin_layout Description
7167 \begin_inset LatexCommand index
7168 name "timesRepeat: (message)"
7173 timesRepeat:\InsetSpace ~
7183 \begin_layout Description
7186 \begin_inset LatexCommand index
7187 name "whileTrue: (message)"
7192 \begin_inset LatexCommand index
7193 name "whileFalse: (message)"
7197 condition\InsetSpace ~
7198 whileTrue:\InsetSpace ~
7204 condition\InsetSpace ~
7205 whileFalse:\InsetSpace ~
7209 execute their blocks repeatedly, checking the condition before each iteration
7210 (implying that the body block will not be executed if the condition is
7214 \begin_layout Description
7217 \begin_inset LatexCommand index
7218 name "whileTrue (message)"
7223 \begin_inset LatexCommand index
7224 name "whileFalse (message)"
7236 execute their blocks repeatedly, checking the return value before repeating
7237 iterations (so that they will always execute at least one time).
7240 \begin_layout Description
7243 \begin_inset LatexCommand index
7244 name "upTo:do: (message)"
7249 \begin_inset LatexCommand index
7250 name "downTo:do: (message)"
7264 downTo:\InsetSpace ~
7270 executes the block with each number in turn from
7281 \begin_layout Description
7284 \begin_inset LatexCommand index
7285 name "upTo:by:do: (message)"
7290 \begin_inset LatexCommand index
7291 name "downTo:by:do: (message)"
7303 executes the block with each number in turn in the inclusive range, with
7304 the given stepping increment.
7307 \begin_layout Description
7310 \begin_inset LatexCommand index
7311 name "below:do: (message)"
7316 \begin_inset LatexCommand index
7317 name "above:do: (message)"
7337 act identically to the previous method except that they stop just before
7339 This assists in iterating over array ranges, where the 0-based indexing
7340 makes a difference in range addresses by one, avoiding excessive use of
7350 \begin_layout Description
7353 \begin_inset LatexCommand index
7354 name "below:by:do: (message)"
7359 \begin_inset LatexCommand index
7360 name "above:by:do: (message)"
7372 vary on the previous methods with the given stepping increment.
7375 \begin_layout Standard
7376 \begin_inset Note Note
7379 \begin_layout Standard
7380 Slate's looping control structures can easily be extended without concern
7381 due to the fact that the evaluator
7385 at one point unroll properly tail-recursive blocks into low-level loop
7386 code that re-uses the same activation frame.
7387 So basically structuring custom looping code so that it calls itself last
7388 within its own body and returns that value will avoid the need for increasing
7389 stack space per iteration.
7390 (Turn this back into a paragraph if it is implemented again.)
7398 \begin_layout Subsubsection
7402 \begin_layout Standard
7403 Slate provides some powerful methods for operating on
7407 (block) objects themselves.
7408 The answers of these operations are also fully-fledged
7412 objects which respond to all of the normal queries and are useful anywhere
7420 \begin_layout Description
7423 \begin_inset LatexCommand index
7429 \begin_inset LatexCommand index
7430 name "method composition"
7440 s in a functional manner, so that
7441 \begin_inset Formula $(F\circ G)(x)=F(G(x))$
7444 ; basically the result of applying the first to the result of the second
7445 (which in turn consumes the input).
7446 This operation is associative, so grouping of continued applications should
7448 This semantics assumes that the inner/right function
7449 \begin_inset Formula $G$
7452 may take any number of arguments, and that
7453 \begin_inset Formula $F$
7457 If both of these are false, then there is an extended form of the semantics
7459 \begin_inset Formula $F$
7462 is used to group the results of applying
7463 \begin_inset Formula $G$
7466 to each element in the argument array.
7467 The groups are then passed as a whole to one invocation of
7468 \begin_inset Formula $F$
7474 \begin_layout Description
7477 \begin_inset LatexCommand index
7488 taken as a message selector and expands into an appropriate
7492 which takes an appropriate number of arguments for the selector and sends
7493 the selector to those arguments, answering the result.
7514 \begin_layout Description
7517 \begin_inset LatexCommand index
7518 name "converse (message)"
7532 with the same body but with input argument order reversed.
7535 \begin_layout Description
7536 \begin_inset LatexCommand index
7542 \begin_inset LatexCommand index
7555 and an object and returns a new
7559 with the same body but with the object substituted for the first argument,
7560 so it takes one less argument.
7561 This is also known as
7582 curry the next three argument positions and the last argument, respectively.
7587 fills the N'th argument.
7590 \begin_layout Description
7593 \begin_inset LatexCommand index
7594 name "`commutatively (macro)"
7604 and defines it with two signatures, one reversed from the original definition,
7608 \begin_layout Subsection
7612 \begin_layout Standard
7613 \begin_inset LatexCommand index
7614 name "Symbol (object)"
7619 \begin_inset LatexCommand index
7625 \begin_inset LatexCommand index
7626 name "intern (message)"
7631 \begin_inset LatexCommand index
7632 name "intern: (message)"
7637 \begin_inset LatexCommand index
7638 name "name (message)"
7646 s in Slate are basically a large group of
7650 s sorted by identity into a global table
7659 is created or identified by taking a
7667 method on it (or alternately, the context message
7684 object will return the exact same
7702 \begin_inset LatexCommand ref
7703 reference "sub:Sequences"
7711 must be asked for its
7715 which gives a separate
7719 with its value; the results of these operations will still be
7734 \begin_layout Subsection
7735 Magnitudes and Numbers
7738 \begin_layout Subsubsection
7740 \begin_inset LatexCommand index
7746 \begin_inset LatexCommand index
7754 \begin_layout Description
7758 \begin_inset LatexCommand index
7759 name "Magnitude (object)"
7765 the abstract protocol for linearly-comparable objects, following
7788 \begin_layout Description
7792 \begin_inset LatexCommand index
7793 name "Number (object)"
7799 the abstract type of dimensionless quantities.
7802 \begin_layout Description
7806 \begin_inset LatexCommand index
7807 name "Integer (object)"
7813 integral quantities, generally.
7816 \begin_layout Description
7820 \begin_inset LatexCommand index
7821 name "SmallInteger (object)"
7827 machine-word-limited integer values (minus 1 bit for the immediate-value
7829 Their normal protocol will not produce errors inconsistent with mathematic
7834 s, however: instead of overflows,
7838 objects of the appropriate value are returned.
7841 \begin_layout Description
7845 \begin_inset LatexCommand index
7846 name "BigInteger (object)"
7856 s, implemented by wrapping
7861 \begin_inset LatexCommand index
7862 name "ByteArray (object)"
7866 s with the appropriate behavior.
7869 \begin_layout Description
7873 \begin_inset LatexCommand index
7874 name "Fraction (object)"
7880 An exact representation of a quotient, or rational number.
7883 \begin_layout Description
7887 \begin_inset LatexCommand index
7888 name "Float (object)"
7894 A low-level floating-point numeric representation, being inexact.
7895 Floats are currently only implemented as
7898 \begin_inset LatexCommand index
7899 name "SingleFloat (object)"
7905 , a single-precision floating-point number representation.
7908 \begin_layout Description
7912 \begin_inset LatexCommand index
7913 name "Complex (object)"
7919 A complex number, similar to a pair of real numbers.
7922 \begin_layout Subsubsection
7926 \begin_layout Standard
7927 \begin_inset LatexCommand index
7928 name "operations, basic"
7933 \begin_inset LatexCommand index
7934 name "basic operations"
7939 \begin_inset LatexCommand index
7945 \begin_inset LatexCommand index
7951 \begin_inset LatexCommand index
7957 \begin_inset LatexCommand index
7958 name "operations, arithmetic"
7963 \begin_inset LatexCommand index
7964 name "arithmetic operations"
7969 \begin_inset LatexCommand index
7975 \begin_inset LatexCommand index
7981 \begin_inset LatexCommand index
7987 \begin_inset LatexCommand index
7988 name "multiplication"
7993 \begin_inset LatexCommand index
7999 \begin_inset LatexCommand index
8005 \begin_inset LatexCommand index
8011 \begin_inset LatexCommand index
8017 \begin_inset LatexCommand index
8018 name "slash, forward"
8023 \begin_inset LatexCommand index
8024 name "forward slash"
8029 \begin_inset LatexCommand index
8030 name "\\char `\\/ (forward slash)"
8034 All of the normal arithmetic operations (i.e.
8051 ) are supported primitively between elements of the same type.
8052 Type coercion has to be done entirely in code; no implicit coercions are
8053 performed by the virtual machine.
8054 However, the standard library includes methods which perform this coercion.
8055 The interpreter also transparently provides unlimited-size integers, although
8056 the bootstrapped system may not do so implicitly.
8059 \begin_layout Standard
8060 The following are the rest of the primitive operations, given with an indication
8061 of their "signatures":
8064 \begin_layout Description
8067 \begin_inset LatexCommand index
8068 name "raisedTo: (message)"
8073 \begin_inset LatexCommand index
8074 name "exponentiation"
8079 \begin_inset LatexCommand index
8080 name "power, raising to a"
8085 raisedTo:\InsetSpace ~
8088 is simple floating-point exponentiation.
8091 \begin_layout Description
8094 \begin_inset LatexCommand index
8095 name "as: (message)"
8100 \begin_inset LatexCommand index
8101 name "conversion, number"
8106 \begin_inset LatexCommand index
8107 name "number conversion"
8111 Integer\InsetSpace ~
8115 extends an integer into a float.
8118 \begin_layout Description
8128 \begin_layout Description
8131 \begin_inset LatexCommand index
8132 name "bitOr: (message)"
8137 \begin_inset LatexCommand index
8138 name "bit operations"
8143 \begin_inset LatexCommand index
8144 name "operations, bit"
8148 Integer\InsetSpace ~
8152 performs bitwise logical
8159 \begin_layout Description
8162 \begin_inset LatexCommand index
8163 name "bitXor: (message)"
8167 Integer\InsetSpace ~
8168 bitXor:\InsetSpace ~
8171 performs bitwise logical
8178 \begin_layout Description
8181 \begin_inset LatexCommand index
8182 name "bitAnd: (message)"
8186 Integer\InsetSpace ~
8187 bitAnd:\InsetSpace ~
8190 performs bitwise logical
8197 \begin_layout Description
8200 \begin_inset LatexCommand index
8201 name "bitShift: (message)"
8205 Integer\InsetSpace ~
8206 bitShift:\InsetSpace ~
8209 performs bitwise logical right-shift (left-shift if negative).
8212 \begin_layout Description
8215 \begin_inset LatexCommand index
8216 name "bitNot (message)"
8220 Integer\InsetSpace ~
8223 performs bitwise logical
8230 \begin_layout Description
8233 \begin_inset LatexCommand index
8238 Integer\InsetSpace ~
8242 performs logical right-shift.
8245 \begin_layout Description
8248 \begin_inset LatexCommand index
8253 Integer\InsetSpace ~
8257 performs logical left-shift.
8260 \begin_layout Description
8263 \begin_inset LatexCommand index
8264 name "quo: (message)"
8269 \begin_inset LatexCommand index
8275 \begin_inset LatexCommand index
8276 name "division, integer"
8281 \begin_inset LatexCommand index
8282 name "integer division"
8286 Integer\InsetSpace ~
8290 returns a quotient (integer division).
8293 \begin_layout Standard
8294 \begin_inset LatexCommand index
8295 name "mod: (mesage)"
8300 \begin_inset LatexCommand index
8301 name "reciprocal: (message)"
8306 \begin_inset LatexCommand index
8307 name "min: (message)"
8312 \begin_inset LatexCommand index
8313 name "max: (message)"
8318 \begin_inset LatexCommand index
8319 name "between:and: (message)"
8324 \begin_inset LatexCommand index
8325 name "lcm: (message)"
8330 \begin_inset LatexCommand index
8331 name "gcd: (message)"
8336 \begin_inset LatexCommand index
8337 name "Fraction (object)"
8341 Many more useful methods are defined, such as
8370 Slate also works with
8374 when dividing Integers, keeping them lazily reduced.
8377 \begin_layout Subsubsection
8381 \begin_layout Description
8384 \begin_inset LatexCommand index
8385 name "zero (message)"
8391 The zero element for the type of number.
8394 \begin_layout Description
8397 \begin_inset LatexCommand index
8398 name "isZero (message)"
8404 Whether the number is the zero element for its type.
8407 \begin_layout Description
8410 \begin_inset LatexCommand index
8411 name "isPositive (message)"
8416 \begin_inset LatexCommand index
8417 name "isNegative (message)"
8427 Whether it's positive or negative.
8430 \begin_layout Description
8433 \begin_inset LatexCommand index
8434 name "abs (message)"
8440 The absolute value of the number.
8443 \begin_layout Description
8446 \begin_inset LatexCommand index
8447 name "sign (message)"
8453 The sign of the number.
8456 \begin_layout Description
8459 \begin_inset LatexCommand index
8460 name "negated (message)"
8477 \begin_layout Description
8480 \begin_inset LatexCommand index
8481 name "gcd: (message)"
8487 Greatest common divisor.
8490 \begin_layout Description
8493 \begin_inset LatexCommand index
8494 name "lcm: (message)"
8500 Least common multiple.
8503 \begin_layout Description
8506 \begin_inset LatexCommand index
8507 name "factorial (message)"
8516 \begin_layout Description
8519 \begin_inset LatexCommand index
8520 name "mod: (message)"
8525 \begin_inset LatexCommand index
8526 name "rem: (message)"
8531 \begin_inset LatexCommand index
8532 name "quo: (message)"
8546 Modulo division, remainder, and quotient.
8549 \begin_layout Description
8552 \begin_inset LatexCommand index
8553 name "reciprocal (message)"
8559 Constructs a new fraction reciprocal.
8562 \begin_layout Description
8565 \begin_inset LatexCommand index
8566 name "min: (message)"
8572 The lesser of the arguments.
8573 The least in cases of
8580 \begin_layout Description
8583 \begin_inset LatexCommand index
8584 name "max: (message)"
8590 The greater of the arguments.
8591 The greatest in cases of
8598 \begin_layout Description
8601 \begin_inset LatexCommand index
8602 name "between:and: (message)"
8607 between:\InsetSpace ~
8627 \begin_layout Description
8630 \begin_inset LatexCommand index
8631 name "truncated (message)"
8636 \begin_inset LatexCommand index
8637 name "fractionPart (message)"
8647 answers the greatest integer less than the number, and the corresponding
8648 difference as a fraction (or a float for
8655 \begin_layout Description
8658 \begin_inset LatexCommand index
8659 name "reduced (message)"
8669 , this is the lazily-applied reducer; it will be invoked automatically for
8670 arithmetic operations as necessary, but is useful when only the reduced
8674 \begin_layout Description
8677 \begin_inset LatexCommand index
8678 name "readFrom: (message)"
8692 with compatible contents and parses the first available data as the type
8694 If the return value is not the same as the argument type, an error is signalled
8695 (beyond any normal parsing errors).
8696 If the value is valid, it is returned; otherwise only
8703 \begin_layout Subsubsection
8707 \begin_layout Description
8710 \begin_inset LatexCommand index
8711 name "limits, numeric"
8716 \begin_inset LatexCommand index
8717 name "numeric limits"
8722 \begin_inset LatexCommand index
8723 name "PositiveInfinity (object)"
8729 is greater than any other
8736 \begin_layout Description
8739 \begin_inset LatexCommand index
8740 name "NegativeInfinity (object)"
8746 is lesser than any other
8753 \begin_layout Description
8756 \begin_inset LatexCommand index
8757 name "LargeUnbound (object)"
8767 designed to represent non-infinite, but non-bounded (
8768 \begin_inset Quotes eld
8771 as large as you like
8772 \begin_inset Quotes erd
8778 \begin_layout Description
8781 \begin_inset LatexCommand index
8782 name "PositiveEpsilon (object)"
8788 is as small as you like, but positive and greater than zero.
8791 \begin_layout Description
8794 \begin_inset LatexCommand index
8795 name "NegativeEpsilon (message)"
8801 is as small as you like, but negative and lesser than zero.
8804 \begin_layout Subsubsection
8808 \begin_layout Standard
8809 \begin_inset LatexCommand index
8815 \begin_inset LatexCommand index
8816 name "dimensioned units"
8821 \begin_inset LatexCommand index
8822 name "units, dimensioned"
8827 \begin_inset LatexCommand index
8833 \begin_inset LatexCommand index
8834 name "English units"
8839 \begin_inset LatexCommand index
8840 name "units, English"
8844 There is an entire system for handling dimensioned units and their various
8845 combinations and mathematical operations.
8846 There is included support for SI units, and common English units; furthermore,
8847 any object may conceivably be used as a base unit.
8850 src/lib/dimensioned.slate
8852 ' file for an overview.
8855 \begin_layout Subsection
8859 \begin_layout Standard
8860 \begin_inset LatexCommand index
8866 \begin_inset LatexCommand index
8867 name "Collection (object)"
8872 \begin_inset LatexCommand index
8873 name "Mapping (object)"
8878 \begin_inset LatexCommand index
8879 name "ExtensibleCollection (object)"
8884 \begin_inset LatexCommand index
8885 name "Sequence (object)"
8890 \begin_inset LatexCommand index
8891 name "LinkedCollection (object)"
8896 \begin_inset LatexCommand index
8902 \begin_inset LatexCommand index
8903 name "NoDuplicatesCollection (object)"
8908 \begin_inset LatexCommand index
8909 name "ExtensibleSequence (object)"
8914 \begin_inset LatexCommand index
8915 name "LinkedList (object)"
8920 \begin_inset LatexCommand index
8921 name "Tree (object)"
8926 \begin_inset LatexCommand index
8927 name "Graph (object)"
8932 \begin_inset LatexCommand index
8933 name "Tuple (object)"
8938 \begin_inset LatexCommand index
8939 name "Cord (object)"
8944 \begin_inset LatexCommand index
8950 \begin_inset LatexCommand index
8951 name "SortedSequence (object)"
8956 \begin_inset LatexCommand index
8957 name "Array (object)"
8962 \begin_inset LatexCommand index
8963 name "ByteArray (object)"
8968 \begin_inset LatexCommand index
8969 name "String (object)"
8974 \begin_inset LatexCommand index
8975 name "Range (object)"
8980 \begin_inset LatexCommand index
8981 name "Buffer (object)"
8986 \begin_inset LatexCommand index
8987 name "Dictionary (object)"
8992 \begin_inset LatexCommand index
8993 name "SortedSet (object)"
8998 \begin_inset LatexCommand index
8999 name "InsertionSequence (object)"
9003 Slate's collection hierarchy makes use of composing multiple behaviors (via
9004 inheritance) to provide a collection system that can be reasoned about
9005 with greater certainty, and that can be extended more easily than other
9006 object-oriented languages' collection types.
9007 Primarily Slate collections are mutable, which means that basic modifications
9008 occur destructively on the collection object.
9011 \begin_layout Standard
9013 \begin_inset LatexCommand ref
9014 reference "cap:Collections-delegation"
9018 shows the overview of the collection types, and how their inheritance is
9022 \begin_layout Standard
9023 \begin_inset Float figure
9029 \begin_layout Standard
9030 \begin_inset VSpace defskip
9036 \begin_layout Standard
9038 \begin_inset Graphics
9039 filename collection-web.eps
9046 \begin_layout Standard
9047 \begin_inset VSpace defskip
9053 \begin_layout Standard
9054 \begin_inset Caption
9056 \begin_layout Standard
9057 \begin_inset LatexCommand label
9058 name "cap:Collections-delegation"
9062 Core Collections Inheritance
9075 \begin_layout Standard
9076 All collections support a minimal set of methods, including support for
9077 basic internal iteration and testing.
9078 The following are representative core methods, and are by no means the
9079 limit of collection features:
9082 \begin_layout Paragraph
9083 \begin_inset LatexCommand index
9084 name "testing, collections"
9089 \begin_inset LatexCommand index
9090 name "collection testing"
9097 \begin_layout Description
9100 \begin_inset LatexCommand index
9101 name "isEmpty (message)"
9107 answers whether or not the collection has any elements in it.
9110 \begin_layout Description
9113 \begin_inset LatexCommand index
9114 name "includes: (message)"
9120 answers whether the collection contains the object.
9123 \begin_layout Paragraph
9124 \begin_inset LatexCommand index
9125 name "properties, collections"
9130 \begin_inset LatexCommand index
9131 name "collection properties"
9138 \begin_layout Description
9141 \begin_inset LatexCommand index
9142 name "size (message)"
9148 answers the number of elements in it.
9149 This is often calculated dynamically for extensible collections, so it's
9150 often useful to cache it in a calling method.
9153 \begin_layout Description
9156 \begin_inset LatexCommand index
9157 name "capacity (message)"
9163 answers the size that the collection's implementation is currently ready
9167 \begin_layout Paragraph
9168 \begin_inset LatexCommand index
9169 name "creation, collections"
9174 \begin_inset LatexCommand index
9175 name "collection creation"
9179 Making new collections
9182 \begin_layout Description
9185 \begin_inset LatexCommand index
9186 name "newSize: (message)"
9193 answers a new (empty) collection of the same type that is sized to the
9194 optional argument or a sensible default per type.
9197 \begin_layout Description
9200 \begin_inset LatexCommand index
9201 name "newSizeOf: (message)"
9207 answers a new collection of the same type that is sized to same size that
9211 \begin_layout Description
9214 \begin_inset LatexCommand index
9215 name "as:newWithAll: (message)"
9220 \begin_inset LatexCommand index
9221 name "newWithAll: (message)"
9238 has extensive support in the collection types to produce collections of
9239 the type of the second with the contents of the first collection (
9250 \begin_layout Paragraph
9251 \begin_inset LatexCommand index
9252 name "collection iteration"
9257 \begin_inset LatexCommand index
9258 name "iteration, collections"
9265 \begin_layout Description
9268 \begin_inset LatexCommand index
9269 name "do: (message)"
9274 \begin_inset LatexCommand index
9275 name "each: (message)"
9281 executes a block with
9285 (the idiomatic input slot for iterating) of the collection's elements in
9287 It answers the original collection.
9290 \begin_layout Description
9293 \begin_inset LatexCommand index
9294 name "collect: (message)"
9300 also takes a block, but answers a collection with all the results of those
9301 block-applications put into a new collection of the appropriate type.
9304 \begin_layout Description
9307 \begin_inset LatexCommand index
9308 name "select: (message)"
9314 takes a block that answers a
9318 and answers a new collection of the elements that the block filters (answers
9326 \begin_layout Description
9329 \begin_inset LatexCommand index
9330 name "reject: (message)"
9336 performs the logical opposite of
9340 , answering elements for which the block answers
9347 \begin_layout Description
9350 \begin_inset LatexCommand index
9351 name "inject:into: (message)"
9355 inject:\InsetSpace ~
9360 takes a two-argument accumulation block and applies it across the collection's
9362 The initial value given becomes the first argument, and is replaced through
9363 the iterations with the result of the block.
9366 \begin_layout Description
9369 \begin_inset LatexCommand index
9370 name "reduce: (message)"
9376 takes a two-argument block and performs the same action as
9380 only using one of the collection's elements as an initial value.
9383 \begin_layout Description
9384 \begin_inset LatexCommand index
9385 name "project: (message)"
9393 takes a block, answering a
9401 in general with each argument (member of the original collection) mapped
9402 to the result of applying the block to it.
9405 \begin_layout Subsubsection
9406 Extensible Collections
9409 \begin_layout Standard
9410 \begin_inset LatexCommand index
9411 name "extensible collections"
9416 \begin_inset LatexCommand index
9417 name "collections, extensible"
9422 \begin_inset LatexCommand index
9423 name "ExtensibleCollection (object)"
9427 Collections derived from
9429 ExtensibleCollection
9431 can be modified by adding or removing elements in various ways.
9432 The core protocol is:
9435 \begin_layout Description
9438 \begin_inset LatexCommand index
9439 name "add: (message)"
9445 inserts the given object into the collection.
9448 \begin_layout Description
9451 \begin_inset LatexCommand index
9452 name "remove: (message)"
9458 removes an object equal to the given one from the collection.
9461 \begin_layout Description
9464 \begin_inset LatexCommand index
9465 name "addAll: (message)"
9471 inserts all elements from the first collection contained in the second.
9474 \begin_layout Description
9477 \begin_inset LatexCommand index
9478 name "removeAll: (message)"
9484 removes all elements from the first collection contained in the second.
9487 \begin_layout Description
9490 \begin_inset LatexCommand index
9491 name "clear (message)"
9497 removes all the elements from the collection.
9500 \begin_layout Subsubsection
9502 \begin_inset LatexCommand label
9503 name "sub:Sequences"
9510 \begin_layout Standard
9513 \begin_inset LatexCommand index
9514 name "Sequence (object)"
9519 \begin_inset LatexCommand index
9520 name "Mapping (object)"
9530 from a range of natural numbers to some objects, sometimes restricted to
9532 Slate sequences are all addressed from a base of 0.
9535 \begin_layout Description
9538 \begin_inset LatexCommand index
9539 name "at: (message)"
9545 answers the element at the index given.
9548 \begin_layout Description
9551 \begin_inset LatexCommand index
9552 name "at:put: (message)"
9558 replaces the element at the index given with the object that is the last
9562 \begin_layout Description
9565 \begin_inset LatexCommand index
9566 name "doWithIndex: (message)"
9572 operates as do:, but applying the block with both the element as first
9573 argument and the index of the element in the Sequence as the second argument.
9576 \begin_layout Paragraph
9580 \begin_layout Standard
9583 \begin_inset LatexCommand index
9584 name "Array (object)"
9589 \begin_inset LatexCommand index
9590 name "WordArray (object)"
9595 \begin_inset LatexCommand index
9596 name "ByteArray (object)"
9601 \begin_inset LatexCommand index
9602 name "String (object)"
9608 are fixed-length sequences of any kind of object and are supported primitively.
9609 Various parameter types of
9613 are supported primitively, such as
9628 \begin_layout Paragraph
9632 \begin_layout Standard
9635 \begin_inset LatexCommand index
9636 name "Vector (object)"
9641 \begin_inset LatexCommand index
9642 name "Tuple (object)"
9647 \begin_inset LatexCommand index
9648 name "Point (object)"
9653 \begin_inset LatexCommand index
9659 \begin_inset LatexCommand index
9670 are fixed-length sequences constructed for geometrical purposes.
9680 The constructor message for these types is
9681 \begin_inset Quotes eld
9689 \begin_inset Quotes erd
9695 \begin_layout Paragraph
9696 Subsequences / Slices
9699 \begin_layout Standard
9702 \begin_inset LatexCommand index
9703 name "Subsequence (object)"
9709 allow one to treat a segment of a sequence as a separate sequence with
9710 its own addressing scheme; however, modifying the subsequence will cause
9711 the original to be modified.
9714 \begin_layout Paragraph
9718 \begin_layout Standard
9721 \begin_inset LatexCommand index
9722 name "Cord (object)"
9727 \begin_inset LatexCommand index
9733 \begin_inset LatexCommand index
9734 name "; (semicolon)"
9739 \begin_inset LatexCommand index
9746 are a non-copying representation of a concatenation of
9751 Normal concatenation of Sequences is performed with the
9755 method, and results in copying both of the arguments into a new
9759 of the appropriate type; the
9763 method will construct a
9768 They efficiently implement accessing via
9783 \begin_inset Quotes eld
9787 \begin_inset Quotes erd
9801 \begin_layout Paragraph
9802 Extensible and Sorted Sequences
9805 \begin_layout Standard
9806 \begin_inset LatexCommand index
9807 name "ExtensibleSequence (object)"
9819 with some special methods to treat both ends as queues.
9820 It provides the following additional protocol:
9823 \begin_layout Description
9826 \begin_inset LatexCommand index
9827 name "addFirst: (message)"
9833 inserts the given object at the beginning of the sequence.
9836 \begin_layout Description
9839 \begin_inset LatexCommand index
9840 name "addLast: (message)"
9846 inserts the given object at the end of the sequence.
9849 \begin_layout Description
9852 \begin_inset LatexCommand index
9853 name "add: (message)"
9859 inserts the given object at the end of the sequence (it's addLast:).
9862 \begin_layout Description
9865 \begin_inset LatexCommand index
9866 name "first: (message)"
9872 answers a sequence of the first N elements.
9875 \begin_layout Description
9878 \begin_inset LatexCommand index
9879 name "last: (message)"
9885 answers a sequence of the final N elements.
9888 \begin_layout Description
9891 \begin_inset LatexCommand index
9892 name "removeFirst (message)"
9898 removes the first element from the sequence.
9901 \begin_layout Description
9904 \begin_inset LatexCommand index
9905 name "removeLast (message)"
9911 removes the final element from the sequence.
9914 \begin_layout Standard
9915 \begin_inset LatexCommand index
9916 name "SortedSequence (object)"
9921 \begin_inset LatexCommand index
9922 name "remove: (message)"
9927 \begin_inset LatexCommand index
9928 name "Heap (object)"
9936 behaves similarly except that it will arrange for its members to remain
9937 sorted according to a block closure that compares two individual elements;
9938 as a result, it should not be manipulated except via
9946 since it maintains its own ordering.
9955 designed for collecting elements in arbitrary order, and removing the first
9959 \begin_layout Paragraph
9963 \begin_layout Standard
9964 \begin_inset LatexCommand index
9965 name "Stack (object)"
9970 \begin_inset LatexCommand index
9971 name "push: (message)"
9976 \begin_inset LatexCommand index
9977 name "pop (message)"
9982 \begin_inset LatexCommand index
9983 name "top (message)"
9995 augmented with methods to honor the stack abstraction:
10010 \begin_layout Paragraph
10014 \begin_layout Standard
10015 \begin_inset LatexCommand index
10016 name "Range (object)"
10032 s between two values, that is ordered consecutively and has some stepping
10033 value; they include the
10041 value unless the stepping doesn't lead to the
10045 value exactly, in which case the last value is the greatest value in the
10046 sequence that is still before the end marker value.
10047 Creating ranges is identical to the numeric iteration protocol in
10048 \begin_inset LatexCommand ref
10049 reference "sub:Looping"
10053 , without the final
10057 keyword, and sending the
10065 performs the identical function.
10068 \begin_layout Paragraph
10072 \begin_layout Standard
10073 \begin_inset LatexCommand index
10074 name "Buffer (object)"
10079 \begin_inset LatexCommand index
10080 name "RingBuffer (object)"
10085 \begin_inset LatexCommand index
10086 name "ReadBufferStream (object)"
10091 \begin_inset LatexCommand index
10092 name "WriteBufferStream (object)"
10104 that takes extra care to only use one underlying array object, and also
10105 stores its elements in a
10106 \begin_inset Quotes eld
10110 \begin_inset Quotes erd
10113 fashion, to make for an efficient queue for Streams (see
10122 \begin_inset LatexCommand vref
10123 reference "des:ReadBufferStream"
10128 One consequence of this is that a
10132 has a limited upper bound in size which the client must handle, although
10133 the capacity can be grown explicitly.
10136 \begin_layout Subsubsection
10137 Strings and Characters
10140 \begin_layout Standard
10143 \begin_inset LatexCommand index
10144 name "String (object)"
10150 in Slate are non-extensible, mutable
10162 s can easily be made for them via, say,
10175 s have a special literal syntax, and methods specific to dealing with text;
10176 most of the useful generic methods for strings are lifted to the
10181 Strings provide the following specific protocol:
10184 \begin_layout Description
10185 \begin_inset LatexCommand index
10186 name "lexicographicallyCompare: (message)"
10192 lexicographicallyCompare:
10194 performs an in-order comparison of the codes of the constituent
10202 arguments, returning the sign of comparison,
10206 if the first argument is greater,
10217 \begin_layout Description
10220 \begin_inset LatexCommand index
10221 name "capitalize (message)"
10227 uppercases in-place the first
10238 \begin_layout Description
10241 \begin_inset LatexCommand index
10242 name "toUppercase (message)"
10248 uppercases in-place all
10259 \begin_layout Description
10262 \begin_inset LatexCommand index
10263 name "toLowerCase (message)"
10269 lowercases in-place all
10280 \begin_layout Description
10283 \begin_inset LatexCommand index
10284 name "toSwapCase (message)"
10290 toggles in-place the case of all
10301 \begin_layout Description
10304 \begin_inset LatexCommand index
10305 name "toCamelCase (message)"
10309 toCamelCase\InsetSpace ~
10316 up according to the given separators (defaulting to whitespace), joining
10321 'd versions of each element.
10324 \begin_layout Description
10327 \begin_inset LatexCommand index
10328 name "fromCamelCase (message)"
10332 fromCamelCase\InsetSpace ~
10339 up according to capitalization transition boundaries and joins the elements
10340 together with the given separator.
10343 \begin_layout Description
10346 \begin_inset LatexCommand index
10347 name "escaped (message)"
10357 based on adding slash-escapes for literal printing so it can be read in
10361 \begin_layout Description
10364 \begin_inset LatexCommand index
10365 name "unescaped (message)"
10375 based on removing slash-escapes, the same way that parsing is done.
10378 \begin_layout Description
10381 \begin_inset LatexCommand index
10382 name "readFrom: (message)"
10396 with compatible contents and parses the first available data as a
10400 with the relevant escape interpretation.
10403 \begin_layout Description
10404 \begin_inset LatexCommand index
10405 name "plural (message)"
10413 uses English rules to answer a new regular plural form of the argument
10421 \begin_layout Description
10422 \begin_inset LatexCommand index
10423 name "asAn (message)"
10431 uses English rules to answer a new String with
10444 \begin_layout Subsubsection
10445 Collections without Duplicates
10448 \begin_layout Standard
10451 \begin_inset LatexCommand index
10452 name "NoDuplicationCollection (object)"
10457 \begin_inset LatexCommand index
10458 name "include: (message)"
10462 NoDuplicatesCollection
10464 forms a special protocol that allows for extension in a well-mannered way.
10469 protocol for extension, these collections provide
10473 , which ensures that at least one element of the collection is the target
10474 object, but doesn't do anything otherwise.
10479 will never add an object if it is already present.
10480 These collection types still respond to
10484 and its variants, but they will behave in terms of the
10491 \begin_layout Standard
10492 \begin_inset LatexCommand index
10493 name "Set (object)"
10497 The default implementation of this protocol is
10501 , which stores its elements in a (somewhat sparse) hashed array.
10504 \begin_layout Subsubsection
10505 Mappings and Dictionaries
10508 \begin_layout Standard
10511 \begin_inset LatexCommand index
10512 name "Mapping (object)"
10517 \begin_inset LatexCommand index
10518 name "Association (object)"
10523 \begin_inset LatexCommand index
10524 name "keysDo: (message)"
10529 \begin_inset LatexCommand index
10530 name "valuesDo: (message)"
10535 \begin_inset LatexCommand index
10536 name "keysAndValuedDo: (message)"
10541 \begin_inset LatexCommand index
10542 name "Dictionary (object)"
10548 s provide a general protocol for associating the elements of a set of keys
10549 each to a value object.
10562 s, but they are generally used with
10569 \begin_layout Standard
10574 defines the general protocol
10586 s use, which also happen to be Mappings.
10587 Mappings also support iteration protocols such as
10602 \begin_layout Subsubsection
10606 \begin_layout Standard
10607 \begin_inset LatexCommand index
10608 name "LinkedCollection (object)"
10616 provides a type of collection where the elements themselves are central
10617 to defining what is in the collection and what is not.
10620 \begin_layout Paragraph
10624 \begin_layout Standard
10625 \begin_inset LatexCommand index
10626 name "LinkedList (object)"
10631 \begin_inset LatexCommand index
10632 name "Link (object)"
10640 type, comprised of individual
10644 s with forward and backward directional access, is provided as a flexible
10645 but basic data structure.
10646 This type does require that its elements follow the
10650 protocol, however, so it does require some advanced preparation to use
10654 \begin_layout Paragraph
10658 \begin_layout Standard
10659 \begin_inset LatexCommand index
10665 \begin_inset LatexCommand index
10666 name "trees, binary"
10671 \begin_inset LatexCommand index
10672 name "binary trees"
10677 \begin_inset LatexCommand index
10678 name "trees, red-black"
10683 \begin_inset LatexCommand index
10684 name "red-black trees"
10689 \begin_inset LatexCommand index
10690 name "trees with ordered elements"
10695 \begin_inset LatexCommand index
10696 name "ordered elements, trees"
10701 \begin_inset LatexCommand index
10706 Slate includes libraries for binary trees, red-black trees, trees with ordered
10707 elements, and tries.
10710 \begin_layout Paragraph
10714 \begin_layout Standard
10715 \begin_inset LatexCommand index
10721 \begin_inset LatexCommand index
10722 name "Digraph (object)"
10727 \begin_inset LatexCommand index
10728 name "Node (object)"
10733 \begin_inset LatexCommand index
10734 name "Edge (object)"
10739 \begin_inset LatexCommand index
10740 name "KeyedDigraph (object)"
10744 A directed graph, or
10748 (directed graph) type, is provided with associated
10761 provides the same behavior with a keyed access, similar to that in a
10765 , although there is an allowance for various kinds of non-determinism, which
10766 makes this useful for creating Non-deterministic Finite Automata.
10769 \begin_layout Subsubsection
10770 Vectors and Matrices
10773 \begin_layout Standard
10774 \begin_inset LatexCommand index
10780 \begin_inset LatexCommand index
10785 Slate includes the beginnings of a mathematical vector and matrix library.
10788 src/lib/matrix.slate
10790 ' file for an overview.
10793 \begin_layout Subsection
10794 Streams and Iterators
10797 \begin_layout Standard
10798 \begin_inset LatexCommand index
10804 \begin_inset LatexCommand index
10809 Streams are objects that act as a sequential channel of elements from (or
10817 \begin_layout Subsubsection
10821 \begin_layout Standard
10822 Streams respond to a number of common messages.
10823 However, many of these only work on some of the stream types, usually according
10827 \begin_layout Description
10830 \begin_inset LatexCommand index
10831 name "next (message)"
10838 reads and answers the next element in the stream.
10839 This causes the stream reader to advance one element.
10840 If no further elements are available to return, then the block supplied
10845 is invoked (with no arguments), or if the optional argument was not supplied,
10850 condition is signalled.
10853 \begin_layout Description
10856 \begin_inset LatexCommand index
10857 name "peek (message)"
10864 reads and answers the next element in the stream.
10869 advance the stream reader.
10870 If no further elements are available to return, the
10874 argument is processed as for
10881 \begin_layout Description
10884 \begin_inset LatexCommand index
10885 name "next: (message)"
10895 number of elements from the stream and delivers them in a
10899 of the appropriate type.
10900 If fewer than n elements are available before the end of stream (when
10904 would have signalled
10912 than asked for, possibly even empty, is returned.
10915 \begin_layout Description
10918 \begin_inset LatexCommand index
10919 name "next:putInto: (message)"
10925 reads the next N elements into the given
10929 starting from index 0.
10930 Returns the number of elements actually read and inserted.
10935 , the returned number may be smaller than actually asked for.
10938 \begin_layout Description
10941 \begin_inset LatexCommand index
10942 name "next:putInto:startingAt: (message)"
10946 next:putInto:startingAt:
10948 reads the N elements into the given
10952 starting from the given index.
10953 Returns the number of elements read and inserted, exactly as for
10960 \begin_layout Description
10963 \begin_inset LatexCommand index
10964 name "nextPutInto: (message)"
10970 reads into the given
10974 the number of elements which will fit into it.
10975 Returns a result exactly as for
10982 \begin_layout Description
10985 \begin_inset LatexCommand index
10986 name "nextPut: (message)"
10990 nextPut:\InsetSpace ~
10993 writes the object to the stream.
10994 If the stream is full, and will not accept the object, the
10998 optional argument is processed as for
11005 \begin_layout Description
11008 \begin_inset LatexCommand index
11009 name "nextPutAll: (message)"
11014 \begin_inset LatexCommand index
11015 name "; (semicolon)"
11028 stream\InsetSpace ~
11033 writes all the objects in the
11042 selector allows the user to cascade several sequences into the stream as
11043 though they were concatenated.
11044 If the stream fills up (signalling
11048 ) during the write, a
11052 condition containing the number of successfully written elements is signalled.
11055 \begin_layout Description
11058 \begin_inset LatexCommand index
11059 name "do: (message)"
11065 applies a block to each element of the stream.
11068 \begin_layout Description
11071 \begin_inset LatexCommand index
11072 name "flush (message)"
11078 synchronizes the total state of the stream with any pending requests made
11082 \begin_layout Description
11085 \begin_inset LatexCommand index
11086 name "isAtEnd (message)"
11092 answers whether or not the stream has reached some input limit: returns
11093 true if next or peek would signal Exhaustion at the time
11097 was called; returns false otherwise (modulo signalled Conditions).
11098 Note that, for some streams (notably sockets), even though
11102 has returned false,
11110 may still signal Exhaustion because the underlying input-source has changed
11111 its state asynchronously.
11116 optional argument to
11124 for reliable notifications in these cases.
11128 \begin_layout Description
11129 \begin_inset LatexCommand index
11130 name "hasAnEnd (message)"
11138 answers whether the stream has a definable or possible end-point.
11139 All stream types support this protocol and will often recurses on their
11140 components to find the answer.
11143 \begin_layout Description
11144 \begin_inset LatexCommand index
11145 name "isWritable (message)"
11153 answers whether the stream is prepared to accept further objects via
11170 was called; returns true otherwise (modulo signalled
11182 \begin_layout Description
11185 \begin_inset LatexCommand index
11186 name "upToEnd (message)"
11192 collects all the elements of the stream up to its limit into an
11194 Extensible\SpecialChar \-
11197 , and returns the sequence.
11200 \begin_layout Description
11203 \begin_inset LatexCommand index
11204 name "contents (message)"
11210 answers a collection of the output of the argument
11217 \begin_layout Subsubsection
11218 Basic Stream Variants
11221 \begin_layout Standard
11222 \begin_inset LatexCommand index
11223 name "Stream (object)"
11228 \begin_inset LatexCommand index
11229 name "PositionableStream (object)"
11234 \begin_inset LatexCommand index
11235 name "FilterStream (object)"
11240 \begin_inset LatexCommand index
11241 name "CollectStream (object)"
11246 \begin_inset LatexCommand index
11247 name "ReadStream (object)"
11252 \begin_inset LatexCommand index
11253 name "WriteStream (object)"
11258 \begin_inset LatexCommand index
11259 name "BufferStream (object)"
11264 \begin_inset LatexCommand index
11265 name "FileStream (object)"
11270 \begin_inset LatexCommand index
11271 name "Socket (object)"
11276 \begin_inset LatexCommand index
11277 name "Pipe (object)"
11282 \begin_inset LatexCommand index
11283 name "Console (object)"
11288 \begin_inset LatexCommand index
11289 name "DummyStream (object)"
11294 \begin_inset LatexCommand index
11295 name "BlockStream (object)"
11300 \begin_inset LatexCommand index
11301 name "ReadWriteStream (object)"
11306 \begin_inset LatexCommand index
11307 name "EchoStream (object)"
11312 \begin_inset LatexCommand index
11313 name "LineNumberedStream (object)"
11318 \begin_inset LatexCommand ref
11319 reference "cap:Stream-Inheritance"
11323 shows the major stream types and their relationships.
11326 \begin_layout Standard
11327 \begin_inset Float figure
11332 \begin_layout Standard
11333 \begin_inset VSpace defskip
11339 \begin_layout Standard
11341 \begin_inset Graphics
11342 filename stream-web.eps
11349 \begin_layout Standard
11350 \begin_inset VSpace defskip
11356 \begin_layout Standard
11357 \begin_inset Caption
11359 \begin_layout Standard
11360 \begin_inset LatexCommand label
11361 name "cap:Stream-Inheritance"
11378 \begin_layout Description
11383 provides the basic protocol for instantiating streams.
11386 \begin_layout Description
11391 provides the basic protocol for input access from a source.
11394 \begin_layout Description
11399 provides the basic protocol for output access to a target.
11402 \begin_layout Description
11407 provides the basic protocol for both read and write access, and caches
11408 its input as necessary.
11411 \begin_layout Description
11414 \begin_inset LatexCommand index
11415 name "PeekableStream (object)"
11425 to provide the ability to look forward on the stream without advancing
11429 \begin_layout Description
11432 \begin_inset LatexCommand index
11433 name "ReadPositionableStream (object)"
11438 \begin_inset LatexCommand index
11439 name "WritePositionableStream (object)"
11444 \begin_inset LatexCommand index
11445 name "ReadWritePositionableStream (object)"
11455 to provide a basic protocol to iterate over a sequence of elements from
11460 or a file or other source.
11461 These streams store their position in the sequence as they iterate, and
11462 are re-positionable.
11463 It also has its own variants, -
11478 \begin_layout Description
11481 \begin_inset LatexCommand index
11482 name "reader (message)"
11487 \begin_inset LatexCommand index
11488 name "writer (message)"
11493 \begin_inset LatexCommand index
11494 name "iterator (message)"
11508 repeatedly (and does nothing on writing).
11509 It is best created by applying the
11528 \begin_layout Description
11531 \begin_inset LatexCommand index
11532 name "echo (message)"
11537 \begin_inset LatexCommand index
11538 name "echoTo: (message)"
11548 which copies all stream input/output interactions to another
11552 for logging purposes.
11553 It is best created by applying the
11563 echoTo:\InsetSpace ~
11566 methods to any stream.
11567 It answers the original stream, so that further processing can be chained.
11570 \begin_layout Description
11573 \begin_inset LatexCommand index
11574 name "Method ReadStream (object)"
11578 Method\InsetSpace ~
11585 that targets a no-input block and returns its output each time.
11586 It is best created by applying the
11594 method to any block.
11597 \begin_layout Description
11600 \begin_inset LatexCommand index
11601 name "Method WriteStream (object)"
11605 Method\InsetSpace ~
11612 that targets a single-input block and applies its input each time.
11613 It is best created by applying the
11617 method to any block.
11620 \begin_layout Description
11623 \begin_inset LatexCommand index
11624 name "StreamProcessor (object)"
11630 is an abstract kind of
11638 which it processes in some way.
11639 Derivatives specialize it in various useful ways.
11642 \begin_layout Description
11645 \begin_inset LatexCommand index
11646 name "select: (message)"
11651 \begin_inset LatexCommand index
11652 name "reject: (message)"
11662 that returns the elements of a wrapped
11666 that satisfy the logical test of a single-argument block being applied
11668 It is created by applying the
11683 \begin_layout Description
11686 \begin_inset LatexCommand index
11687 name "collect: (message)"
11697 that returns the results of applying a single-argument block to each element
11703 It is created by applying the
11714 \begin_layout Description
11715 \begin_inset LatexCommand index
11716 name "inject:into: (message)"
11728 that returns the results of successively applying a two-argument block
11729 to an initial seed and each stream element.
11730 The result of the block is used as seed for the next block application.
11731 It is created by applying the
11742 \begin_layout Description
11745 \begin_inset LatexCommand index
11746 name "splitWith: (message)"
11756 that returns the sequences of elements between a given set of separators.
11757 It is created by applying the
11761 (using whitespace separators) or
11772 \begin_layout Description
11773 \begin_inset LatexCommand index
11774 name "generate:until: (message)"
11786 that returns the results of successively applying a single-argument block
11787 to an initial seed.
11788 The result of the block is used as seed for the next block.
11793 creates such a stream with a termination block which takes each element
11794 as the argument to determine where the stream should end.
11797 \begin_layout Description
11800 \begin_inset LatexCommand index
11801 name "readBuffered (message)"
11808 \begin_inset LatexCommand label
11809 name "des:ReadBufferStream"
11813 wraps another stream with a special
11817 object for reading large chunks from the stream at a time while handing
11818 out the elements as requested.
11819 This also minimizes stress on the memory-allocator by avoiding unnecessary
11820 allocation of arrays.
11821 It is created by applying the
11832 \begin_layout Description
11835 \begin_inset LatexCommand index
11836 name "writeBuffered (message)"
11843 \begin_inset LatexCommand label
11844 name "des:WriteBufferStream"
11848 wraps another stream with a special
11852 object for writing large chunks to the stream at a time while accepting
11853 new elements as requested.
11854 This also minimizes stress on the memory-allocator by avoiding unnecessary
11855 allocation of arrays.
11856 It is created by applying the
11867 \begin_layout Subsubsection
11868 Basic Instantiation
11871 \begin_layout Standard
11872 \begin_inset LatexCommand index
11873 name "creation, streams"
11878 \begin_inset LatexCommand index
11879 name "stream creation"
11883 There are a number of ways to create
11887 s, and a large number of implementations, so some methods exist to simplify
11888 the process of making a new one:
11891 \begin_layout Description
11894 \begin_inset LatexCommand index
11895 name "newOn: (message)"
11905 of the same type as the first argument, targeting it to the second as a
11907 This should not be overridden.
11908 Instead, the re-targeting method
11915 \begin_layout Description
11918 \begin_inset LatexCommand index
11919 name "newTo: (message)"
11929 of the appropriate type on the specified target.
11930 This should be overridden for derived types, and the first argument should
11931 apply to the generic
11935 type to allow any instance to know this protocol.
11938 \begin_layout Description
11941 \begin_inset LatexCommand index
11942 name "newFrom: (message)"
11952 of the appropriate type on the specified target.
11953 This should be overridden for derived types, and the first argument should
11954 apply to the generic
11958 type to allow any instance to know this protocol.
11961 \begin_layout Description
11964 \begin_inset LatexCommand index
11965 name "buffered (message)"
11971 creates and returns a new
11975 whose type corresponds to the argument and wraps the argument
11982 \begin_layout Description
11985 \begin_inset LatexCommand index
11986 name "readBuffered (message)"
11992 creates and returns a new
11996 which wraps the argument
12003 \begin_layout Description
12006 \begin_inset LatexCommand index
12007 name "writeBuffered (message)"
12013 creates and returns a new
12017 which wraps the argument
12024 \begin_layout Description
12027 \begin_inset LatexCommand index
12028 name "echoTo: (message)"
12034 creates and returns a new
12038 which wraps the first argument
12042 and echoes to the second.
12045 \begin_layout Description
12048 \begin_inset LatexCommand index
12049 name "echo (message)"
12055 creates and returns a new
12066 \begin_layout Description
12069 \begin_inset LatexCommand index
12070 name ">> (message)"
12076 performs a looping iterative transfer of all elements of the first stream
12078 The second argument may be any
12086 , or a single-argument
12090 in which case it has the same semantics as
12099 s, it will perform a buffered transfer.
12100 This method always returns the target stream so that the results may be
12104 \begin_layout Subsubsection
12105 Collecting Protocols
12108 \begin_layout Standard
12109 Mirroring the collection protocols, streams support a mirror of that interface
12131 The difference is that where collections would answer other collections,
12132 streams return corresponding streams.
12135 \begin_layout Subsubsection
12136 \begin_inset LatexCommand label
12137 name "sub:Iterator-Streams"
12144 \begin_layout Standard
12145 \begin_inset LatexCommand index
12146 name "iterator streams"
12151 \begin_inset LatexCommand index
12152 name "streams, iterator"
12157 \begin_inset LatexCommand index
12158 name "Set ReadStream (object)"
12162 Many types (typically collections) define their own
12166 type which goes over its elements in series, even if the collection is
12167 not ordered, and only visits each element once.
12168 This type's prototype is accessed via the slot
12172 within each collection (located on its traits object).
12174 \begin_inset Quotes eld
12183 \begin_inset Quotes erd
12186 refers to the prototype suitable for iterating over
12193 \begin_layout Standard
12194 \begin_inset LatexCommand index
12195 name "iterator (message)"
12199 In order to create a new iterator for a specific collection, the
12203 message is provided, which clones the prototype for that collection's type
12204 and targets it to the receiver of the message.
12205 The protocol summary:
12208 \begin_layout Description
12221 if one is available for the type, targetted to the argument of the message.
12224 \begin_layout Description
12227 \begin_inset LatexCommand index
12228 name "reader (message)"
12233 \begin_inset LatexCommand index
12234 name "writer (message)"
12246 get streams with only
12254 capabilities for the type, when available, targetted to the argument of
12258 \begin_layout Standard
12259 The stream capabilities supported for each basic collection type are usually
12260 limited by the behavior that the type supports.
12261 The capabilities per basic type are as follows; types not mentioned inherit
12262 or specialize the capabilities of their ancestors:
12265 \begin_layout Standard
12267 \begin_inset Tabular
12268 <lyxtabular version="3" rows="6" columns="2">
12270 <column alignment="center" valignment="top" leftline="true" width="0sp">
12271 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0sp">
12272 <row topline="true" bottomline="true">
12273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12276 \begin_layout Standard
12282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12285 \begin_layout Standard
12292 <row topline="true">
12293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12296 \begin_layout Standard
12302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12305 \begin_layout Standard
12312 <row topline="true">
12313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12316 \begin_layout Standard
12317 ExtensibleCollection
12322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12325 \begin_layout Standard
12332 <row topline="true">
12333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12336 \begin_layout Standard
12342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12345 \begin_layout Standard
12346 Read and Write separately
12352 <row topline="true">
12353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12356 \begin_layout Standard
12362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12365 \begin_layout Standard
12366 Positionables (R, W, RW); copy for extension
12372 <row topline="true" bottomline="true">
12373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12376 \begin_layout Standard
12382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12385 \begin_layout Standard
12386 Positionables (R, W, RW)
12399 \begin_layout Subsection
12401 \begin_inset LatexCommand label
12402 name "sub:External-Resources"
12409 \begin_layout Standard
12410 \begin_inset LatexCommand index
12411 name "external resources"
12416 \begin_inset LatexCommand index
12417 name "resources, external"
12421 Slate includes an extensible framework for streams that deal with external
12422 resources, such as files or network connections or other programs.
12423 This generally relies on having a representative object in the image which
12424 tracks the underlying primitive identity of the resource, and also provides
12425 methods for iterator-style streams over what is available through the resources.
12426 Many of these resources aren't sequences as files are sequences of bytes,
12427 so they're asynchronous and behave differently from ordinary streams.
12430 \begin_layout Paragraph
12434 \begin_layout Description
12437 \begin_inset LatexCommand index
12438 name "ExternalResource (object)"
12444 provides the basic behavior for external resource types.
12447 \begin_layout Description
12450 \begin_inset LatexCommand index
12451 name "ExternalResource Locator (object)"
12455 ExternalResource\InsetSpace ~
12458 provides a core attribute type for structured descriptors of external resources
12459 , as a generalization of file pathnames, port descriptions, URLs, or even
12463 \begin_layout Description
12466 \begin_inset LatexCommand index
12467 name "ExternalResource Stream (object)"
12471 ExternalResource\InsetSpace ~
12474 provides an extension of the iterator interface (described on
12475 \begin_inset LatexCommand vref
12476 reference "sub:Iterator-Streams"
12485 All of them provide
12497 variants as appropriate.
12500 \begin_layout Paragraph
12504 \begin_layout Standard
12505 Extending the framework to cover new primitive or otherwise connection types
12506 is fairly simple, since the following methods are the only input/output
12507 primitives needed for defining an external resource type:
12510 \begin_layout Description
12513 \begin_inset LatexCommand index
12514 name "read:from:startingAt:into: (message)"
12518 resource\InsetSpace ~
12522 handle\InsetSpace ~
12523 startingAt:\InsetSpace ~
12528 reads the next n elements from the resource identified by the given low-level
12529 handle, from the given starting point.
12530 The contents are placed in the given array, which should be a
12537 \begin_layout Description
12540 \begin_inset LatexCommand index
12541 name "write:to:startingAt:from: (message)"
12545 resource\InsetSpace ~
12546 write:\InsetSpace ~
12549 handle\InsetSpace ~
12550 startingAt:\InsetSpace ~
12555 writes the next n elements to the resource identified by the given low-level
12556 handle, from the given starting point.
12557 The contents are read from the given array, which should be a
12564 \begin_layout Paragraph
12568 \begin_layout Description
12571 \begin_inset LatexCommand index
12572 name "open (message)"
12578 Opens the resource for usage within the system.
12581 \begin_layout Description
12584 \begin_inset LatexCommand index
12585 name "close (message)"
12591 Closes the resource, releasing related administrative data; this happens
12592 automatically during garbage collection, but it is poor practice to rely
12596 \begin_layout Description
12599 \begin_inset LatexCommand index
12600 name "enable (message)"
12606 Creates the external resource represented (used by
12613 \begin_layout Description
12616 \begin_inset LatexCommand index
12617 name "isOpen (message)"
12623 answers whether the resource is open or closed.
12626 \begin_layout Description
12629 \begin_inset LatexCommand index
12630 name "isActive (message)"
12636 answers whether the resource is active.
12639 \begin_layout Description
12642 \begin_inset LatexCommand index
12643 name "restart (message)"
12649 restarts the resource if it's already active.
12652 \begin_layout Description
12655 \begin_inset LatexCommand index
12656 name "flush (message)"
12662 flushes any unwritten elements.
12665 \begin_layout Description
12668 \begin_inset LatexCommand index
12669 name "commit (message)"
12675 commits all pending write-out information to the resource.
12676 Commit performs a flush but also ensures that the data is actually sent
12680 \begin_layout Description
12683 \begin_inset LatexCommand index
12684 name "read:startingAt:into: (mesage)"
12688 read:startingAt:into:
12692 read:from:startingAt:into:
12694 with the resource's handle.
12697 \begin_layout Description
12700 \begin_inset LatexCommand index
12701 name "write:startingAt:into: (message)"
12705 write:startingAt:from:
12709 write:to:startingAt:from:
12711 with the resource's handle.
12714 \begin_layout Description
12717 \begin_inset LatexCommand index
12718 name "interactor (message)"
12728 for accessing the resource.
12729 Unlike the stream that
12737 is expected to return a coupled pair of a
12745 over the same resource, synchronized to preserve the resource's behavior.
12748 \begin_layout Description
12751 \begin_inset LatexCommand index
12752 name "bufferSize (message)"
12758 answers a sensible buffer size for interaction, possibly dynamically determined.
12761 \begin_layout Description
12764 \begin_inset LatexCommand index
12765 name "defaultBufferSize (message)"
12771 answers a default sensible buffer size for interaction.
12774 \begin_layout Description
12777 \begin_inset LatexCommand index
12778 name "locator (message)"
12784 answers a suitable structured object for dealing with that resource's identity/
12788 \begin_layout Description
12791 \begin_inset LatexCommand index
12792 name "sessionDo: (message)"
12798 executes a code block with the resource as its argument, opening and closing
12799 the resource transparently to the block, even for abnormal terminations.
12800 If the resource is already open, then this takes no opening or closing
12801 actions, so that calls may be nested blindly.
12804 \begin_layout Subsubsection
12808 \begin_layout Standard
12809 \begin_inset LatexCommand index
12810 name "Console (object)"
12815 \begin_inset LatexCommand index
12816 name "ConsoleInput (object)"
12821 \begin_inset LatexCommand index
12822 name "ConsoleOutput (object)"
12826 The Slate interpreter provides two console
12846 by default, capturing keyboard input and writing out to the console, respective
12848 These are also accessible as
12850 Console\InsetSpace ~
12855 Console\InsetSpace ~
12861 Console\InsetSpace ~
12864 delegates to these, acting as a
12871 \begin_layout Subsubsection
12875 \begin_layout Standard
12876 \begin_inset LatexCommand index
12882 \begin_inset LatexCommand index
12883 name "File (object)"
12887 Files are persistent external sequences of bytes.
12888 The interpreter provides an object type
12892 which provides the corresponding protocol extensions to
12899 \begin_layout Description
12902 \begin_inset LatexCommand index
12903 name "newNamed:\\&mode: (message)"
12913 with the given name as its locator and also a mode option.
12914 No attempt to open the file is automatically made.
12917 \begin_layout Description
12920 \begin_inset LatexCommand index
12921 name "sessionDo:\\&mode: (message)"
12931 with a simple temporary mode option (which is reset on return).
12934 \begin_layout Description
12937 \begin_inset LatexCommand index
12938 name "withOpenNamed:Do:\\&mode: (message)"
12942 withOpenNamed:do:&mode:
12948 with the ability to create a new
12952 dynamically for the session along with a specified mode.
12955 \begin_layout Description
12958 \begin_inset LatexCommand index
12959 name "position (message)"
12965 returns the position within the
12972 \begin_layout Description
12975 \begin_inset LatexCommand index
12976 name "position: (message)"
12982 sets the position within the
12986 to the given integer number of bytes.
12989 \begin_layout Description
12992 \begin_inset LatexCommand index
12993 name "size (message)"
13006 \begin_layout Description
13009 \begin_inset LatexCommand index
13010 name "name (message)"
13023 \begin_layout Description
13026 \begin_inset LatexCommand index
13027 name "fullName (message)"
13033 will always return a complete pathname whereas the regular method may not.
13036 \begin_layout Description
13039 \begin_inset LatexCommand index
13040 name "renamedTo: (message)"
13046 adjusts the file to have the given name.
13049 \begin_layout Description
13052 \begin_inset LatexCommand index
13053 name "atEnd (message)"
13059 answers whether the file's end has been reached.
13062 \begin_layout Description
13065 \begin_inset LatexCommand index
13066 name "create (message)"
13072 makes a file with the given name, with empty contents.
13075 \begin_layout Description
13078 \begin_inset LatexCommand index
13079 name "exists (message)"
13085 answers whether there is a file with the object's pathname.
13088 \begin_layout Description
13091 \begin_inset LatexCommand index
13092 name "delete (message)"
13101 \begin_layout Standard
13102 \begin_inset LatexCommand index
13103 name "load: (message)"
13107 Perhaps the most important utility is to load libraries based on path names.
13112 will execute a file with the given path name as Slate source.
13115 \begin_layout Standard
13116 \begin_inset LatexCommand index
13117 name "File Read (object)"
13122 \begin_inset LatexCommand index
13123 name "File Write (object)"
13128 \begin_inset LatexCommand index
13129 name "File ReadWrite (object)"
13134 \begin_inset LatexCommand index
13135 name "File CreateWrite (object)"
13139 File mode objects specify the interaction capabilities requested of the
13140 underlying system for the handle.
13141 The modes consist of
13164 \begin_layout Subsubsection
13165 Shells and Pipes (Not Currently Implemented)
13166 \begin_inset OptArg
13169 \begin_layout Standard
13178 \begin_layout Standard
13179 \begin_inset LatexCommand index
13180 name "Shell (object)"
13185 \begin_inset LatexCommand index
13186 name "Environment (object)"
13198 globals are provided to access the underlying operating system's command
13199 shell functionality from within the Slate environment.
13204 provides a dispatch hook for shell-related methods, while
13212 of the current shell context's defined variables and values.
13213 They support several primitive methods as follows:
13216 \begin_layout Description
13219 \begin_inset LatexCommand index
13220 name "enter (message)"
13227 enters the host operating system's command-line shell.
13228 This has no effect on the Slate environment directly except for suspending
13232 \begin_layout Description
13235 \begin_inset LatexCommand index
13236 name "runProgram:withArgs: (message)"
13241 runProgram:\InsetSpace ~
13242 programName\InsetSpace ~
13243 withArgs:\InsetSpace ~
13246 executes the program with the given name and passes it the arguments which
13254 \begin_layout Description
13257 \begin_inset LatexCommand index
13258 name "execute: (message)"
13263 execute:\InsetSpace ~
13266 passes the contents of the file named along to the shell, returning its
13270 \begin_layout Description
13273 \begin_inset LatexCommand index
13274 name "at: (message)"
13278 Environment\InsetSpace ~
13282 returns the value stored in a given environment variable.
13285 \begin_layout Description
13288 \begin_inset LatexCommand index
13289 name "at:put: (message)"
13293 Environment\InsetSpace ~
13295 varName\InsetSpace ~
13299 stores the new value into the given environment variable named.
13302 \begin_layout Description
13305 \begin_inset LatexCommand index
13306 name "keys (message)"
13310 Environment\InsetSpace ~
13317 of the environment variable names defined in the context that Slate was
13319 This result is independent of the actual environment variables.
13322 \begin_layout Description
13325 \begin_inset LatexCommand index
13326 name "values (message)"
13330 Environment\InsetSpace ~
13337 of the environment variable values in the context that Slate was executed
13338 in, in the same order as the keys are returned.
13339 This result is independent of the actual environment variables.
13342 \begin_layout Subsubsection
13346 \begin_layout Standard
13349 \begin_inset LatexCommand index
13350 name "Socket (object)"
13360 that provide a connection on an operating system port.
13361 The behaviors specific to these two types are as follows:
13364 \begin_layout Description
13367 \begin_inset LatexCommand index
13368 name "newOnPort: (message)"
13374 creates a new socket of the appropriate type to listen/request on the port
13378 \begin_layout Description
13381 \begin_inset LatexCommand index
13382 name "listen (message)"
13386 listen\InsetSpace ~
13389 sets the port to listening for client connections, with an optional override
13390 of the system default number of request queue entries.
13393 \begin_layout Description
13396 \begin_inset LatexCommand index
13397 name "accept (message)"
13403 creates a new socket connection for the next incoming request.
13406 \begin_layout Description
13409 \begin_inset LatexCommand index
13410 name "shutdown (message)"
13416 shuts down the socket, called when closing (automatically).
13419 \begin_layout Description
13422 \begin_inset LatexCommand index
13423 name "host (message)"
13429 answers the hostname of the socket.
13432 \begin_layout Description
13435 \begin_inset LatexCommand index
13436 name "port (message)"
13442 answers the port number of the socket.
13445 \begin_layout Description
13448 \begin_inset LatexCommand index
13449 name "peerHost (message)"
13455 answers the hostname of the peer.
13458 \begin_layout Description
13461 \begin_inset LatexCommand index
13462 name "peerPort (message)"
13468 answers the peer's port number.
13471 \begin_layout Description
13474 \begin_inset LatexCommand index
13475 name "peerIP (message)"
13481 answers the Internet Protocol address string of the peer, if any.
13484 \begin_layout Description
13487 \begin_inset LatexCommand index
13488 name "status (message)"
13498 representing the socket's current status.
13501 \begin_layout Subsection
13505 \begin_layout Standard
13506 Since the environment is structured into namespaces and many types have
13508 \begin_inset Quotes eld
13512 \begin_inset Quotes erd
13515 (for example, the iterator streams), it is helpful to have more than a
13516 name by which to refer to an object or its location in the system.
13517 The path library allows doing this with
13520 \begin_inset LatexCommand index
13521 name "Path (object)"
13527 objects, which describe the sequence of slot traversals necessary to reach
13528 a particular object.
13529 A sub-variant called
13532 \begin_inset LatexCommand index
13533 name "RootedPath (object)"
13539 remembers the specific origin object used for the path and follows the
13543 \begin_layout Description
13551 \begin_inset LatexCommand index
13552 name "from:to: (message)"
13562 object containing the necessary slot traversals to obtain the target object
13563 (the destination) from the given root (the origin).
13564 Paths are created by searching breadth-first through slot names; if the
13565 search completes without an identical match,
13572 \begin_layout Description
13576 \begin_inset LatexCommand index
13577 name "to: (message)"
13591 is taken as the origin.
13594 \begin_layout Description
13598 \begin_inset LatexCommand index
13599 name "target (message)"
13605 answers the target object as computed by following the slot names from
13609 \begin_layout Description
13613 \begin_inset LatexCommand index
13614 name "targetFrom: (message)"
13620 answers the target object relative to the given one, taking it as the origin.
13623 \begin_layout Description
13627 \begin_inset LatexCommand index
13628 name "reduced (message)"
13634 answers another equivalent
13638 object consisting of all non-delegation slots traversed.
13640 \begin_inset Quotes eld
13644 \begin_inset Quotes erd
13647 or shortest path to the object.
13650 \begin_layout Description
13654 \begin_inset LatexCommand index
13655 name "expanded (message)"
13661 answers another equivalent
13665 object consisting of all delegation slots required to traverse to reach
13666 the object directly.
13669 \begin_layout Description
13673 knows:\InsetSpace ~
13675 \begin_inset LatexCommand index
13676 name "target (message)"
13682 answers whether there is a
13686 from the given root to the target.
13689 \begin_layout Description
13693 \begin_inset LatexCommand index
13694 name "isWellKnown (message)"
13700 answers whether there is a
13708 to the given object.
13711 \begin_layout Standard
13716 objects also respond to relevant
13723 \begin_inset LatexCommand index
13733 \begin_inset LatexCommand index
13734 name "isPrefixOf: (message)"
13743 \begin_layout Subsection
13744 Exceptional Situations and Errors
13745 \begin_inset OptArg
13748 \begin_layout Standard
13757 \begin_layout Standard
13758 \begin_inset LatexCommand index
13759 name "error handling"
13764 \begin_inset LatexCommand index
13770 \begin_inset LatexCommand index
13771 name "Condition (object)"
13775 Slate has a special kind of object representing when an exceptional situation
13776 has been reached in a program, called a
13781 Condition objects may have attributes and methods like other ordinary objects,
13782 but have special methods for dealing with exceptional situations and recovering
13783 from them in various ways, often automatically.
13786 \begin_layout Subsubsection
13790 \begin_layout Description
13793 \begin_inset LatexCommand index
13794 name "Condition (object)"
13800 An object representing a situation which must be handled.
13801 This also provides a hook for working with the control-flow of the situation,
13802 and dynamic unwinding of control.
13805 \begin_layout Description
13808 \begin_inset LatexCommand index
13809 name "Restart (object)"
13815 An object representing and controlling how a condition is handled.
13816 Because they are a kind of
13820 , they can themselves be handled dynamically.
13823 \begin_layout Description
13826 \begin_inset LatexCommand index
13827 name "Warning (object)"
13832 \begin_inset LatexCommand index
13833 name "warn: (message)"
13843 which should generate notifications, but does not need to be raised for
13845 no action needs to be taken.
13850 with a description.
13853 \begin_layout Description
13856 \begin_inset LatexCommand index
13857 name "StyleWarning (object)"
13862 \begin_inset LatexCommand index
13863 name "note: (message)"
13873 that certain conventions set up by the library author have not been followed,
13874 which could lead to problems.
13879 with a description.
13882 \begin_layout Description
13885 \begin_inset LatexCommand index
13886 name "BreakPoint (object)"
13891 \begin_inset LatexCommand index
13892 name "break (message)"
13902 that pauses the current computation.
13910 \begin_layout Description
13913 \begin_inset LatexCommand index
13914 name "Abort (object)"
13919 \begin_inset LatexCommand index
13920 name "abort (message)"
13930 which unwinds the stack and cleans up contexts after a condition is raised.
13931 This is raised by the context method
13938 \begin_layout Description
13941 \begin_inset LatexCommand index
13942 name "SeriousCondition (object)"
13952 that requires handling, but is not a semantic error of the program.
13953 Rather, it's due to some incidental or pragmatic consideration.
13956 \begin_layout Description
13959 \begin_inset LatexCommand index
13960 name "Error (object)"
13965 \begin_inset LatexCommand index
13966 name "error: (message)"
13976 which involves some misstep in program logic, and raises the need for handlers
13977 to avoid a program crash.
13982 with a description.
13985 \begin_layout Subsubsection
13989 \begin_layout Description
13992 \begin_inset LatexCommand index
13993 name "signal (message)"
13999 Raises the exception that is the argument.
14000 This will immediately query for exception handlers in the current context,
14001 performing dynamic automatic recovery if possible, or starting the debugger
14005 \begin_layout Description
14008 \begin_inset LatexCommand index
14009 name "on:do: (message)"
14015 Executes the block of code with a dynamically bound handler block for the
14016 given type of condition.
14019 \begin_layout Description
14022 \begin_inset LatexCommand index
14023 name "ensure: (message)"
14029 This is a block method that ensures that the second block is executed either
14030 after the first or in
14034 case if the original is aborted or control is otherwise handed elsewhere
14035 in the middle of execution without possibility of returning into that same
14039 \begin_layout Description
14042 \begin_inset LatexCommand index
14043 name "handlingCases: (message)"
14049 Executes the block of code with a set of dynamically bound handler blocks,
14062 objects and the handlers.
14065 \begin_layout Description
14068 \begin_inset LatexCommand index
14069 name "return (message)"
14074 \begin_inset LatexCommand index
14075 name "return: (message)"
14085 Returns from the condition with a value (default
14089 ), to the point where the condition was signalled.
14092 \begin_layout Description
14095 \begin_inset LatexCommand index
14096 name "exit (message)"
14101 \begin_inset LatexCommand index
14102 name "exit: (message)"
14112 Aborts from the condition, or aborts from it with a value, to the point
14113 where the handler was set up.
14116 \begin_layout Description
14119 \begin_inset LatexCommand index
14120 name "defaultHandler (message)"
14126 This is the condition method that is called if no other handlers are found
14130 \begin_layout Subsection
14132 \begin_inset LatexCommand index
14140 \begin_layout Subsubsection
14144 \begin_layout Standard
14145 Concurrency mostly involves the unit of the
14149 , which is conceptually a manager for a single interpreter.
14150 Concurrency may be performed within the context of a single process, using
14151 stack / control-flow interaction, or across processes using messaging.
14154 \begin_layout Standard
14159 es in Slate run in turns, each acting as an interpreter with an event loop.
14160 They also act as object pools, being opaque and having a context with various
14161 local elements which must be explicitly published to be visible to objects
14162 in other Processes.
14165 \begin_layout Subsubsection
14166 Promises and Eventual-Sends
14169 \begin_layout Standard
14170 Coupled with event-loop concurrency is Slate's support of deferred execution,
14175 prefix for selectors (for the message-send) or for entire expressions.
14176 When a deferral is performed on a message-send, we call it an eventual
14178 If the return value is in a syntactic position where it might be used,
14179 the caller may expect an object of type
14187 to be delivered as the answer.
14188 These objects are resolvable placeholders, which may also communicate errors
14189 in the requested computation.
14192 \begin_layout Standard
14193 What's significant is that the use of deferred evaluation means that the
14194 relevant expression costs the caller nothing in the immediate execution
14195 turn; no matter how expensive side-effecting an expression may be, it will
14196 not be executed until at least the next turn in the owning process.
14197 Specifically, when a deferred expression is evaluated, it is turned into
14198 an event and added to the end of the owner
14203 When a process finishes each turn, it executes one event at a time from
14204 the other end of the queue.
14205 Also, if one deferred expression involves the use of the return value from
14206 another deferred expression, the dependency will be enforced so that such
14207 events will execute in the data-flow partial order in which they were created.
14210 \begin_layout Subsection
14212 \begin_inset LatexCommand label
14220 \begin_layout Standard
14221 \begin_inset LatexCommand index
14227 \begin_inset LatexCommand index
14228 name "Types (namespace)"
14232 In coordination with the reserved syntax for type-annotation in block headers,
14233 the standard libraries include a collection of representations of primitive
14238 as well as quantifications over those types.
14239 The library of types is laid out within the non-delegated namespace
14246 \begin_layout Subsubsection
14250 \begin_layout Description
14253 \begin_inset LatexCommand index
14260 The type that any object satisfies: the universal type.
14263 \begin_layout Description
14266 \begin_inset LatexCommand index
14273 The type that no object satisfies: the empty type.
14276 \begin_layout Description
14279 \begin_inset LatexCommand index
14280 name "Range (type)"
14285 \begin_inset LatexCommand index
14286 name "start (message)"
14291 \begin_inset LatexCommand index
14292 name "finish (message)"
14298 A parametrized type over another type with a linear ordering, such as
14303 This type is bounded, it has a
14311 (least and greatest possible member).
14316 can be used as a base of a Range type.
14319 \begin_layout Description
14322 \begin_inset LatexCommand index
14323 name "Member (type)"
14329 The type associated with membership in a specific set of objects.
14332 \begin_layout Description
14335 \begin_inset LatexCommand index
14336 name "Singleton (type)"
14342 The type of a single object, as distinct from any other object.
14345 \begin_layout Description
14348 \begin_inset LatexCommand index
14349 name "Clone (type)"
14355 The type of an object and its
14359 , the set of objects that are direct copies (clones plus changes to slot
14363 \begin_layout Description
14366 \begin_inset LatexCommand index
14367 name "Array (type)"
14373 The type representing all arrays, as parametrized by an element type and
14377 \begin_layout Description
14380 \begin_inset LatexCommand index
14381 name "Block (type)"
14387 The type representing code closures of a given (optional) input and output
14391 \begin_layout Subsubsection
14395 \begin_layout Standard
14396 \begin_inset LatexCommand index
14397 name "union: (message)"
14402 \begin_inset LatexCommand index
14403 name "intersection: (message)"
14408 \begin_inset LatexCommand index
14409 name "derive (message)"
14414 \begin_inset LatexCommand index
14415 name "deriveWith: (message)"
14419 Types may be combined in various ways, including
14431 which preserve type constraints on the derivations.
14434 \begin_layout Subsubsection
14438 \begin_layout Standard
14439 \begin_inset LatexCommand index
14440 name "type annotations"
14445 \begin_inset LatexCommand index
14446 name "annotations, type"
14450 Local slot specifiers in a Method header as well as input slot specifiers
14451 may have types optionally declared within the header.
14452 Within a method declaration expression, the input slots may be redundantly
14453 specified in the header as well as in the dispatch expression.
14454 However, if this is done, the header's specifier needs to be specified
14455 as an input slot and if multiple input slot types are specified, they should
14456 be specified in order.
14459 \begin_layout Standard
14460 \begin_inset LatexCommand index
14461 name "exclamation mark"
14466 \begin_inset LatexCommand index
14467 name "\\char `\\! (exclamation mark) "
14471 The syntax is similar to that for
14475 -based dispatch notation: follow the slot name with the bang character
14476 \begin_inset Quotes eld
14484 \begin_inset Quotes erd
14487 and then a type expression, which may be a primitive or derived type.
14491 \begin_layout LyX-Code
14492 [| :foo!Integer bar | bar: (foo raisedTo: 3).
14495 foo + bar] applyWith: 4.3.
14498 \begin_layout Standard
14499 Type annotations don't use primitive expressions: the evaluator doesn't
14500 have a library of pre-built types at its disposal.
14501 Instead, Type annotation expressions are evaluated within the namespace
14506 accessible from the
14511 For this reason, user-defined named types should be installed in some place
14512 accessible through the
14519 \begin_layout Subsubsection
14523 \begin_layout Standard
14524 \begin_inset LatexCommand index
14525 name "type inference"
14530 \begin_inset LatexCommand index
14531 name "inference, type"
14536 \begin_inset LatexCommand index
14537 name "inferTypes (message)"
14541 Type-inference on syntax trees is driven by calling
14547 Syntax\InsetSpace ~
14551 This will process type information already annotated to produce derived
14552 annotations on related nodes.
14555 \begin_layout Standard
14556 \begin_inset LatexCommand index
14557 name "rules (slot)"
14561 Also, there is a facility to extend the type-inference capability per method.
14562 To explain, each Type object comes with a
14566 object slot that is dual to the traits delegate object; rules delegate
14567 as the traits do but do not confer to the types their methods.
14568 Instead, they are used by the inference system transparently to allow for
14569 more intelligent specialization.
14573 \begin_layout LyX-Code
14574 _@((Member of: {True.
14575 False}) rules) ifTrue: then@(Block rules)
14577 ifFalse: else@(Block rules)
14582 then returnType union: else returnType
14587 \begin_layout Standard
14588 is a type-inference extension method for
14592 for any boolean and a pair of blocks, that the return type will be in the
14593 union of the blocks' return types.
14596 \begin_layout Subsection
14600 \begin_layout Standard
14601 \begin_inset LatexCommand index
14607 \begin_inset LatexCommand index
14608 name "provides: (message)"
14613 \begin_inset LatexCommand index
14614 name "requires: (message)"
14619 \begin_inset LatexCommand index
14620 name "features (slot)"
14625 \begin_inset LatexCommand index
14626 name "load: (message)"
14631 \begin_inset LatexCommand index
14632 name "currentModule (slot)"
14636 A simple module system is provided, designed to capture the bare essentials
14637 of a collection of coherent code.
14638 The current module system is just associated with each library file for
14648 applied to the context will add to and check against a global
14652 sequence respectively, and missing requirements are noted as the code is
14654 Again for simplicity,
14658 currently contains and expects
14667 method also invokes a hook to set the
14674 \begin_layout Subsubsection
14678 \begin_layout Description
14681 \begin_inset LatexCommand index
14682 name "Module (object)"
14688 a group of objects and methods, along with some information about their
14690 Modules can also provide privacy boundaries, restricting certain methods'
14691 accessibility outside of the module.
14694 \begin_layout Description
14697 \begin_inset LatexCommand index
14698 name "FileModule (object)"
14704 a module that has been built from source code from a file.
14707 \begin_layout Description
14710 \begin_inset LatexCommand index
14711 name "System (object)"
14717 a collection of modules that together provide some larger service.
14718 Systems notably support operations on them to control large-scale libraries.
14721 \begin_layout Subsubsection
14725 \begin_layout Description
14728 \begin_inset LatexCommand index
14729 name "new (message)"
14733 Module\InsetSpace ~
14743 \begin_layout Description
14746 \begin_inset LatexCommand index
14747 name "newLocated: (message)"
14751 Module\InsetSpace ~
14758 with the given locator (a filename produces a
14765 \begin_layout Description
14768 \begin_inset LatexCommand index
14769 name "newForFileNamed: (message)"
14773 Module\InsetSpace ~
14780 for the given file name.
14783 \begin_layout Description
14786 \begin_inset LatexCommand index
14787 name "load (message)"
14793 loads the module or system.
14796 \begin_layout Description
14799 \begin_inset LatexCommand index
14800 name "build (message)"
14806 (re-)builds the module or system.
14809 \begin_layout Description
14812 \begin_inset LatexCommand index
14813 name "provide: (message)"
14819 adds the element to the module's provision collection.
14822 \begin_layout Description
14825 \begin_inset LatexCommand index
14826 name "provides: (message)"
14832 declares a collection's elements to be provided by the current module.
14835 \begin_layout Description
14838 \begin_inset LatexCommand index
14839 name "requires: (message)"
14845 declares a collection's elements to be required by the current context.
14846 If any are not found, an error is raised.
14850 \begin_layout Standard
14851 In the future, automatic querying and loading an appropriate module could
14860 \begin_layout Description
14863 \begin_inset LatexCommand index
14864 name "import:from: (message)"
14870 adds an element to the import collection of the current module from the
14871 other one's provisions.
14872 If it's not provided by the other module, an error is raised.
14875 \begin_layout Description
14878 \begin_inset LatexCommand index
14879 name "importAll:from: (message)"
14885 adds a collection's elements to the import collection of the current module
14886 from the other one's provisions.
14887 If it's not provided by the other module, an error is raised.
14890 \begin_layout Subsubsection
14894 \begin_layout Standard
14895 \begin_inset LatexCommand index
14896 name "AutoLoader (object)"
14904 object manages unloaded
14908 s and allows them to be transparently loaded when their features are requested
14909 (via simple message-send).
14910 This mechanism relies primarily on defining methods which mimick accessors
14911 for the actual resolved object exactly, except for the fact that their
14912 action involves loading the file and then re-sending the message once that
14913 completes successfully.
14914 It is essential that the match between stub and feature be exact, since
14915 the feature itself must replace the stub once done.
14916 However, the standard protocol hides these mechanics and verification successfu
14920 \begin_layout Description
14926 readFromSourceIn: takes a
14931 , reads the source in the file, and fills the database with mappings from
14932 the features it defines to the module representing it.
14935 \begin_layout Description
14938 AutoLoader\InsetSpace ~
14939 performScan\InsetSpace ~
14952 By default it scans a default list.
14955 \begin_layout Description
14958 AutoLoader\InsetSpace ~
14961 reads definitions in the database, installing stubs for those which only
14962 take one message to resolve.
14965 \begin_layout Description
14968 AutoLoader\InsetSpace ~
14971 writes its definitions to a default external database file for quick re-constit
14975 \begin_layout Description
14978 AutoLoader\InsetSpace ~
14981 reads definitions from the default external database file.
14982 It will automatically calling
14989 \begin_layout Subsection
14993 \begin_layout Subsubsection
14997 \begin_layout Standard
14998 Slate's environment is available for saving as a whole via the representative
15002 \begin_inset LatexCommand index
15003 name "Image (object)"
15010 It offers the following methods:
15013 \begin_layout Description
15016 \begin_inset LatexCommand index
15017 name "save (message)"
15024 Writes out a file containing the contents of the heap, after running a
15025 simple cleaning sweep of memory contents.
15026 The filename defaults to
15030 or to the name of the most recent filename parameter value given.
15031 Note that execution context state is not disturbed, so saves may occur
15032 in any context as a snapshot of system-wide state, including debuggers,
15033 inspectors, and other live running processes.
15036 \begin_layout Description
15039 \begin_inset LatexCommand index
15040 name "handleShutdown (message)"
15046 Performs each action (a block) in the
15053 \begin_inset LatexCommand index
15054 name "shutdownActions (object)"
15064 mapping keys to those corresponding actions.
15065 The keys are not meaningful except for identification by the library which
15066 installs it, so generally
15070 s are used or objects which can be identified and distinguished very easily.
15075 is actually called by the
15080 The purpose of shutdown actions is to clean up any state that may affect
15081 the surrounding environment if not handled properly.
15084 \begin_layout Description
15087 \begin_inset LatexCommand index
15088 name "handleStartup (message)"
15094 Performs each action (a block) in the
15101 \begin_inset LatexCommand index
15102 name "startupActions (object)"
15112 mapping keys to those corresponding actions.
15113 The keys are not meaningful except for identification by the library which
15114 installs it, so generally
15118 s are used or objects which can be identified and distinguished very easily.
15123 is actually called by the
15127 method when the image is re-started, because the execution context is preserved
15128 , and the VM sends a signal to indicate a fresh startup.
15129 The purpose of startup actions is to clean up any state that may be left
15130 over from a previous session with that Slate environment, and also to re-initia
15131 lize state which must persist to avoid inconsistent execution of various
15138 \begin_inset LatexCommand vref
15139 reference "sub:External-Resources"
15143 ) whose connections must be persistent are primary users of these hooks.
15146 \begin_layout Description
15149 \begin_inset LatexCommand index
15150 name "handleSave (message)"
15156 Performs each action (a block) in the
15163 \begin_inset LatexCommand index
15164 name "saveActions (object)"
15174 mapping keys to those corresponding actions.
15175 The keys are not meaningful except for identification by the library which
15176 installs it, so generally
15180 s are used or objects which can be identified and distinguished very easily.
15185 is actually called by the
15190 The purpose of save actions is to clean up any state that should not be
15191 saved at all; for example, passwords stored for secure access to external
15192 resources should be purged.
15193 In general, startup actions should be used for any other save-related activitie
15197 \begin_layout Subsubsection
15198 Heap Image Segments
15201 \begin_layout Standard
15202 We are developing methods for extracting
15203 \begin_inset Quotes eld
15207 \begin_inset Quotes erd
15210 of images and saving them on disk along with explicit linking information
15211 so that groups of arbitrary objects may be transported reliably.
15214 \begin_layout Section
15218 \begin_layout Standard
15219 \begin_inset LatexCommand index
15224 Slate provides an unusual opportunity to organize programs and environments
15225 in unique ways, primarily through the unique object-centered combination
15226 of prototypes and multiple-argument dispatch.
15227 This section provides a guide to the generally recommended style of developing
15228 in this environment, to promote a better understanding of the system and
15232 \begin_layout Subsection
15233 Environment organization
15236 \begin_layout Subsubsection
15240 \begin_layout Standard
15241 \begin_inset LatexCommand index
15246 New namespaces should be used for separate categories of concepts.
15247 Occasionally, these are the kind that should automatically included in
15248 their enclosing namespace (which can be further inherited up to the lobby).
15249 This is done simply by placing the new namespace object in a delegate slot.
15252 \begin_layout Subsubsection
15253 Exemplars or Value Objects
15256 \begin_layout Standard
15257 These represent objects such as specific colors with well-known names, or
15258 cloneable objects with useful default values.
15259 Generally these should have capitalized names if they are cloneable, and
15260 can be capitalized or lowercase if not.
15261 For cases with a large group of such value objects, like colors, there
15262 usually should involve a separate namespace to avoid cluttering up the
15264 This also helps with naming the use of a value if the intuitive interpretation
15265 of its name is dependent on context.
15268 \begin_layout Subsection
15272 \begin_layout Standard
15273 One of the primary benefits and peculiarities of the Smalltalk
15274 \begin_inset LatexCommand index
15279 family's style of method syntax is that it provides an opportunity to name
15280 one's protocols using something resembling a phrase.
15281 Usually, it is recommended to re-use protocols whenever describing similar
15282 behaviors, as an aid to the user's memory in matching functionality to
15283 a name to call; in some exceptional situations, different protocols are
15284 helpful when there is more than one desired algorithm or behavior to provide
15285 for a kind of object.
15286 Here are some general practices which have been brought forward from years
15287 of Smalltalk practice.
15290 \begin_layout Subsubsection
15294 \begin_layout Standard
15295 Attributes are perhaps the simplest to name of all, in that they are generally
15296 nouns or noun phrases of some sort, whether used as direct slots or methods
15297 which calculate a property dynamically.
15300 \begin_layout Subsubsection
15304 \begin_layout Standard
15305 Methods which test for some fact or property about a single object are generally
15307 \begin_inset Quotes eld
15311 \begin_inset Quotes erd
15320 answers whether one's car is red.
15321 Slate offers an additional idiom over this particular style, in that
15328 is also possible, since
15332 looks at both the subject and the object of the query.
15333 The only remaining obstacle is whether the conceived subject can stand
15334 on its own as a named concept; if there are multiple perspectives in normal
15335 use, the language can support a certain amount of ambiguity using subjective
15336 overrides, but there are limits to this.
15339 \begin_layout Subsubsection
15343 \begin_layout Standard
15352 of building new objects in Slate, rather than instantiating a class, there
15353 is still the need to provide and use an idiom for delivering optional attribute
15354 s and varying semantics of creation to one's new objects.
15355 Generally, these methods should start with
15359 - as a prefix to help the reader and code user to know that the original
15360 object will not be modified, and that the result is a new, separate individual.
15361 These methods are usually methods with keywords, with each of the keywords
15362 describing each option.
15363 If the keyword literally names an attribute, the optional-keyword facility
15364 is ideal, but if providing a grammatical phrase using prepositions, it
15365 is preferable to create a full keyword method.
15368 \begin_layout Subsubsection
15372 \begin_layout Standard
15373 The most interesting protocols are akin to commands, where one addresses
15374 the objects in question with a phrase that suggests performing some action.
15375 This should usually have one key verb for each major component of the action
15376 (there is usually just one action per method, but
15378 select:thenCollect:
15380 , for example, performs two), and prepositions or conjunctions to relate
15381 the verbs and nouns.
15384 \begin_layout Standard
15385 There is a particular idiom of languages without multiple dispatch to add
15386 the noun (or type) name of an argument to the name of a function involving
15388 Slate makes this unnecessary and an obstacle to polymorphism, since the
15389 type of an argument can be specified in a dispatch as needed.
15390 Of course, nouns still sometimes have a useful place in a method name,
15391 when the noun is not a formal type, but an informal role or usage name.
15394 \begin_layout Subsubsection
15398 \begin_layout Standard
15399 These are perhaps the most controversial of any programming language's protocols.
15400 In the Smalltalk family of syntax, there are no precedence orderings between
15401 operators of different names, so the issues with those do not arise.
15402 However, it is very tempting for the library author to re-use mathematical
15403 symbols for her own domain, to allow her users to have a convenient abbreviatio
15404 n for common operations.
15405 While this benefits the writer of code which uses her library, there are
15406 domains and situations that punish the reader of the code that results.
15409 \begin_layout Standard
15410 For example, mathematical addition and multiplication symbols,
15411 \begin_inset Quotes eld
15419 \begin_inset Quotes erd
15423 \begin_inset Quotes eld
15431 \begin_inset Quotes erd
15434 , are generally associative and commutative.
15435 That is, repeated calls to these should be able to re-order their arguments
15436 arbitrarily and achieve the same result.
15440 \begin_inset Formula $3+4+5=4+3+5=5+4+3$
15446 However, string concatenation (as an example) is not commutative; we cannot
15447 re-order the arguments and expect the same result, i.e\SpecialChar \@.
15449 \begin_inset Formula "gold"+"fish"="goldfish"
15454 \begin_inset Formula "fish"+"gold"="fishgold"
15459 Because concatenation is associative, however, we can re-use the punctuation
15460 style of the semi-colon
15461 \begin_inset Quotes eld
15469 \begin_inset Quotes erd
15472 and achieve intuitive results.
15473 This general style of reasoning should be applied wherever this type of
15474 operator name re-use could arise.
15477 \begin_layout Subsection
15478 Instance-specific Dispatch
15481 \begin_layout Standard
15482 \begin_inset LatexCommand index
15483 name "instance-specific dispatch"
15488 \begin_inset LatexCommand index
15489 name "dispatch, instance-specific"
15493 Often there are situations whether the user will want to specialize a method
15494 in some argument position for a specific object.
15495 There are various reasons to do this, and various factors to consider when
15499 \begin_layout Subsubsection
15503 \begin_layout Standard
15504 Two common patterns where the developer wants to specialize to a single
15505 object usually emerge after extended usage.
15506 First, there are domain objects which naturally have special non-sharable
15512 is clearly a particular object that helps define the semantics of the whole
15513 system, by representing mechanical truth abstractly.
15514 In other situations, the same pattern occurs where one has a
15518 concept, or locally an
15522 concept within a domain.
15525 \begin_layout Standard
15526 Second, there are situations whether the user is demonstratively modifying
15527 the behavior of some
15531 in order to achieve some
15535 that behaves in some situation as they desire.
15536 Depending on whether the user decides to share this behavior or not, the
15537 instance-specific behavior may or may not migrate to some shared
15542 In either case, this is an encouraged use of objects and methods within
15546 \begin_layout Subsubsection
15550 \begin_layout Standard
15551 There are factors which weigh
15555 the use of dispatch on objects with non-shared behaviors.
15556 Generally, these just amount to a few simple reasons.
15557 First, the behavior will not be shared, which is obvious, but sometimes
15558 not clear to the author.
15559 Second, the author may mistake an object for its value or attributes, such
15564 s, which are not unique per their value, and so get unexpected results if
15570 The same is true for all literals of that nature, with the exception of
15578 \begin_layout Standard
15579 The general rule for defining a
15583 on an instance which is a lightweight
15584 \begin_inset Quotes eld
15588 \begin_inset Quotes erd
15591 object, is that the object must be reliably re-identifiable, as
15595 s are for the language, or through naming paths from the
15599 or some other object that the user is given access to, such as a method
15601 Otherwise, the user must be careful to hang on to the identity of the given
15602 object, which offsets any polymorphism gains and exposes implementation
15603 details unnecessarily.
15606 \begin_layout Subsection
15607 Organization of Source
15610 \begin_layout Standard
15611 The nature (and current limitations) of defining objects, relations, and
15612 the methods that operate over them require a certain ordering at this point
15613 which is worth mentioning.
15614 The central point of constraints is the definition of dispatching methods:
15615 these methods must have their dispatch targets available at the time they
15617 Since there is no late-binding yet of dispatch expressions, generally the
15618 basic construction of one's traits and prototype definitions must all occur
15619 before defining methods which dispatch to them.
15620 The definition needs merely to introduce the actual object that will be
15621 used later; other features of the objects, such as the slots and methods
15622 defined upon it, are late-bound and will not hinder a method-definition
15626 \begin_layout Standard
15627 In general, however, it is recommended to define methods in a
15631 fashion: that more basic utilities should be introduced before the methods
15633 This allows the user (and the author) of the code to read the program sequentia
15634 lly as a document and have some understanding of a program's components
15635 when only the name of the component is seen.
15636 Of course, this is not always possible, but it helps often enough.
15639 \begin_layout Subsection
15640 Type-Annotating Expressions
15643 \begin_layout Subsection
15647 \begin_layout Standard
15648 Slate includes a port of Smalltalk's SUnit unit-testing framework (implemented
15653 ), as well as a collection of unit tests (in
15658 Three namespaces are provided in which users may place their
15665 \begin_layout Description
15666 testing\InsetSpace ~
15667 UnitTests should contain unit-test cases;
15670 \begin_layout Description
15671 testing\InsetSpace ~
15672 RegressionTests is for test cases covering bug fixes, for detecting
15676 \begin_layout Description
15677 testing\InsetSpace ~
15678 BenchmarkTests is to contain test cases for measuring the speed of
15682 \begin_layout Standard
15685 testing runAllTests
15691 s found in a recursive search of the UnitTests and RegressionsTests namespaces.
15694 \begin_layout Standard
15695 To write your own test cases, add a prototype derived from TestCase to the
15696 namespace you've chosen, within the appropriate container - either UnitTests
15697 or RegressionTests.
15698 For example, suppose you are writing test cases covering Ranges; you might
15702 \begin_layout LyX-Code
15703 UnitTests addPrototype: #Range derivedFrom: {TestCase}.
15706 \begin_layout Standard
15707 Once your prototype has been constructed, add tests to it.
15708 Test methods are unary methods with selectors beginning with
15716 \begin_layout LyX-Code
15717 tc@(UnitTests Range traits) testInclusion1
15720 \begin_layout LyX-Code
15721 "Verify that all elements of an Range are found in that Range."
15724 \begin_layout LyX-Code
15728 \begin_layout LyX-Code
15729 range: (25 to: 50 by: 1).
15732 \begin_layout LyX-Code
15733 tc assert: (range allSatisfy: [| :item | range includes: item]).
15736 \begin_layout LyX-Code
15740 \begin_layout Standard
15741 The important assertion methods are
15744 \begin_layout LyX-Code
15748 \begin_layout LyX-Code
15752 \begin_layout LyX-Code
15756 \begin_layout LyX-Code
15757 should: Method raise: Condition
15760 \begin_layout LyX-Code
15764 \begin_layout LyX-Code
15765 shouldnt: Method raise: Condition
15768 \begin_layout Standard
15769 and variants with an additional
15771 description: String
15776 \begin_layout Standard
15777 Once all your test methods are defined, a
15781 method should be defined that constructs a
15792 \begin_layout LyX-Code
15793 t@(UnitTests Range traits) suite
15796 \begin_layout LyX-Code
15797 [t suiteForSelectors: {
15800 \begin_layout LyX-Code
15804 \begin_layout LyX-Code
15806 \begin_inset Quotes eld
15812 \begin_inset Quotes erd
15818 \begin_layout LyX-Code
15822 \begin_layout Standard
15823 See also the method
15825 TestCase suiteForSelectors:
15832 method is called by
15836 , which in turn is called by
15843 \begin_layout Standard
15844 At this point, invoking
15846 testing runAllTests
15848 will exercise your new code.
15851 \begin_layout Standard
15857 \begin_layout Bibliography
15858 \begin_inset LatexCommand bibitem
15859 label "Chambers 97"
15866 The Cecil Language: Specification & Rationale
15870 Cecil/Vortex Project.
15874 \begin_inset LatexCommand htmlurl
15875 name "Available Online"
15876 target "http://www.cs.washington.edu/research/projects/cecil/www/pubs/cecil-spec.html"
15883 \begin_layout Bibliography
15884 \begin_inset LatexCommand bibitem
15892 Multiple Dispatch with Prototypes
15898 \begin_inset LatexCommand htmlurl
15899 name "Available Online"
15900 target "http://tunes.org/\\~{}eihrul/pmd.pdf"
15907 \begin_layout Bibliography
15908 \begin_inset LatexCommand bibitem
15909 label "Ungar et al 95"
15916 The Self Programmer's Reference Manual
15919 Ole Agesen, Lars Bak, Craig Chambers, Bay-Wei Chang, Urs Holzle, John Maloney,
15921 Smith, David Ungar, and Mario Wolczko.
15922 Sun Microsystems and Stanford University, 4.0 edition, 1995.
15926 \begin_inset LatexCommand htmlurl
15927 name "Available Online"
15928 target "http://research.sun.com/self/language.html"
15935 \begin_layout Bibliography
15936 \begin_inset LatexCommand bibitem
15944 On Lisp: Advance Techniques for Common Lisp
15948 Prentice-Hall, Inc., 1994.
15951 \begin_inset LatexCommand htmlurl
15952 name "Available Online"
15953 target "http://paulgraham.com/onlisp.html"
15960 \begin_layout Bibliography
15961 \begin_inset LatexCommand bibitem
15962 label "The Refactory"
15967 The Smalltalk Refactoring Browser.
15969 \begin_inset LatexCommand htmlurl
15970 name "Online Overview"
15971 target "http://www.refactory.com/RefactoringBrowser/Rewrite.html"
15978 \begin_layout Bibliography
15979 \begin_inset LatexCommand bibitem
15987 The Subjective Prototype
15991 Sun Microsystems Laboratories.
15995 \begin_inset LatexCommand htmlurl
15996 name "Available Online"
15997 target "http://www-staff.mcs.uts.edu.au/~cotar/proto/randy.txt"
16004 \begin_layout Standard
16008 \begin_inset LatexCommand printindex