Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!ukc!icdoc!syma!aarons From: aarons@syma.sussex.ac.uk (Aaron Sloman) Newsgroups: comp.lang.prolog Subject: Re: Prefix operators and blanks (was: WG17) Summary: In Pop-11 "x + y" and "+(x,y)" are equivalent. Keywords: operators, prefix, quotes, Pop-11 Message-ID: <1896@syma.sussex.ac.uk> Date: 9 Dec 89 14:18:03 GMT References: <24703@cup.portal.com> <2892@munnari.oz.au> <24783@cup.portal.com> Organization: School of Cognitive & Computing Sciences, Sussex Univ. UK Lines: 78 pgl@cup.portal.com (Peter G Ludemann) writes: > Date: 7 Dec 89 07:00:13 GMT > > The only canonical way of writing out a compound term so that > it can be read in without regard to operator definitions is to > quote everything and use no operator notation. For example: > > a+b ===> '+'('a','b') > :- (a,b) ===> ':'(','('a','b')) > > Why all the quotes? Well, someone could have defined `a' to be > an operator and therefore '+'(a,b) would get a syntax error. etc. and References: <24703@cup.portal.com> matsc@sics.se (Mats Carlsson) writes: > Date: 6 Dec 89 08:50:53 GMT > Organization: Swedish Institute of Computer Science, Kista [.... portion omitted.....] > ................ The only > other language where "atoms" can be quoted that I know of is LISP, but > LISP does not have user defined operators, so it's hard to find an > analogy to justify Peter's suggestion. Pop-11, like Lisp, allows atoms to be quoted, and does have user defined operators (and built in ones). In the original Pop-2 as far as I recall, and certainly in all the derivatives that I have used (POP-10, WPOP, and POP-11) an "infix" operator can also be used in the standard prefix position for a function. It can also be used in postfix position. E.g. all the following are equivalent in Pop-11, (partly because of the way in Pop uses a stack for passing arguments and results). x+y +(x,y) (x,y)+ x,+y x,y,+ x,y,+() nonop+(x,y) valof("+")(x,y) ;;; this one is less efficient (Note: I have relied on the fact that "+" and alphabetic characters are in different lexical classes. If "x" and "y" were replaced by identifiers composed of "sign" characters like ":", "=", "#", "+",etc, then spaces would be required as delimiters to separate them from "+".) Essentially, being an operator in Pop simply means that (a) the identifier cannot be given any value other than a procedure, so that run-time checks are not needed (b) the invocation of the procedure does not REQUIRE the use of following parentheses as for ordinary (non-operator) procedure calls, e.g. max(x,y), min(x,y) (c) the operator has a precedence (so that x*y+z=k does what you expect, where "+", "*", and "=" are operators with different precedences) (d) if you want to refer to the procedure without executing it you have to precede the identifier with "nonop", or, less efficiently, use valof, as above. Of course, in Pop operators are not used to create structures as in prolog (though they can have as values procedures that when executed create structures, e.g. "x :: y" creates a list whose head is x and whose tail is y because "::" is an infix name for CONS). Aaron Sloman, School of Cognitive and Computing Sciences, Univ of Sussex, Brighton, BN1 9QH, England EMAIL aarons@cogs.sussex.ac.uk or: INTERNET: aarons%uk.ac.sussex.cogs@nsfnet-relay.ac.uk aarons%uk.ac.sussex.cogs%nsfnet-relay.ac.uk@relay.cs.net