home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / rexx / factor.cmd < prev    next >
OS/2 REXX Batch file  |  1999-05-11  |  1KB  |  29 lines

  1. /******************************************************************************/
  2. /*  factor                   Object REXX Samples                              */
  3. /*                                                                            */
  4. /*  A factorial program.                                                      */
  5. /*                                                                            */
  6. /*  This program demonstrates a way to define a factorial class using the     */
  7. /*  subclass method and the .methods environment symbol.                      */
  8. /******************************************************************************/
  9. say "Enter a number"
  10. pull number
  11. If \datatype(number, '9') then do
  12.   Say 'Invalid whole number' number
  13.   Exit
  14. end
  15.  
  16. factorial_class = .string~subclass("Sample")~~define('FACTORIAL', .methods['FACTORIAL'])
  17. say number 'factorial is' factorial_class~new(number)~factorial
  18.  
  19. Exit
  20.  
  21. /* Define the factorial method.  Note that this method contains a recursive   */
  22. /* call to itself.                                                            */
  23. ::method factorial 
  24.   If self <= 1 then return 1
  25.   else do
  26.     t = self~class~new(self - 1)
  27.     Return self * (t~factorial)
  28.   end
  29.