From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,81bb2ce65a3240c3 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.228.227 with SMTP id sl3mr5967041pbc.5.1341077836246; Sat, 30 Jun 2012 10:37:16 -0700 (PDT) Path: l9ni3024pbj.0!nntp.google.com!news1.google.com!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Brian Drummond Newsgroups: comp.lang.ada Subject: Re: What would you like in Ada202X? Date: Sat, 30 Jun 2012 17:37:15 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <3637793.35.1335340026327.JavaMail.geo-discussion-forums@ynfi5> Mime-Version: 1.0 Injection-Date: Sat, 30 Jun 2012 17:37:15 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="DkTdSjxOCm6DqG+Uf7eArg"; logging-data="27462"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19soteOzsSG0EduLTwqul8hnkmLaeBMl8k=" User-Agent: Pan/0.135 (Tomorrow I'll Wake Up and Scald Myself with Tea; GIT 30dc37b master) Cancel-Lock: sha1:wB7mjGuc5zskXcVejURA2YJhTuQ= Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Date: 2012-06-30T17:37:15+00:00 List-Id: On Sat, 30 Jun 2012 11:51:51 -0400, Robert A Duff wrote: > Brian Drummond writes: > >> We can overload existing operators (+,-,etc) ... >> But we can't define new ones, e.g. // to denote the value of electronic >> components connected in a parallel circuit) >> One obvious problem with an extensible set of operators, in an operator >> precedence grammar, is assigning the precedence level of new operators. > ... But > "and" and "or" have neither higher, lower, nor equal precedence. That > last possibility is important to allow, and in fact should be the > default -- perhaps call it "unrelated precedence". ... and that may help here. >> Lingo resolved that dilemma by assigning the same precedence to all >> operators! > And some other languages, such as Smalltalk. Yes, it's simple. > But it's a bad idea, because it violates maths conventions. > I could tolerate a+b*c being illegal, but I can't tolerate it being > legal and meaning (a+b)*c. While agreeing it's a bad idea, I think it's a fair compromise IF it's clearly understood from the beginning, that that is what the language does, in order to allow major simplification in other aspects; in Lingo's case (and I believe Smalltalk's), sidestepping the precedence problem. Other bad ideas abound in computing; some languages violate the conventions by making assignment an operator... I am happy to see neither of these ideas in Ada! >> Given that ways can be found to assign precedence to new operators, why >> are extensible operators not found in more languages that allow >> overloading? > > Perhaps because dealing with precedence adds complexity. > What happens if package P1 declares that "//" has higher precedence than > "\\\", and P2 declares the opposite, > and you say "with P1, P2;"? The obvious answer is that they then have > unrelated precedence within the scope of that "with". But it definitely > adds complexity. Conflicting precedences are a problem I hadn't considered. There seems to be some parallel with the diamond problem in multiple inheritance. If P1."//" and P2."//" apply to different types, does it really matter that they have different precedences, unless the base type is the same? Possibly yes, from the perspective that the expression parser now has to take the operand types as well as the operator symbol into consideration. "+" by contrast, has the same precedence for integer, real, string, and foobar types (whether or not that precedence is appropriate for the semantics of e.g. string processing, it's what you get). Perhaps a simple rule - e.g. all user-defined operators have unrelated precedence to ALL other operators - could cut through the complexity. But, like the simple rules in Modula-2, that may prove inconveniently restrictive. > Anyway, I don't think I want programs to look like maths textbooks. > Programming isn't the same as maths. I kind of like reading words, as > in "Union(Intersection(This_Set, That_Set), The_Other);" rather than the > usual maths symbols. On the other hand, I wish ASCII had proper symbols > for <= and >=. Agree that it could be over-used. But in some domains it would be useful. After all, I doubt you would want to see too much "Add(A,Multiply(B,C))"... - Brian.