Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!ukc!dcl-cs!aber-cs!athene!pcg From: pcg@cs.aber.ac.uk (Piercarlo Grandi) Newsgroups: comp.lang.lisp Subject: Re: Virtues of Lisp syntax Message-ID: Date: 15 Sep 90 19:30:24 GMT References: <33709@cup.portal.com> <1990Sep10.091911.20877@hellgate.utah.edu> <3758@goanna.cs.rmit.oz.au> Sender: pcg@aber-cs.UUCP Followup-To: comp.lang.lisp Organization: Coleg Prifysgol Cymru Lines: 77 Nntp-Posting-Host: odin In-reply-to: ok@goanna.cs.rmit.oz.au's message of 14 Sep 90 07:45:24 GMT On 12 Sep 90 02:12:38 GMT, andy@Neon.Stanford.EDU (Andy Freeman) said: andy> 1) We're not doing +,-,*,/ arithmetic, we're programming. (BTW - "+" andy> isn't really a binary operator, neither is "*"; there are andy> surprisingly few true binary, or unary, operations.) In article , pcg@cs.aber.ac.uk (Piercarlo Grandi) writes: pcg> Precisely. Agreed. Even the semantics are different. On 14 Sep 90 07:45:24 GMT, ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) said: ok> I missed this the first time it came around. I have some bad news ok> for the two of you: in floating-point arithmetic "+" _is_ a binary ok> operation. Floating-point "+" and "*" are not associative. The semantics *are* different. Didn't I write that? ok> If one Lisp compiler turns (+ X Y Z) into (plus (plus X Y) Z) and ok> another turns it into (plus X (plus Y Z)) then they are going to ok> produce _different_ results. As long as people *know* that the semantics are different, and this is the big problem, they can choose whether to code the things in either of the three ways. ok> For integer and rational arithmetic, there's no problem, Well, this is a case in point for my argument about the pitfalls; there is still a problem. Nobody constrains you to have only positive numbers as the operands to n-ary fixed point +, so that (+ -10 +32767 +10) is not well defined on a 16 bit machine, unless you do modular arithmetic throughout. As we already know but sometimes forget, arithmetic on computers follows *very* different rules from arithmetic in vanilla mathematics, and using a notation that resembles the latter can be utterly misleading, even for very competent people, without pausing for hard thought. (+ a b c d e) simply means apply repeated *computer* addition on *computer* fixed or floating point throughout. It is the *programmer's* responsibility to make sure this makes sense -- the unfamiliar syntax may make him pause, at least -- and somehow maps into vanilla mathematics not too inaccurately. ok> but anyone doing floating point calculations in Lisp has to be very ok> wary of non-binary + and * . Anyone doing floating point arithmetic on *any* machine, IEEE standard or Cray, has to be very very wary of assuming it is the same as arithmetic on reals, and yet a lot of people do (and then complain that two computers with different floating representations print utterly different results to their programs!). The real problem is that *lots* of people still believe that floating point numbers are reals, and fixed point ones have infinite precision! They miss out completely on the non associativity or modularity, and all the other funny, funny properties of floating and fixed point. My contention is not with lisp n-ary operators (that are damn useful and safe on other domains), it is that even the simplest existing operators on floats and fixeds have entirely non-obvious semantics, and that this is carefully disguised by conventional, mathematics looking syntax. Ah sales! -- Piercarlo "Peter" Grandi | ARPA: pcg%uk.ac.aber.cs@nsfnet-relay.ac.uk Dept of CS, UCW Aberystwyth | UUCP: ...!mcsun!ukc!aber-cs!pcg Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg@cs.aber.ac.uk