[net.lang] IF KICK-BACK GREATER THAN...

render@uiucdcsb.UUCP (11/21/84)

>PS:  How many other languages let you write:
>
>	IF KICK-BACK GREATER THAN 10 AND LESS THAN 100 THEN ...
>
>without having to mention kick-back twice?  They don't design them like they
>used to.  Probably just as well.

For what it is worth, in Icon one can say:

    if 10 < kick_back < 100 then ...

or even the more interesting

    if kick_back = (10 | 100) then ...

(the last being IF KICK-BACK EQUALS 10 OR 100 THEN...)

Who says Ralph Griswold never came up with a couple a good features in a 
language?

                             Hal Render
                             U. of Illinois
                             uiucdcsb!render

ian@ic-cs.UUCP (Ian W. Moor) (12/02/84)

[It went thataway]

In Pascal you can write IF KICK-BACK GREATER THAN 10 AND LESS THAN 100 THEN

  as
    IF Kick_back IN [10..100] THEN
 
  or how about
    IF Kick_back IN [10,20,30,40,50] THEN
  if you only want multiples of 10 ?
 


-- 

  Ian W. Moor			{mcvax,vax135}!ukc!west44!ic-cs!im
  Dept of Computing
  Imperial College		"The squire on a hippopotamus is equal to 
  180 Queen's Gate		 the son of the other two squires"
  London SW7 2BZ

steven@mcvax.UUCP (Steven Pemberton) (12/09/84)

In article <223@ic-cs.UUCP> ian@ic-cs.UUCP (Ian W. Moor) writes:
> In Pascal you can write IF KICK-BACK GREATER THAN 10 AND LESS THAN 100 THEN
> as IF Kick_back IN [10..100] THEN
>
> or how about IF Kick_back IN [10,20,30,40,50] THEN
> if you only want multiples of 10 ?

In B (the new one, not the predecessor of C) you can also write

	IF x in {-1; 10; 20; 30.5; 100*pi; 2**81; 100**1000-1}:
etc.
As already pointed out earlier, B allows you to say
	IF 10<x<100:
(but these two examples are not equivalent, you understand).

Steven Pemberton, CWI, Amsterdam; steven@mcvax

ndiamond@watdaisy.UUCP (Norman Diamond) (12/09/84)

> In Pascal you can write IF KICK-BACK GREATER THAN 10 AND LESS THAN 100 THEN
> 
>   as
>     IF Kick_back IN [10..100] THEN
>  
>   or how about
>     IF Kick_back IN [10,20,30,40,50] THEN
>   if you only want multiples of 10 ?
 
True, but it requires an order of magnitude more CPU time than two comparisons.

-- Norman Diamond

UUCP:  {decvax|utzoo|ihnp4|allegra|clyde}!watmath!watdaisy!ndiamond
CSNET: ndiamond%watdaisy@waterloo.csnet
ARPA:  ndiamond%watdaisy%waterloo.csnet@csnet-relay.arpa

"Opinions are those of the keyboard, and do not reflect on me or higher-ups."

ags@pucc-i (Dave Seaman) (12/11/84)

>> In Pascal you can write IF KICK-BACK GREATER THAN 10 AND LESS THAN 100 THEN
>> 
>>   as
>>     IF Kick_back IN [10..100] THEN
>>  
>>   or how about
>>     IF Kick_back IN [10,20,30,40,50] THEN
>>   if you only want multiples of 10 ?
> 
>True, but it requires an order of magnitude more CPU time than two comparisons.

An order of magnitude?  Not if it's properly implemented.  The indicated
condition needs only ONE comparison, plus most likeley a rotation and perhaps
an indexing operation.
-- 
[This is my bugkiller line.  It may appear to be misplaced, but it works.]

Dave Seaman			My hovercraft is no longer full of 
..!pur-ee!pucc-i:ags		eels (thanks to my confused cat).

mccaugh@uiucdcs.UUCP (12/30/84)

 I believe the set-expression you want for: 10 < KICK-BACK < 100 should be
              kickback  in  [11..99],  not  kick_back  in  [10..100].

 Also, as the following extraction of VAX-code demonstrates, the set-expression
 appears to be the less tedious of the two alternatives, to wit:

 /* set-expression */                  /* conditional-expression */

    clrl    r0                             movl    _kickback,r0
    subl2   r2,r1                          movl    $10,r1
    cmpl    r1,r3                          cmpl    r0,r1
    jgtru   1f                             jleq    L9999
    jbc     r1,(r4),1f                     movl    $1,r0
    incl    r0                             jbr     L9998
1:                                      L9999:
    tstl    r0                             clrl    r0
    jeql    L7                          L9998:
    moval    _output,-12(fp)               movl    _kickback,r1
(* is the code for the *)                  cvtbl    $100,r2
(* following set-expr. *)                  cmpl    r1,r2
if  kickback in [11..99]  then             jgeq    L9997
    writeln(kickback);                     movl    $1,r1
                                           jbr     L9996
                                        L9997:
                                           clrl    r1
                                        L9996:
                                           mcoml   r1,r1
                                           bicl2   r1,r0
                                           jeql    L6
                                           moval   _output,-12(fp)
                                     (* is the code for the *)
                                     (* following cond-expr *)
                                     if  (kickback > 10) and
                                         (kickback < 100)  then
                                         writeln(kickback);

                                       --uiucmsl!mccaugh

ndiamond@watdaisy.UUCP (Norman Diamond) (01/02/85)

> I believe the set-expression you want for: 10 < KICK-BACK < 100 should be
>              kickback  in  [11..99],  not  kick_back  in  [10..100].
[I agree -- N.D.]
> Also, as the following extraction of VAX-code demonstrates, the set-expression
> appears to be the less tedious of the two alternatives, to wit:
> 
>  /* set-expression */                  /* conditional-expression */
> 
>     clrl    r0                             movl    _kickback,r0
>     subl2   r2,r1                          movl    $10,r1
>     cmpl    r1,r3                          cmpl    r0,r1
>     jgtru   1f                             jleq    L9999
>     jbc     r1,(r4),1f                     movl    $1,r0
>     incl    r0                             jbr     L9998
> 1:                                      L9999:
>     tstl    r0                             clrl    r0
>     jeql    L7                          L9998:
>     moval    _output,-12(fp)               movl    _kickback,r1
> (* is the code for the *)                  cvtbl    $100,r2
> (* following set-expr. *)                  cmpl    r1,r2
> if  kickback in [11..99]  then             ... [this column of code]
>     writeln(kickback);                     ... [truncated by N.D.]

The code shown for the set-expression doesn't seem to involve 11 and 99.
What are the original contents of R1 and R2?  I think that not all of the
relevant generated code is shown.

-- Norman Diamond

UUCP:  {decvax|utzoo|ihnp4|allegra|clyde}!watmath!watdaisy!ndiamond
CSNET: ndiamond%watdaisy@waterloo.csnet
ARPA:  ndiamond%watdaisy%waterloo.csnet@csnet-relay.arpa

"Opinions are those of the keyboard, and do not reflect on me or higher-ups."

chris@umcp-cs.UUCP (Chris Torek) (01/04/85)

> Also, as the following extraction of VAX-code demonstrates, the
> set-expression appears to be the less tedious of the two alternatives,
> to wit:

(followed by lots of assembly)

Actually, all this proves is that the Pascal compiler ``pc'' produces
pretty lousy code.

Since the expressions

	if x in [a..b] then

and

	if (x >= a) and (x <= b) then

are equivalent for x, a, b \elem Z (integers), the code produced should
ideally be equivalent.
-- 
(This line accidently left nonblank.)

In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (301) 454-7690
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris@maryland