home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / os2 / programm / 7999 < prev    next >
Encoding:
Internet Message Format  |  1993-01-25  |  1.8 KB

  1. Path: sparky!uunet!vnet.ibm.com
  2. From: francis@vnet.ibm.com (Tim Francis)
  3. Message-ID: <19930125.082123.510@almaden.ibm.com>
  4. Date: Mon, 25 Jan 93 09:56:59 EST
  5. Subject: Rexx question
  6. Newsgroups: comp.os.os2.programmer
  7. References: <1993Jan24.181958.6740@athena.mit.edu>
  8. Reply-To: francis@vnet.ibm.com
  9. Organization: IBM Canada Lab, WorkFrame/2 development
  10. Disclaimer: This posting represents the poster's views, not those of IBM
  11. Lines: 55
  12.  
  13. In article <1993Jan24.181958.6740@athena.mit.edu>,
  14. jawetzel@athena.mit.edu (The Rottweiler) writes:
  15. >
  16. >I'm doing a little Rexx programming and came upon the following:
  17. >
  18. >--------------------------------------
  19. >/* */
  20. >
  21. >line = "prpipgphptp"
  22. >
  23. >do while((n = pos("p", line)) \= 0)
  24. > line = overlay(" ", line, n)
  25. >end
  26. >
  27. >say line
  28. >
  29. >line = "prpipgphptp"
  30. >
  31. >n = pos("p", line)
  32. >do while(n \= 0)
  33. > line = overlay(" ", line, n)
  34. > n = pos("p", line)
  35. >end
  36. >
  37. >say line
  38. >
  39. >-------------------------------
  40. >
  41. >The output when this program is run is the following:
  42. >
  43. >prpipgphptp
  44. > r i g h t
  45. >
  46. >My question is simple - is this a bug or a limitation of the
  47. >Rexx programming language?  Or is it that I'm doing something
  48. >wrong?
  49. >
  50. >                        Jake
  51.  
  52. The problem is that REXX doesn't support assignment within conditional
  53. expressions.  This can be seen fairly easily by running your program
  54. with TRACE ?I  (I = show intermediate values)
  55.  
  56.   *-*   Do While ( ( n = pos('p', line) ) <> 0 );  My Comments
  57.   >L>       "N"                                    n = 'N'
  58.   >L>       "p"
  59.   >V>       "prpipgphptp"
  60.   >F>       "1"                                    pos('p',line) = 1
  61.   >O>       "0"                                    (N = 1) = 0
  62.   >L>       "0"
  63.   >O>       "0"                                    (0 <> 0) = 0
  64.   >>>       "0"
  65.  
  66. The key is the part (N=1), which is evaluated as a condition, whose
  67. result is either 0 (FALSE) or 1 (TRUE).   -tim
  68.