home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / svalues.seq < prev    next >
Text File  |  1988-12-01  |  2KB  |  48 lines

  1. \ SVALUES.SEQ           An sampel file on VALUE usage   by Tom Zimmer
  2.  
  3. comment:
  4.  
  5.   This file contains an example of how an existing program can be modified
  6. to use a VALUE word in place of a VARIABLE to enhance program readability
  7. and performance.
  8.  
  9. NOTE:   VALUEs are NOT more portable than VARIABLEs, and will NOT make
  10.         your programs easier to move to another Forth system.
  11.  
  12.   Observe the use of the word COUNTER in the following program segments.
  13.  
  14. comment;
  15.  
  16. \ program segment using a VARIABLE named COUNTER
  17.  
  18. create vowels ," aeiouAEIOU"
  19. variable counter
  20.  
  21. : vcount        ( | <string> --- )  \ get count of vowels in <string>
  22.                 counter off
  23.                 0 word  drop
  24.                 vowels count bounds
  25.                ?do      here count
  26.                         begin   i c@ scan dup
  27.                         while   1 counter +!
  28.                                 1 -1 d+
  29.                         repeat  2drop
  30.                 loop    cr ." Found " counter @ . ." vowels" ;
  31.  
  32. \ program segment using a VALUE named COUNTER
  33.  
  34. create vowels ," aeiouAEIOU"
  35. 0 value counter
  36.  
  37. : vvcount       ( | <string> --- )  \ get count of vowels in <string>
  38.                 off> counter
  39.                 0 word drop
  40.                 vowels count bounds
  41.                ?do      here count
  42.                         begin   i c@ scan dup
  43.                         while   incr> counter
  44.                                 1 -1 d+
  45.                         repeat  2drop
  46.                 loop    cr ." Found " counter . ." vowels" ;
  47.  
  48.