home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / language / quinta.cpt / Quinta / Quinta.doc2.txt < prev    next >
Text File  |  1990-04-04  |  23KB  |  542 lines

  1.  
  2. The Quinta Environment
  3.  
  4. To some extent, the Quinta system can be self documenting.  
  5. Messages and Responses are elements of the Quinta dictionary 
  6. and may be pushed onto the stack as objects for examination.  To 
  7. push a message onto the stack, enclose it in underscores.  For 
  8. example, to push the message *, 
  9.  
  10.     _*_
  11.  
  12. Several important operations are possible for message objects.  
  13. For example, with a message object on TOS, the message send 
  14. will send that message as if it were typed into the Quinta 
  15. interpreter.  The message print will print information about the 
  16. message including any comments attached to it and the classes 
  17. which may respond to it.  For a response object, the message 
  18. print will print information about the response.
  19.  
  20. A class may be pushed onto the stack by simply typing its name 
  21. into the interpreter.  The resulting object is an instance of class 
  22. class.
  23.  
  24. By pushing a list of classes onto the stack, and sending the 
  25. message responses, a list of responses will be returned to the 
  26. stack.  This list contains the responses defined for that set of 
  27. classes.  Pushing a list of n classes specifies messages of order n.  
  28. For example:
  29.  
  30.     integer float 2 >list
  31.  
  32. The above line builds a list with 2 class objects.
  33.  
  34.     responses
  35.  
  36. This message pushes a list of all responses to messages of order 2 
  37. which are defined when the stack has an integer in level 1 and a 
  38. float in level 2.  Of course, this includes any response defined 
  39. for any ordered combination of n subclasses of the n classes in 
  40. the list.
  41.  
  42. For a response object, the message msg pushes the message for 
  43. which this response is the definition.  The message home pushes 
  44. the list of classes for which this response if the definition.  To 
  45. summarize:  A message can be sent to the stack.  A message of 
  46. order n requires n receivers.  The classes of these n receivers 
  47. must have a response defined to that message.  This response is a 
  48. dictionary structure in itself.  The home of this response is that 
  49. set of classes.
  50.  
  51. The message pdict will print all messages in the dictionary.  This 
  52. can be a very useful method for the Quinta interpreter to 
  53. document itself.
  54.  
  55. The Macintosh implementation of Quinta is an interactive 
  56. interpreter with a text window used for all input and output.  
  57. Upon executing the Quinta application, there is a pause as the 
  58. dictionary is built.  Then, it is your turn to act.  The enter key is 
  59. the significant key.  Like MPW, Quinta will not process input 
  60. until the enter key is pressed.  The return key is not equivalent.  
  61. Multiple lines may be sent by selecting all the lines and pressing 
  62. enter.  In fact, when processing input, Quinta first checks to see 
  63. if the selection is just that.  Is there is a region of text darkened ?  
  64. If so, that text alone is processed.  Otherwise, only the text on 
  65. the current line is processed.  Therefore, if a string of messages 
  66. or response definition or other entry spans more than one line, 
  67. the entire selection must be selected before pressing enter.
  68.  
  69. The editor is a simple editor with no advanced features.  Menus 
  70. are available and the editor is capable of operating on multiple 
  71. files, but the Worksheet is the primary window and file.  To 
  72. write a Quinta program, use the editor (or any editor) to store 
  73. your message, class, and response definitions.  Then, open that 
  74. file from within Quinta.  Copy your Quinta source into the 
  75. worksheet.  Select (highlight by dragging) all the lines you wish 
  76. to be executed (entered into the dictionary).  Then, press Enter 
  77. (not Return), to process the source.  The shortcut for all of the 
  78. above is the Load entry under the Command menu.  This will 
  79. prompt you for a file of Quinta source, and it will execute all of 
  80. the code contained in that file.  Try this procedure on the 
  81. example program sieve.q to see how it all works.  In addition, 
  82. there is a message called load.  Given a filename in a string, this 
  83. allows files to be loaded into the dictionary under Quinta 
  84. control.
  85.  
  86. The Class Hierarchy
  87.  
  88. From the interpreter, the message classes will push a list on the 
  89. stack containing all of the classes currently in the interpreter.  
  90. Typing the name of any class will push that class object onto the 
  91. stack.
  92.  
  93. The most important class of all Quinta classes is generic.  
  94. Generic is the parent class of all other object classes (analogous 
  95. to Smalltalk's OBJECT).  The responses defined for generic are 
  96. for messages of a very general nature.  These messages should 
  97. be acceptable for receiving objects of any class.  However, 
  98. responses for class generic are not acceptable when the stack is 
  99. empty.  Furthermore, there will be times that we wish to 
  100. perform certain actions regardless of the condition of the stack.  
  101. For this reason, there is another "class" above generic, called 
  102. control.  There are no instances of class control which can be 
  103. created.  We think of the interpreter itself as the only object of 
  104. class control.  The interpreter is considered to always be on the 
  105. bottom of the stack, for the purposes of receiving messages.  In 
  106. terms of a physical paradigm, it is most accurate to say that we 
  107. consider the stack to be resting on the interpreter.  We send 
  108. messages to the stack, and the objects on TOS respond.  
  109. However, when we send a message to the stack and the stack is 
  110. empty or cannot respond, it comes to rest on the interpreter, 
  111. which either responds appropriately or assumes the role of 
  112. communicating an error message.
  113.  
  114. An example of a message with a response for class control is 
  115. pdict.  This message simply prints every message in the 
  116. dictionary.  It requires no parameters or input.  It does not 
  117. examine or modify the stack.  It simply provides information to 
  118. the user about the interpreter itself.
  119.  
  120. The class logical is used for conditionals.  A logical object 
  121. represents either true or false.  The messages true and false push 
  122. the only two unique instances of class logical.
  123.  
  124. The class quantity is the parent class for all types of data which 
  125. are manipulated using arithmetic operations.  There are no 
  126. instances of class quantity.  There may be, however, a number 
  127. of subclasses of class quantity.  One such subclass is real.  This 
  128. class also has no instances.  Subclasses of real include integer and 
  129. float.  These are general purpose classes for numerical 
  130. computations and representations.  Any token beginning with a 
  131. digit or unary sign will be interpreted as a real.  If it contains a 
  132. decimal point, it is considered a float.  Floating point operations 
  133. in Quinta are always at extended precision.  The interpreter 
  134. recognizes integers and floating point numbers when entered.  
  135. Exponential notation is ok for floating point numbers, but unless 
  136. the number contains a decimal point, it is assumed to be an 
  137. integer.  Therefore,
  138.  
  139.     345e56
  140.  
  141. will be read by the interpreter incorrectly.  However,
  142.  
  143.     345.e56
  144.  
  145. will work.
  146.  
  147. The class date is used for manipulations of dates.  It is a subclass 
  148. of integer, and represents the number of seconds since 12:00 am 
  149. January 1, 1904.  The message today of class control will push 
  150. the current date onto the stack.  Since date is a descendant of 
  151. integer, dates may be manipulated arithmetically.  Keep in 
  152. mind, that the units on date are seconds.  So, to add one day to a 
  153. date, add 86400, not 1.
  154.  
  155. The class string is used for all data represented as strings of 
  156. characters.  Strings in Quinta may be essentially any length and 
  157. are recognized by the interpreter when surrounded by double 
  158. quotes.
  159.  
  160. The class message is used to allow Quinta messages to operate 
  161. on other messages as a construct of the dictionary.  The class 
  162. response is used to represent responses.  Both respond to the 
  163. message print, for the purpose of displaying information from 
  164. the dictionary.  A message object is recognized by the 
  165. interpreter when surrounded by underscores.  For any message 
  166. on the stack, the message responses will push a list of all possible 
  167. responses to that message.
  168.  
  169. Class block is used for defining Quinta code.  A block is a 
  170. stream of tokens which can be stored in a response.  A block is 
  171. recognized by the interpreter when surrounded by [ brackets ].  
  172. A block, once created, may be used to defined a response to a 
  173. message for some set of classes.  For examples, see above.  In 
  174. addition, a block may be executed by sending the message send.  
  175. Blocks may be nested.  Finally, blocks may be used in the dountil 
  176. and whiledo loops.  See below for a discussion of the looping 
  177. constructs in Quinta.
  178.  
  179. Class aggregation is the parent class for collections of objects.  
  180. For example, class list is one of the subclasses in the aggregation 
  181. class tree.  Currently list is the only significant structure 
  182. supported by aggregation.
  183.  
  184. A list object is a list of other objects.  They are represented 
  185. internally in a manner similar to Lisp lists and respond to the 
  186. messages car and cdr, as in Lisp.  Car pushes the head of the list.  
  187. Cdr pushes the tail of the list, which will ALWAYS be another 
  188. list, even if the list has zero or one members.  A subclass of list, 
  189. called dim is used to specify dimensions of matrices.  Two 
  190. integers can respond to the message >dim to create a new dim 
  191. object.
  192.  
  193. Class matrix is used for matrix operations.  Matrices are arrays 
  194. of floating point numbers.  For speed, it was decided that this 
  195. implementation of matrices would only handle numbers, not 
  196. general objects.  Standard operations on matrices are supported 
  197. including inversion, determinant, transverse, multiplication, dot 
  198. product, etc.
  199.  
  200. Class variable is used for operations on Quinta variables.  A 
  201. variable object is recognized by the interpreter when enclosed in 
  202. single quotes.  Any object my be stored in a variable, such as
  203.  
  204.     object 'var' sto
  205.  
  206. Any variable my have its contents recalled using rcl and any 
  207. variable may be purged from the dictionary using purge.
  208.  
  209. Class member is used to represent member variables of class 
  210. instances.  Any user defined class may have member variables 
  211. for encapsulation of data.  Member variables, in general, act as 
  212. regular variables, but their internal implementation is different.  
  213. When an object of a user defined class with member variables is 
  214. on TOS, sending the name of one of those member variables 
  215. enclosed in single quotes will push the object of class member 
  216. onto the stack.  The object itself will be removed.  Then, when 
  217. something is stored into the member variable using sto, the 
  218. surrounding object is returned to the stack.
  219.  
  220. Class constant is a subclass of variable which does not allow 
  221. modification of its contents.  Any variable may be converted to a 
  222. constant using the message >const.
  223.  
  224. Messages
  225.  
  226. The following is a summary of some of the messages of Quinta.  
  227. The control response for the message messages will push a list of 
  228. every message in the dictionary (this can be a rather large list).
  229.  
  230. Any part of a line after a semicolon is considered a comment.
  231.  
  232. selfdoc    adds comments to a number of messages in the 
  233. dictionary.  These are not added at initialization to save 
  234. memory.  Any message will have its comment printed (if it has 
  235. one) when the message itself is printed.  All messages can be 
  236. printed using the message pdict.
  237.  
  238. >str    converts an object to a string.  If there is no response 
  239. specially programmed for the class of the receiver, the name of 
  240. the class of the receiver is the result.
  241.  
  242. >float    converts an integer to a float
  243.  
  244. PI    pushes the floating point approximation to pi
  245.  
  246. allmsg    pushes a list of every message in the dictionary.
  247.  
  248. size    pushes the size of the receiver.  Defined for lists, 
  249. matrices, and strings
  250.  
  251. cos    most standard trigonometric operations are defined.  
  252. These functions as well as exponential functions and the like are 
  253. defined only for class float.  To define them for integers as well:
  254.  
  255.     float integer inherit
  256.  
  257. (This uses the multiple inheritance feature of Quinta)
  258.  
  259. beep    A simple beep, using whatever beep is currently the 
  260. system beep
  261.  
  262. depth    gives the integer depth of the stack
  263.  
  264. if    used for conditionals - not object oriented.  the structure 
  265. if-else-endif (else optional) can enclose code for decision 
  266. making.  Logical objects may respond.  For example,
  267.  
  268.     3 6 < if "no" else "yes" endif
  269.  
  270. div    integer division operator.  normally, division of 2 
  271. integers using /, yields a float.  div yields an integer, discarding 
  272. the remainder.
  273.  
  274. dot    dot products of matrices
  275.  
  276. idn    given an integer, pushes the identity matrix of that size
  277.  
  278. norm    normal distribution function approximation for floats
  279.  
  280. polyfit    polynomial curve fits - see example program fit.q
  281.  
  282. rand    random number
  283.  
  284. recurse    recursively send the message currently being 
  285. executed.  faster than sending the message itself
  286.  
  287. today    the current date, as a date object
  288.  
  289. sl    shifts an integer left, also sr, slb, srb
  290.  
  291. sinv    given a variable, inverts the contents, also sneg, sto+, sto-
  292.  
  293. min    minimum of two numbers, also max
  294.  
  295. The Debugger
  296.  
  297. Quinta has a source level debugger which is activated using the 
  298. Command menu.  When the debugger is on, user defined 
  299. responses halt after every message, to allow the user to 
  300. manipulate data and monitor the program.  Once the debugger 
  301. has halted a response, variables may be examined or modified.  
  302. In fact, any Quinta operation is legal.  The message step causes a 
  303. single step.  The message go turns the debugger off.  Within a 
  304. response being debugged, halt causes a breakpoint.  If an error 
  305. occurs while in the debugger, the debugger is turned off.  The 
  306. message rstk will attempt to print a trace of the Quinta return 
  307. stack.  This will give some indication of how the program has 
  308. progressed.
  309.  
  310. Loops
  311.  
  312. Quinta supports several flavors of loops.  They fall into two 
  313. main kinds: object oriented, and structured.  Structured loops 
  314. are legal only within response definitions.  The kinds of 
  315. structured loops are: for-next, do-until, and while-repeat-end.  
  316. Below, (flag) refers to a logical object.  Their usages:
  317.  
  318. (start) (end) (localname) for (contents of loop) (localvariable) 
  319. next
  320.  
  321.     1 5 "q" for q print 'q' next
  322.  
  323. do (contents of loop) (flag) until
  324.  
  325.     do q 1 + 'q' sto q 5 > until
  326.  
  327. while (flag) repeat (contents of loop) end
  328.  
  329.     while q 5 < repeat q 1 + 'q' sto end
  330.  
  331. For the for-next loop, the local variable is a loop index.  It is 
  332. created when the for loop begins.  It's value is not destroyed 
  333. when the loop exits.
  334.  
  335. Object oriented loops, as I call them, are much nicer when 
  336. considered in a purely object oriented programming 
  337. framework.  There are currently two messages which work 
  338. with object oriented loops: dountil and whiledo.  Each of these 
  339. expects two block objects to be on the stack.  The block object in 
  340. level 2 is the body of the loop; ie. the code to be executed on each 
  341. pass.  The block object in level 1 may contain any messages 
  342. desired, but it must leave a logical object on the stack.  This is 
  343. used for the termination condition of the loop.  The dountil loop 
  344. checks for termination AFTER each pass.  The whiledo loops 
  345. checks for termination BEFORE each pass.  Therefore, the 
  346. dountil loop is guaranteed to executed its body at least once 
  347. while the whiledo loop is not.  An example:
  348.  
  349.     [ 1 "x" local [ 'x' ++ x print ] [ x 10 > ] dountil ]
  350.     send
  351.  
  352. This loop prints the numbers 2 through 11.
  353.  
  354. Conditionals
  355.  
  356. The best way to handle conditionals in Quinta is using the 
  357. message cond.  Cond is of order 3 and requires:
  358.     3:    a block of code for the ELSE case
  359.     2:    a block of code for the THEN case
  360.     1:    a logical object
  361.  
  362. If the logical is true, then the block in level 2 is sent.  Otherwise, 
  363. the block in level 3 is sent.  Example,
  364.  
  365. [ "Nope!" ] [ "OK" ] true cond
  366.  
  367. Data Constants in Quinta Code
  368.  
  369. Data constants are textual representations of objects which are 
  370. recognized by the interpreter and automatically converted and 
  371. pushed onto the stack.  Currently, only integers, floats, strings, 
  372. and blocks are recognized by the interpreter.  The only way to 
  373. construct other objects is to use messages defined for that 
  374. purpose.  For example, pushing n objects onto the stack and then 
  375. pushing n as an integer allows one to use the message >str to 
  376. build a list with those n objects.  Also, the message new is 
  377. defined for the class class.  It creates a new object for the given 
  378. class.  The value of this new object is, in general, undefined.  A 
  379. builder response may be defined for a class to initialize the value 
  380. of a newly created instance, using setbld.  Builder responses are 
  381. analgous to C++ constructor functions.  Builder responses to 
  382. NOT automatically execute the builder response of the parent 
  383. class.  Executing the builder response for any class can be 
  384. accomplished by using the message bld sent to the desired class 
  385. object.  See sieve.q for examples of builder responses.  
  386. Predefined Quinta classes do not currently have any builder 
  387. responses.
  388.  
  389. Multiple Inheritance
  390.  
  391. Quinta supports multiple inheritance.  However, the feature has 
  392. not been tested extensively.  All subclasses are created with a 
  393. principle parent class.  After that, two classes may establish a 
  394. parent - child relationship using the message inherit.  For 
  395. example, to make integer a subclass of logical (thus allowing all 
  396. integers to act as logical values, similar to C):
  397.  
  398.     logical integer inherit
  399.  
  400. Note that this feature is best used with your own subclasses.  
  401. Most Quinta predefined classes should not inherit messages in 
  402. their current implementation.  For example, the following is an 
  403. invitation for a system crash:
  404.  
  405.     string integer inherit ; Don't do this
  406.  
  407. Interacting with the Interpreter
  408.  
  409. After each press of enter, Quinta prints the current status of the 
  410. stack, including the depth and the objects in the first 4 levels.  
  411. This is reconfigurable; see below.  Quinta also will report a 
  412. number of error messages.  For example, consider the 
  413. following message:
  414.  
  415.     wrong
  416.  
  417. Quinta will respond by saying that the message wrong is not in 
  418. the dictionary.  Messages that occur within responses and user 
  419. programs are handled similarly.  Quinta always attempts to 
  420. diagnose the location of the error and report this to the user.
  421.  
  422. The Window menu may be used to switch back and forth 
  423. between edit windows in the Quinta interpreter.
  424.  
  425. Dictionary Memory Usage
  426.  
  427. The Quinta dictionary uses a good deal of memory.  The 
  428. algorithms I have used for the interpreter are designed with 
  429. priority given to speed of execution.  The consequence of this 
  430. decision was ENORMOUS memory usage.  For each message, 
  431. this memory usage is exponentially related to the order of the 
  432. message.  For this reason, Quinta does not allow messages of 
  433. order greater than 3.  A number of methods were used to keep 
  434. memory usage minimal, and as a result, some insertions into the 
  435. dictionary can be rather slow.  For example, the creation of an 
  436. order 3 message defined for three generic objects on the stack 
  437. would require a great deal of memory and work.  The reason is, 
  438. this message would have to be inherited to all of the descendants 
  439. of class generic in all combinations of 3.  However, a message of 
  440. order 3 defined for 3 logical objects would be more benign: 
  441. logical has no subclasses (in the core version).  Multiple 
  442. inheritance can cause a delay as well.  However, all algorithms 
  443. have been designed to be as fast as possible at runtime.  Extra 
  444. work is done when manipulating the dictionary specifically so 
  445. that the actual accesses to the dictionary will be more rapid.
  446.  
  447. Because of the enormous memory usage involved with multiple 
  448. order messages, sometimes it is best to keep the order of the 
  449. message low and allow the possibility of stack underflow.  For 
  450. example, the message put is predefined in the interpreter and is 
  451. used for modifying lists and matrices.  For a list, it should 
  452. require:
  453.     3:    an object to be placed into the list
  454.     2:    the list itself
  455.     1:    the index into the list where the object should be put
  456. However, this would require a response definition for class 
  457. integer:list:generic.  This requires well over 100 kilobytes of 
  458. storage for the response table of the put message!  Instead, I 
  459. have defined put to be of class 2.  The implementation blindly 
  460. assumes that there is an object in level 3.  This dramatically 
  461. reduces memory requirements.
  462.  
  463. The message subclass and respond are even better examples.  To 
  464. be correctly implemented, they should be of order 4.  Order 4 
  465. messages require an unbelievable amount of storage.
  466.  
  467. For any message, the amount of storage (in bytes) which it 
  468. requires is printed when its message object is printed using the 
  469. message print.  The message pdict will, of course, include this 
  470. info with every message it prints.
  471.  
  472. Interpreter Configuration
  473.  
  474. The interpreter has a number of limitations built into itself.  
  475. These limitations are as follows:
  476.  
  477.     1    Maximum length of a message or class name    
  478.     32
  479.     2    # of levels of stack to print            
  480.     4
  481.     3    Maximum members for user classes        
  482.     128
  483.     4    Maximum total number of messages        
  484.     1023
  485.     5    Maximum total number of classes        
  486.     48
  487.     6    Maximum number of subclasses per class    
  488.     64
  489.     7    Maximum main stack depth            
  490.     1000
  491.     8    Maximum number of locals at one time    
  492.     64
  493.     9    Maximum nesting of Quinta responses    
  494.     64
  495.     10    Maximum number of messages in a response
  496.     128
  497.     11    First Quinta message to be sent            
  498.     Qmain
  499.  
  500. All of these parameters are configurable from within Quinta.  
  501. By sending the message getconfig, a list of these parameters will 
  502. be pushed onto the stack.  The user may modify this list and then 
  503. send the message setconfig.  Changes will take effect next time 
  504. the interpreter application is opened.  Be very careful setting 
  505. these parameters !  In general, do not change the first Quinta 
  506. message unless you are sure you know what you are doing.
  507.  
  508. The length of the configuration list will probably be changed in 
  509. future versions of Quinta.  Currently the list contains 11 items, 
  510. and all future versions will leave those 11 items intact.  In other 
  511. words, item 7 will always be the main stack depth.  However, I 
  512. may add an item 12, 13, etc.
  513.  
  514. QCore
  515.  
  516. Upon opening the Quinta application, the dictionary is built and 
  517. then the interpreter looks for a file called Qcore.  If this file is 
  518. found, all of the Quinta source code inside it is executed.  This 
  519. can be a very powerful way to extend the interpreter in Quinta.  
  520. Oft used messages and classes may be installed into this file and 
  521. they will be available each time Quinta is used.  Personalized 
  522. messages may be installed.
  523.  
  524. Origins
  525.  
  526. The design of Quinta has been influenced by a number of 
  527. different sources.  It was originally designed to be an object 
  528. oriented version of Forth.  I have also included similarities to 
  529. Lisp, Smalltalk and the HP-28 calculator programming 
  530. language.  However, although Quinta has received some 
  531. inspiration from the excellent Hewlett Packard 28 calculator 
  532. line, it is not intended to be an emulator for those products (or 
  533. any other products/languages).
  534.  
  535. Credits
  536.  
  537. The user interface code for the Quinta interpreter is built on 
  538. Transkel and TransEdit, by Paul Dubois.  Although I have made 
  539. some modifications to his code, the basic structure of his work 
  540. remains.
  541.  
  542.