Path: utzoo!attcan!uunet!lll-winken!ncis.llnl.gov!ncis!helios.ee.lbl.gov!pasteur!ucbvax!hplabs!hpfcdc!marc From: marc@hpfcdc.HP.COM ('Thelonious' Sabatella) Newsgroups: comp.lang.misc Subject: Re: What is B&D? (Re: Bondage and Discipline Languages) Message-ID: <5160008@hpfcdc.HP.COM> Date: 18 Jan 89 16:31:22 GMT References: <2670@ficc.uu.net> Organization: HP Ft. Collins, Co. Lines: 60 / hpfcdc:comp.lang.misc / sommar@enea.se (Erland Sommarskog) / 2:18 pm Jan 16, 1989 / > >But to throw some new wood on the fire, consider the following: Assume >you have routine you want to call but whose name you don't know until >run-time, thus you have the name in a string. Now in which langauges >can you easily do this? Interpreting langauges like Lisp and Basic, >support this I guess. But compiled langauges? -- BASIC wouldn't necessarily support it (remember, many BASIC's don't have named routines; many of those that do may require static expressions for CALL targets). Lisp certainly does, and quite naturally. For compiled langauges, you have essentially described the "case" statement. I know, it's not the same thing, but considering that in a statically compiled language like C, Pascal, or Ada, the range of callable functions is completely determined at compile time (and hence at coding time, if you plan things well), you can get the same effect. C and Ada will also let you have a mapping (say, a hash table) from strings to functions (addresses in C) and let you call a function indirectly in that manner, which is more in keeping with the spirit of the request, but still requires advance planning by the programmer. Actually polymorphic languages (such as most OO languages) behave this way in principle, even if they don't extend the ability to the programmer. Forth, which is a threaded-interpretive language, meaning it is "kind of" compiled (like "kind of pregnant :-), can be tricked into giving the same behavior as Lisp (i.e., completely arbitrary routines that the programmer never in a million years would have imagined would be chosen dynamically can be executed given a string and a definition), but it is more of a "hack" than a natural technique as in Lisp. But it would be possible to encapsulate the hack into a single word which would give the same functionality as the Lisp 'eval'. So, in the context of B&D, what does this say? For one, thing, the 'discipline' enforced by C, Pascal, Ada, et al is that the programmer must anticipate what the possible values are for the string, and handle each case individually. This doesn't prevent you from doing what you want to do, as in the degenerate case the range is every routine in the program plus all library routines made visible as a result of the link, but it does prevent you from doing it in a manner which would not require you to explicitly specify this range, and an explicit mapping from the domain of strings into this range. Standard Pascal is more limited than C or Ada in this regard. Since none of these language let you create new routines dynamically (another 'discipline'), this is sufficient. In Forth, it is difficult, but by no means impossible, to extend the language dynamically, and it is correspondingly difficult to execute a routine given only its dictionary name. In Lisp, both are trivial. So, IN THIS CONTEXT, I would rate these language as follows: [ most B&D ] Pascal, C, Ada, Forth, Lisp [ most B&D ] Any polymorphic/OO language which extended its built in collision resolution mechanism to the programmer would probably fit in either to the left or right of Forth, depending on how natural the construct was. Also, for this purpose, Fortran and Pascal are essentially equivalent. -------------- Marc Sabatella HP Colorado Language Lab marc%hpfcrt@hplabs.hp.com