home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / dev / alst-3.04.lha / ALSt-3.04 / manual.ms < prev    next >
Text File  |  1994-05-14  |  31KB  |  836 lines

  1. .TL
  2. Little Smalltalk Users Manual - Version Three
  3. .AU
  4. Tim Budd
  5. .AI
  6. Department of Computer Science
  7. Oregon State University
  8. Corvallis, Oregon
  9. 97331 USA
  10. .AB
  11. .PP
  12. Version three of Little Smalltalk was designed specifically to
  13. be easy to port
  14. to new machines and operating systems.  
  15. This document provides the basic information needed to use Version Three of
  16. Little Smalltalk, plus information needed by those wishing to undertake the
  17. job of porting the system to a new operating environment.
  18. .AE
  19. .PP
  20. The first version of Little Smalltalk, although simple, small and fast, was in 
  21. a number of very critical ways very Unix specific.  Soon after the
  22. publication of the book \fIA Little Smalltalk\fP, requests started flooding
  23. in asking if there existed a port to an amazingly large number of different
  24. machines, such as the IBM PC, the Macintosh, the Acorn, the Atari, and even
  25. such systems as DEC VMS.  Clearly it was beyond our capabilities to
  26. satisfy all these requests, however in an attempt to meet them partway in
  27. the summer of 1988 I designed a second version of Little Smalltalk, which
  28. was specifically designed to be less Unix specific and more amenable to
  29. implementation of different systems.
  30. .PP
  31. This document describes is divided into two parts.  In part one I describe
  32. the basic features of the user interface.  This is essential information
  33. for anybody wishing to use the system.  In part two we give the basic
  34. information needed by anybody wishing to undertake the task of porting
  35. version three Little Smalltalk to a new machine.
  36. .NH
  37. Getting Started
  38. .PP
  39. How you get started depends upon what kind of system you are working on.
  40. Currently there are two styles of interface supported.  A line-oriented,
  41. tty style stdin interface is available, which runs under Unix and other systems.
  42. There is also a window based system which runs under X-windows and on the
  43. Mac.
  44. .NH 2
  45. The stdin/stdout interface
  46. .PP
  47. Using the stdin/stdout interface, there is a prompt (the ``>'' caracter)
  48. typed to indicate the system is waiting for input.  
  49. Expressions are read at the keyboard and
  50. evaluated following each carrage return.  The result of the expression
  51. is then printed.
  52. .DS I
  53. >    5 + 7
  54. 12
  55. .DE
  56. Global variables can be created simply by assigning to a name.
  57. The value of an assignment statement is the value of the right hand side.
  58. .DS I
  59.     x <- 3
  60. 3
  61. .DE
  62. Multiple expressions can appear on the same line separated by periods.
  63. Only the last expression is printed.
  64. .DS I
  65.     y <- 17.  3 + 4
  66. 7
  67. .DE
  68. .NH 2
  69. The windowing interface
  70. .PP
  71. The windowing interface is built on top of guido van rossums standard
  72. window package, and runs on top of systems that support standard windows.
  73. These include X-11 and the Macintosh.
  74. .PP
  75. When you start up the system, there will be a single window titled
  76. ``workspace''.  You can enter expressions in the workspace, then select either
  77. the menu items ``do it'' or ``print it''.
  78. Both will evaluate the expression; the latter, in addition, will print the
  79. result.
  80. .PP
  81. A number of other memu commands are also available.  These permit you to
  82. save the current image, exit the system, or start the browser.
  83. .PP
  84. The browser is an interface permiting you to easily view system code.
  85. Selecting a class in the first pane of the browser brings up a second pane
  86. in which you can select methods, selecting a method brings up a third pane
  87. in which you can view and edit text.  Selecting ``compile'' following the
  88. editing of text will attempt to compile the method.  If no errors are
  89. reported, the method is then available for execution.
  90. .NH
  91. Exploring and Creating
  92. .PP
  93. This section describes how to discover information about existing objects 
  94. and create new objects using the Little Smalltalk
  95. system (version three).  
  96. In Smalltalk one communicates with objects by passing messages to them.
  97. Even the addition message + is treated as a message passed to the
  98. first object 5, with an argument represented by the second object.  
  99. Other messages can be used to discover
  100. information about various objects.
  101. The most basic fact you can discover about an object is its class.
  102. This is given by the message \fBclass\fP, as in the following examples:
  103. .DS I
  104. >    7 class 
  105. Integer
  106. >    nil class
  107. UndefinedObject
  108. .DE
  109. .PP
  110. Occasionally, especially when programming, one would like to ask whether
  111. the class of an object matches some known class.  One way to do this would
  112. be to use the message \fB= =\fP, which tells whether two expressions 
  113. represent the same object:
  114. .DS I
  115. >    ( 7 class = = Integer)
  116. True
  117. >    nil class = = Object
  118. False
  119. .DE
  120. .PP
  121. An easier way is to use the message \fBisMemberOf:\fP;
  122. .DS I
  123. >    7 isMemberOf: Integer
  124. True
  125. >    nil isMemberOf: Integer
  126. False
  127. .DE
  128. .PP
  129. Sometimes you want to know if an object is an instance of a particular
  130. class or one if its subclasses; in this case the appropriate message is
  131. \fBisKindOf:\fP.
  132. .DS I
  133. >    7 isMemberOf: Number
  134. False
  135. >    7 isKindOf: Number
  136. True
  137. .DE
  138. .PP
  139. All objects will respond to the message \fBdisplay\fP by telling a little
  140. about themselves.  Many just give their class and their printable
  141. representation:
  142. .DS I
  143. >    7 display
  144. (Class Integer) 7
  145. >    nil display
  146. (Class UndefinedObject) nil
  147. .DE
  148. .LP
  149. Others, such as classes, are a little more verbose:
  150. .DS I
  151. >    Integer display
  152. Class Name: Integer
  153. SuperClass: Number
  154. Instance Variables:
  155. no instance variables
  156. Subclasses:
  157. .DE
  158. .LP
  159. The display shows that the class \fBInteger\fP is a subclass of class
  160. \fBNumber\fP (that is, class \fBNumber\fP is the superclass of
  161. \fBInteger\fP).  There are no instance variables for this class, and it
  162. currently has no subclasses.  
  163. All of this information could be obtained by means of other messages,
  164. although the \fBdisplay\fP form is the easiest.
  165. [ Note: at the moment printing subclasses takes a second or two.  I'm not
  166. sure why.]
  167. .DS I
  168. >    List variables display
  169. links
  170. >    Integer superClass
  171. Number
  172. >    Collection subClasses display
  173. IndexedCollection
  174. Interval
  175. List
  176. .DE
  177. About the only bit of information that is not provided when one passes the
  178. message \fBdisplay\fP to a class
  179. is a list of methods the class responds to.  There are two
  180. reasons for this omission; the first is that this list can often be quite
  181. long, and we don't want to scroll the other information off the screen
  182. before the user has seen it.  The second reason is that there are really
  183. two different questions the user could be asking.  The first is what
  184. methods are actually implemented in a given class.  A list containing
  185. the set of methods implemented in a class can be found by passing the
  186. message \fBmethods\fP to a class.
  187. As we saw with the message
  188. \fBsubClasses\fP shown above, the command \fBdisplay\fP prints this
  189. information out one method to a line:
  190. .DS I
  191. >    True methods display
  192. #ifTrue:ifFalse:
  193. #not
  194. .DE
  195. .PP
  196. A second question that one could ask is what message selectors an instance of a
  197. given class will respond to, whether they are inherited from superclasses
  198. or are defined in the given class.  This set is given in response to the
  199. message \fBrespondsTo\fP. [ NOTE: again form some reason I'm not sure of
  200. this command seems to take a long time to execute ].
  201. .DS I
  202. >    True respondsTo display
  203. #class
  204. #==
  205. #hash
  206. #isNil
  207. #display
  208. #=
  209. #basicSize
  210. #isMemberOf:
  211. #notNil
  212. #print
  213. #basicAt:put:
  214. #isKindOf:
  215. #basicAt:
  216. #printString
  217. #or:
  218. #and:
  219. #ifFalse:ifTrue:
  220. #ifTrue:
  221. #ifFalse:
  222. #not
  223. #ifTrue:ifFalse:
  224. .DE
  225. .PP
  226. Alternatively, one can ask whether instances of a given class will respond
  227. to a specific message by writing the message selector as a symbol:
  228. .DS I
  229. >    String respondsTo: #print
  230. True
  231. >    String respondsTo: #+
  232. False
  233. .DE
  234. .PP
  235. The inverse of this would be to ask what classes contain methods for a
  236. given message selector.  Class \fBSymbol\fP defines a method to yield just
  237. this information:
  238. .DS I
  239. >    #+ respondsTo display
  240. Integer
  241. Number
  242. Float
  243. .DE
  244. .PP
  245. The method that will be executed in response to a given message selector
  246. can be displayed by means of the message \fBviewMethod:\fP
  247. .DS I
  248. >    Integer viewMethod: #gcd:
  249. gcd: value
  250.     (value = 0) ifTrue: [ \(ua self ].
  251.     (self negative) ifTrue: [ \(ua self negated gcd: value ].
  252.     (value negative) ifTrue: [ \(ua self gcd: value negated ].
  253.     (value > self) ifTrue: [ \(ua value gcd: self ].
  254.     \(ua value gcd: (self rem: value)
  255. .DE
  256. .PP
  257. Some Smalltalk systems make it very difficult for you to disc