Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!think.com!hsdndev!cmcl2!arizona!gudeman From: gudeman@cs.arizona.edu (David Gudeman) Newsgroups: comp.lang.misc Subject: Re: Runtime Polymorphism -- To Have and Have Not (Par Message-ID: <591@optima.cs.arizona.edu> Date: 9 Mar 91 23:57:40 GMT Sender: news@cs.arizona.edu Lines: 66 In article <1991Mar5.214727.8630@hawk.cs.ukans.edu> Bill Kinnersley writes: ]... ]Runtime polymorphism is one of the worst features of Smalltalk and Icon. ] ]In Smalltalk, people miss the typing so much that they name all of their ]variables "anObject" or aNumber" to make up for it, thus forgoing the ]opportunity to use meaningful names. I'd guess that this is actually a result of people blindly following poor examples from books. It isn't seen in other languages with dynamic typing. ]And in Icon, the absence of typing has led to an incredible proliferation ]of operators. That's completely wrong. The proliferation of operators in Icon is a result of two things: (1) there are a lot of powerful built-in types, and (2) the designers liked operator syntax for these things better than function syntax. It has absolutely nothing to do with dynamic typing. ] Since the variables are polymorphic, the operators must all ]be monomorphic. That too is wrong. There are many polymorphic operators in Icon. All the arithmetic operators are polymorphic the same way they are in C. I can off-hand think of three operators that operate on list, strings and tables: element generation, random element choice, and subscripting. The set operators work for sets as well as csets, And many of the built-in functions are polymorphic also. ] It's entirely the operator's responsibility to decide ]whether to compare two variables as numbers (=) as strings (==) or as ]values (===). These are all distinct operations that would generally be just as useful in a statically typed language except for the operators that express things that can't be expressed in statically typed langauges. "=": do numerical comparison, but it is an error if one of the arguments is not a number or convertiable to one. "==": do lexical comparison, but it is an error if one of the arguments is not a string or convertible to one. These two operators are distinct in most languages that have string comparison. "===" expresses something that you can't even say in a statically typed language -- compare the values numerically, lexically, or by some other criteria, depending on the dynamic type of the expression. ] Thus we get monstrous operations like >>=:= and --:= ]and |||:= and ~===:= that no one can remember. I've never had trouble. All you need to do is remember some simple rules. These examples in particular are silly since they are compound assignment operators that are easy to remember if you can remember the base operator. For all operators "@", "x @:= y" is equivalent to "x := x @ y" except that x only gets evaluated once: x >>= y return y if x is lexically greater than y, otherwise fail. x >>=:= y x gets y if x is lexically greater than y. x -- y return the set difference of x and y. x --:= y x gets the the set difference of x and y. x ||| y return the list concatenatio of x and y. x |||:= y x gets the list concatenatio of x and y. -- David Gudeman gudeman@cs.arizona.edu noao!arizona!gudeman