home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:12474 comp.programming:2367
- Newsgroups: comp.lang.c,comp.programming
- Path: sparky!uunet!nntp1.radiomail.net!fernwood!metrop!robert
- From: robert@metropolis.com (Robert Munyer)
- Subject: Re: A LITTLE BRAINTEASER...
- Message-ID: <Bt6BK2.HrC@metropolis.com>
- Organization: Metropolis Software, Inc.
- References: <1992Aug14.123054.4872@fwi.uva.nl> <9222810.19441@mulga.cs.mu.OZ.AU> <O1ywr*J00@ro-chp.UUCP>
- Date: Tue, 18 Aug 1992 09:55:14 GMT
- Lines: 42
-
- In article <O1ywr*J00@ro-chp.UUCP> chopps@ro-chp.UUCP (Chris Hopps) writes:
-
- > I guess I don't understand what it is you exactly want. Should the program
- > be portable? What _is_ a data structure to you? To me recursing and
- > saving values on the stack is a data structure, albeit an ugly and not very
- > usefull one in this case, it still represents a logical structuring of data.
-
- I think what he wanted was to use only data structures that the compiler
- creates AUTOMATICALLY, without being asked, in order to implement the
- semantics of the language. And "ugly" is in the eye of the beholder.
-
- The problem is pretty easy to solve in any language that supports recursion
- within multiple threads. C does not support this, but the Unix environment
- does. Compile these two programs, and then pipe either one into the other:
-
- -------------------- a.c --------------------
- #include <stdio.h>
- f ()
- { int c = getchar ();
- return c == EOF ? 0 :
- f () || c != '\n' ? (putchar (c), 1) : 1;
- }
- main () { f (); putchar ('\n'); }
- -------------------- b.c --------------------
- #include <stdio.h>
- f ()
- { int c = getchar ();
- return c == EOF ? 0 :
- c == '\n' ? 1 :
- f () ? (putchar (c), 1) :
- (putchar (c), 0);
- }
- main () { while (f ()) putchar ('\n'); }
- ---------------------------------------------
-
- At the shell prompt, you can type either "a | b" or "b | a". Note that each
- process has one recursive function, with one local variable and no arguments.
-
- ______________________________________________________________________
- Robert Munyer | "I may be synthetic, but I'm not stupid."
- robert@metropolis.com | -- Bishop, _Aliens_
-
-