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.190.104 with SMTP id gp8mr5771075pbc.4.1341071512351; Sat, 30 Jun 2012 08:51:52 -0700 (PDT) Path: l9ni2750pbj.0!nntp.google.com!news1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!.POSTED!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: What would you like in Ada202X? Date: Sat, 30 Jun 2012 11:51:51 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <3637793.35.1335340026327.JavaMail.geo-discussion-forums@ynfi5> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 X-Trace: pcls6.std.com 1341071512 5115 192.74.137.71 (30 Jun 2012 15:51:52 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sat, 30 Jun 2012 15:51:52 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:gG0wo1LP3Y0NPBwM2RFXKI8Asgk= Content-Type: text/plain; charset=us-ascii Date: 2012-06-30T11:51:51-04:00 List-Id: 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) or -- (bad choice! maybe ++) > for series connection. > > For example, the definition of // would clearly be different for > resistance and capacitance, which we can assume to be distinct types of > complex number. > > The last language I used that allowed this, (Lingo, on the Linn Rekursiv) > restricted the characters used to build such an operator to a suitable > set, chosen to avoid clashes with the inherent language syntax, so no > { or } for example. > > One obvious problem with an extensible set of operators, in an operator > precedence grammar, is assigning the precedence level of new operators. Yes, you would need some way to deal with precedence, but I think it is a mistake to think of precedence in terms of "levels". In Ada "*" has higher precedence than "+", and "+" the same precedence as "-". 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". > Lingo resolved that dilemma by assigning the same precedence to all > operators! You explicitly wrote a + (b*c) - d to achieve the usual > precedence. Simple, clean, and effective, but entirely inappropriate for > Ada! 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. > 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. 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 >=. - Bob