home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / m / msh_ut11.zip / MYDEFS.ZIP / DEMO2.MSH < prev    next >
Text File  |  1992-03-26  |  4KB  |  110 lines

  1. | file DEMO2.MSH   
  2. hide_all
  3. ("Welcome to Mi-Shell"
  4.     Copyright(C) PMC/OPENetwork 1990     
  5.  
  6.  "
  7. message)message1!
  8. message1
  9. ("Demo2" swap message)m!
  10. "  This is an advanced tutorial where we'll explore the
  11.   language and the debugger. The Mi-Shell script language
  12.   is a stack language, like Postcript and FORTH. If 
  13.   you are not familiar with either, this tutorial should
  14.   help as an introduction." m
  15. "  When the debugger window comes up, you will see 2 parts:
  16.  the top line reflects the source code submitted, together
  17.  with a caret pointing to the token being interpreted.
  18.  below the dotted line, you will see the contents of the stack.
  19. " m
  20. "  First, we will push 2 on the stack, push another 2 on the stack,
  21.   then push a + on the stack. The + will add 2+2 and return a 4.
  22.   The whole code will be
  23.               2  2  +  3  +  drop
  24.   To step thru in the debugger, push s (for step) repeatedly and 
  25.   watch the stack.  " m
  26. |
  27. (true debug!2 2 + 3 + drop false debug!)#
  28. "  You may have noticed that after the computation, we issued
  29.   a drop, which dropped the result from the stack.
  30.   Then we had the code   
  31.              false debug !  
  32.   This is how we turn off the debug mode: we push false on the
  33.   stack, then push the system variable debug, then push !, 
  34.   the assignment function. This causes the value false to be 
  35.   assigned to debug. In most languages, this would be written
  36.   as         debug = false
  37.   We did that, so that invoking this message would
  38.   be immediate, rather than a slow step thru process. " m
  39. "  Let us make an even simpler assignment, 
  40.   similar to the usual XYZ = 23
  41.   This is done with the statement 23 XYZ ! 
  42.   There is not much to see in the debugger, but we'll
  43.   follow it anyway." m
  44. (true debug!23 "XYZ" ! false debug!)#
  45. "  Now let's watch the concatenation of two strings, 
  46.   which is done with the & operator." m 
  47. (true debug!"hello, " "world" & drop false debug!)#
  48. " A boolean variable is one whose values are true or false.
  49.  In the Mi-Shell script, every value is a string, and a value
  50.  of \"false\" or \"\" (an empty string) are understood as false.
  51.  Every other string is considered true." m
  52. " Let us examine the ifelse statement.
  53.  First we look at the syntax:
  54.  
  55.  Boolean (action1) (action2) ifelse
  56.  
  57.  will run action2 if Boolean is false (or the empty string),
  58.      and  action1 otherwise. 
  59.  
  60.  Now, we will look at an example:
  61.   XYZ (message1) (quit) ifelse! 
  62.  will execute message1
  63.  because XYZ is not false  (we set to 23 a few windows ago). " m
  64. (true debug!"XYZ" (message1) (quit) ifelse! false debug!)#
  65.  
  66. "  A more interesting example is the definition of 
  67.  debug_toggle, a standard definition you can find
  68.  in STDDEFS.MSH.
  69.  
  70.  (debug(false debug!)(true debug!)ifelse)debug_toggle!
  71.  
  72.  This may look formidable, but is actually rather simple.
  73.  The whole thing is a piece of code (the outer parentheses),
  74.  defining debug_toggle.
  75.  Inside, we see 4 items:
  76.  debug          the system variable which is either true or false,
  77.  (false debug!) action1, which turns debug off,
  78.  (true  debug!) action2, which turns debug on,
  79.  ifelse         which causes action1 or action2 to occur, 
  80.                 based on the value of debug.
  81.   If you can follow this example, you have gone a long 
  82.   way towards understanding stack languages in general,
  83.   and Mi-Shell in particular." m
  84. " Let us now look at a while loop.
  85.   ((stack_size 0 > ) (drop) while)clean_stack!
  86.  This is a definition for clean_stack which can 
  87.  be found in STDDEFS.MSH. In english, it says 
  88.  while the stack size (a primitive) is positive,
  89.  drop the top from the stack. It is clear that the 
  90.  syntax is:
  91.  (boolean) (action) while
  92.  and means while boolean is true, perform action.
  93.  Let us see it work. the code will be
  94.  3 2 clean_stack" m
  95. (true debug!3 2 clean_stack false debug!)#
  96. " Now that you are almost done with this advanced tutorial, 
  97.  let us take a look at the Mi-Shell script that it 
  98.  is written in. We'll use pager, Mi-Shell's built-in 
  99.  viewer. The Up, Down, PgUp and PgDwn keys will be
  100.  active, and you can use F1 for help and ESC to quit. " m
  101. prog_dir "DEMO2.MSH"& pager
  102. " Well, so long now. . . You have graduated!
  103.  The next logical steps are to study the primitives
  104.  in the Reference Manual, to study the standard
  105.  definitions in stddefs.msh and menu.msh, and
  106.  to start writing your own!" m
  107. hide_all
  108. |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  109.