Path: utzoo!attcan!uunet!husc6!mailrus!purdue!decwrl!hplabs!ucbvax!decvax.DEC.COM!binder From: binder@decvax.DEC.COM (A complicated and secret quotidian existence) Newsgroups: comp.os.cpm Subject: COMPAS/Turbo/recursion program Message-ID: <8807021208.AA10306@caliph.dec.com> Date: 2 Jul 88 12:08:02 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 46 PROGRAM Tryit (INPUT, OUTPUT); { Recursion program discussed earlier in INFO-CPM Digest - implemented for Turbo Pascal. The program as originally submitted will not work in *any* correctly implemented Pascal, because it allows only one byte for the variable "nextchar". Declaring the variable inside a procedure doesn't mean that the variable will have a new space created for it on every call to the procedure; it only means that the variable is not global. Furthermore, it is necessary to make your Pascal's I/O routines take characters as they are typed, instead of waiting for a . Turbo does this by using a file read from predeclared file "Kbd". Then it is necessary to write the character because file reads do not echo. } {$A-} { The above compiler directive enables recursion in the CP/M-80 incar- nation of Turbo. } VAR index: INTEGER; nextchar: ARRAY [1..100] OF CHAR; { Allow 100 chars } PROCEDURE Readwrite; BEGIN index := index+1; READ (Kbd, nextchar [index]); WRITE (nextchar [index]); IF (nextchar [index] <> ' ') THEN Readwrite; WRITE (nextchar [index]); index := index-1 END; BEGIN index := 0; WRITE ('Enter a word, end with a space: '); Readwrite END.