home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / Apps / DevTools / COWS / Docs / Test Code < prev   
Encoding:
Text File  |  1994-03-26  |  1.8 KB  |  67 lines

  1. [ sample array testing code, demonstrating how arrays work]
  2.  
  3.  
  4. (function test-array 
  5.     variable ar x y z do
  6.     
  7.     [ you set arrays by calling make-array.  This example
  8.       sets up a 3x4x5 array.  make-array returns a pointer
  9.       (a string) to the array.  You can then set a variable
  10.       to "be" that array.  As in the variable ar below. ]
  11.       
  12.     (set ar (make-array 3 4 5))
  13.     (print ar)        [ take a look on the screen ]
  14.     
  15.     [ next, let's set some values.  We'll set each cell
  16.       in the array to a string value describing its
  17.       relative position.  You do this with set-array,
  18.       passing it the array variable holding the pointer,
  19.       the value you want to set, and the coordinates.
  20.       Easy enough...]
  21.     
  22.     (for x 1 3 1
  23.         (for y 1 4 1
  24.             (for z 1 5 1
  25.                 (set-array ar (concatenate x " " y " " z) x y z))))
  26.                 
  27.     [ okay, let's see what we did. Print out values
  28.       through "array", passing it the array pointer
  29.       and coordinates of the needed value. ]        
  30.                 
  31.     (for x 1 3 1
  32.         (for y 1 4 1
  33.             (for z 1 5 1
  34.                 (print (array ar x y z)))))
  35.     
  36.     [ ...and lastly, free the array.  Remember memory leaks!
  37.       this interpreter doesn't do garbage collection, guys ]
  38.     
  39.     (free-array ar)
  40.     
  41.     )
  42.  
  43.  
  44.  
  45.  
  46.  
  47. [sample ipc code.  This consists of three functions:  cows-ipc-example, cows2-synchronous, and cows2-asynchronous.  Load cows-ipc-example on COWS.app, and the two cows2 functions on COWS2.app.  Then call cows-ipc-example and see what happens.]
  48.  
  49.  
  50. (function cows-ipc-example variable x do
  51.     
  52.     (print 
  53.         "I sent COWS2 the value 100 and got back: " 
  54.         (set x (send "COWS2" "cows2-synchronous" 100))
  55.         "Nifty, huh?"
  56.         "Now, I'm gonna just tell COWS2 to print what I got back.")
  57.     (send-out "COWS2" "cows2-asynchronous" x))
  58.     
  59. (function cows2-synchronous in do
  60.     (+ 100 in))                        [returns 100 + what it got]
  61.     
  62. (function cows2-asynchronous in do
  63.     (print "I've recieved" in "from COWS!"))
  64.     
  65.     
  66.     
  67.