home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / programm / 2370 < prev    next >
Encoding:
Internet Message Format  |  1992-08-18  |  2.5 KB

  1. Path: sparky!uunet!mcsun!uknet!yorkohm!minster!dan
  2. From: dan@minster.york.ac.uk
  3. Newsgroups: comp.programming
  4. Subject: Re: A LITTLE BRAIN... in parallel
  5. Message-ID: <714154949.3534@minster.york.ac.uk>
  6. Date: 18 Aug 92 16:22:29 GMT
  7. Organization: Department of Computer Science, University of York, England
  8. Lines: 59
  9.  
  10.  
  11. Dear Netters,
  12.  
  13. Here is my solution to the little problem someone posted a while ago.
  14. I am not too happy to see that more and more people are getting stuck
  15. into the arcane ways of C. comp.lang.c is a good place for that and I
  16. though that something a little different might be of interest.
  17. (... I am being a hypocrite; I spend my days hacking C as well)
  18.  
  19. The following proglet (if I am allowed to call it so) reads lines and
  20. prints them in the reverse, while the words stay properly orientated;
  21. so FOO BAR BAZ becomes BAZ BAR FOO. As it stands the program works for a
  22. single line of text. It is written in Hoare's CSP language and my
  23. colleagues and I believe that it works. The version that worked for a
  24. single word only was tested in Ada and it worked properly. 
  25.  
  26. The following code DOESN'T use a stack or a list or env or anything like
  27. that. It uses a PROCESS per character. Each char is read by a single
  28. process and printed by that same process. BAZ BAR FOO would need 12
  29. separate processes.
  30.  
  31. If CSP was executable, running META would do the trick.
  32.  
  33. END = p? -> d! -> SKIP
  34. P   = input?ch ->
  35.     IF ch == <CR>
  36.             (f:META//(f.nw? -> p! -> d? -> output!ch -> SKIP))
  37.      ELSIF ch == <SPACE>
  38.             p! -> d? -> output!ch -> nw! -> SKIP
  39.       ELSE
  40.             (n:P //(n.p? -> p! -> d? -> output!ch -> n.d! -> SKIP))
  41. META = END || P
  42.  
  43. where <CR> is ASCII 0x0d and <SPACE> is ASCII 0x20
  44. (note [pd][!?] implies that a communication channel is engaged, but
  45. that we are NOT interested in the actual messages that will be passed.
  46. The channels are only used for synchronization.)
  47.  
  48. Beware of the above code...
  49. I didn't even proved it correct, but I suppose I could if needed.
  50.  
  51. p.s. as I said I am NOT sure that it works, but I give it a very high
  52. probability of correctness. :)
  53.  
  54. p.p.s Just an afterthought if you want it to work for more then one line
  55. define another process, say TEXT as follows:
  56.  
  57.     TEXT = META -> TEXT
  58.  
  59. p.p.p.s I will try to convince my colleague to translate all of the
  60. above into Ada. If he does, I'll post it.
  61.  
  62.  
  63.  
  64.                        Daniel Kustrin
  65.               Distributed Ada Debugging Group
  66.                      University of York
  67.                        York,  England
  68.                    dan@minster.york.ac.uk
  69.