I suspect you've seen this kind of thing before, but it's the first time a student has come up with it. After talking about lists, stacks, and queues, I gave as part of an assignment the problem of writing a file out with the lines displayed last-to-first. One student wrote:
Oh well.procedure main() if line := read() then { main() write(line) } end
This can of course be written more compactly:
By the way, didn't something like this come up before?procedure main() write(read(), main()) return end
How about a more Icon-like solution:
Steve Wampler:procedure main() write(read(), main() | "") end
Compare these two programs:
(Theprocedure main() (write(read(), main())) return end procedure main() (write(read()), main()) return endreturn
s aren't really needed, but one of them would have to be modified slightly to work properly -- destroying the similarity.)
He comments "The nice thing about it is that it can 'sleep' for fractions of a second --# sleep (restlessly) for n seconds procedure sleep(n) local start start := &time while &time < start + n * 1000 return end
sleep(0.5)
sleeps for half a second". Note
that this depends on adequate clock resolution.