From: ppch@doc.ic.ac.uk (P P C Herring)
Newsgroups: comp.lang.rexx
Subject: Re: Spelt logical operators
Followup-To: comp.lang.rexx
Date: 17 Dec 1992 18:29:03 -0000
Organization: Department of Computing, Imperial College, University of London, UK.
Distribution: world
NNTP-Posting-Host: dove.doc.ic.ac.uk


In article <2902.imc@uk.ac.ox.prg>, imc@comlab.ox.ac.uk (Ian Collier) writes:
|> In article <1garqeINNdt4@oak9.doc.ic.ac.uk>, ppch@doc.ic.ac.uk (P P C Herring) wrote:
|> >Has anyone ever suggested that Rexx implement the logical operators in words as
|> >well as in symbols? 
|> 
|> >I mean:                  if not A or (B and C) then ... 
|> >as an alternative to:    if \A | (B & C) then ...        
|> >which suffers from using characters that keyboard manufacturers and operating 
|> >systems treat as fair game for their own purposes, and also from not being very 
|> >close to any of the notations used in logic (except for '&'
                                                               , and even that
is old fashioned, the current symbol in logic/maths is ^ (like an upside-down 'v')
|>                                                             ).
|> 
|> Firstly, notice that on the right-hand side of an assignment there are no
|> reserved words whatsoever.  Using words for arithmetic or logic operators
|> goes against this.

Well yes and no. What's the difference between a reserved character and a reserved
word in a character string based language? Consider,

 A = ? ; say A                             /* gives  '?'                      */
 A = \                                     /* gives invalid expression error  */
 A = '\'; say A                            /* gives '\'                       */

 B = 0   ; A = \B      ; say A             /* gives '1'                       */
 B = 0   ; A = not B   ; say A             /* gives 'NOT 0'                   */
 B = 0   ; A = 'not' B ; say A             /* gives 'not 0'                   */

 B = 0   ; A = not B   ; say A             /* gives '1'                       */
 B = 'x' ; A = not B   ; say A             /* gives not logical value error   */
 B = 0   ; A = 'not' B ; say A             /* gives 'not 0'                   */

where the first two groups are what works now.

The third group looks much more Rexxish to me, and there are precedents for 
quoting strings to get their uninterpreted meaning (external commands and
getting native overridden bifs for example). 

|>                      Secondly, you may think it is bad style to have a
|> variable named "and", but there will surely be some programs out there that
|> get broken.  Consider that some programmers will name their variables in
|> languages other than English.  A French game program in which you have to
|> collect gold pieces might have a variable called "or" (think about it...)
|> 

Ok I've thought about it. As a user I'd be more than happy to buy a new
version of Rexx and find the interpreter had a switch that could suppress all the
new features that could break existing code, plus the ability to access this
switch from an 'options =' statement, plus a menu-driven utility that made it
easy to insert such a statement in any or all of my existing programs. If the
switch command was well-designed it would be easy to see what state the code was 
in just by looking (particularly if there was a switch for every such new
feature - this gives an incentive for not putting in too many!). 

|> Finally, why stop at the logical operators?  The symbols % and // are not
|> very intuitive are they?  Better have a word for ** as well, just to be on
|> the safe side.  Oh, and if we are to have a word for not, we have to have a
|> word for \== too.  Etc, etc...

Indeed: 'div' or 'intdiv' would be better than '%' (or even truncdiv to tally
with 'a % b = trunc(a / b) )'; 'mod' for '//' - yes I know it doesn't work for -ves
but it could do eg '-1 mod 3 = 2 mod 3' just needs extra flexibility in the
implementation though I admit I haven't thought through all the implications
here; 'power' for '**'; 'not ==' for '\=='. This is really besides my point, which
was that the logical operator symbols are impossible to implement clearly and 
intuitively; they get used so often it would make sense to target them for a more 
practical solution.

A way of doing the material conditional which would be relatively clear could be
to make 'iff' a synonym for the keyword 'if' and have 'if' change it's meaning 
within a statement like:

              iff B if A then do; nop; end                      .

The operator would be useful where B relies on A if A is the case but if A is
false it doesn't matter since 'iff' is really 'if and only if', and 'if' is really
half of an 'iff' with a truth table the same as '\( A & \B)' ( to be the same way 
round as the example) ie.
 
                      A B    \( A & \ B )    B if A
                      1 1    1  1 0 0 1         1
                      0 1    1  0 0 0 1         1
                      1 0    0  1 1 1 0         0 
                      0 0    1  0 0 1 0         1

A = 1
B = 1 ; iff B if A then; say 'ok'; else; say 'not ok'          /* gives ok     */
B = 0 ; iff B if A then; say 'ok'; else; say 'not ok'          /* gives not ok */
A = 0
B = 1 ; iff B if A then; say 'ok'; else; say 'not ok'          /* gives ok     */
B = 0 ; iff B if A then; say 'ok'; else; say 'not ok'          /* gives ok     */.

Well I'm not really sure about this but it's the best I can think of; at least
'iff' is a universally accepted abbreviation.
 

/* Patrick Herring, Imperial College, University of London */
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU