Path: utzoo!mnetor!uunet!husc6!cca!g-rh From: g-rh@cca.CCA.COM (Richard Harter) Newsgroups: comp.lang.c Subject: Re: The D Programming Language: switches Message-ID: <25930@cca.CCA.COM> Date: 24 Mar 88 03:03:37 GMT References: <222965b9@ralf.home> <941@micomvax.UUCP> <3074@haddock.ISC.COM> <25835@cca.CCA.COM> <298@aiva.ed.ac.uk> Reply-To: g-rh@CCA.CCA.COM.UUCP (Richard Harter) Organization: Computer Corp. of America, Cambridge, MA Lines: 44 Summary: Last word on switches, I promise. >No, *practically* the switch construct is more powerful because it selects >in one step. *Theoretically* switch can compile into an if-then-else chain >(and often will, if the case values are widely separated), and an >if-then-else chain can be analysed to discover whether it can be compiled >into a jump table. >The theoretical power of a language is [determined by] the set of >algorithms it can implement. Its efficiency in executing these algorithms >depends on its implementation, though it's obviously easier to produce >efficient implementations of some languages than others. This is a useless definition of the power of a language. Almost all languages of any interest can implement a turing machine emulation in which all effective algorithms can be implemented. You can even do it if the only flow-control construct is the 'while' loop. You can pick any measure of strength of constructs that you like -- however the usual measure is space and time efficiency. For example, it can be shown, that if language A provides the if-then-else and the while-loop and language B provides the if-then-else and the goto as their sole flow control constructs, then there are programs of length N and execution time O(N) in language B such that any equivalent program in language A requires either O(N logN) execution time or O(n *exp(N)) space, or some combination thereof. By this criteria the goto is more powerful than the while-loop. The hierarchy of strengths runs while-loop forever-loop-with-multiple-escapes goto procedure-invocation-and-return computed-goto/switch The switch construct is equivalent in power to the computed goto. This measure of power is unambiguous. One can also speak of the expressiveness of a construct, in the sense of what can be easily done in the language. Although this is probably the most useful criteria (and I suspect what you really) meant it is obviously vague and subjective. -- In the fields of Hell where the grass grows high Are the graves of dreams allowed to die. Richard Harter, SMDS Inc.