Number: 1191

Date: 21-May-84 19':43':39

Submitter: Sannella.PA

Source: Stefik.pa

Subject: translation of for...from...to...by wrong if BY is variable and negative

Assigned To: 

Attn: Masinter.pa

Status: Open

In/By: 

Problem Type: Bug

Impact: Minor

Difficulty: Moderate

Frequency: Everytime

Priority: Unlikely

System: Programming Environment

Subsystem: DWIM

Machine: 

Disk: 

Lisp Version: 

Source Files: 

Microcode Version: 

Memory Size: 

File Server: 

Server Software Version: 

Disposition: '
["Masinter" " 1-Sep-84 15':56':41" Subject': Attn':]

Description: '
Date': 17 May 84 11':19 PDT'
From': Stefik.pa'
Subject': Lisp': CLISP  Translation Puzzle?'
To': LispSupport.pa'
cc': Stefik.pa'
Lisp-System-Date':  9-Apr-84 18':28':19'
Machine-Type': Dorado'
'
(FOR  I FROM -1 TO 0 BY -1 DO (PRINT "HI"))'
'
correctly does not print anything, but if we use variables as in'
'
(SETQ ifrom -1)'
(SETQ  ito 0)'
(SETQ iby -1)'
'
(FOR I FROM ifrom TO ito BY iby DO (PRINT "HI"))'
'
actually executes the loop once and prints.  The CLISP translation of the second example as shown by PPT is much different from the first, and I believe incorrect.'
'
Mark '
'
-----'
'
mjsannella 5/21/84 --- I tried this, with the results below.  I think that it may just be a matter of test whether the for loop should do one iteration in this case....'
'
'
NIL'
77←FIX 68'
←DWIMIFY ((for X from 1 to 10 by 2 do (PRINT "HI")))'
(PROG (($$TEM1 10)'
       $$VAL'
       (X 1))'
  $$LP(COND'
        ((IGREATERP X $$TEM1)'
          (RETURN $$VAL)))'
      (PRINT "HI")'
  $$ITERATE'
      (SETQ X (IPLUS X 2))'
      (GO $$LP))'
(for X from 1 to 10 by 2 do (PRINT "HI"))'
78←(SETQ ifrom 1)'
1'
79←(SETQ ito 10)'
10'
80←(SETQ iby 2]'
2'
81←FIX 75'
←DWIMIFY ((for X from ifrom to ito by iby do (PRINT "HI")))'
(PROG (($$TEM2 ito)'
       $$TEM1 $$VAL (X ifrom))'
  $$LP(COND'
        ([AND $$TEM1 (OR (ZEROP $$TEM1)'
                         (COND'
                           ((MINUSP $$TEM1)'
                             (ILESSP X ito))'
                           (T (IGREATERP X ito]'
          (RETURN $$VAL)))'
      (PRINT "HI")'
  $$ITERATE'
      (SETQ X (IPLUS X (SETQ $$TEM1 iby)))'
      (GO $$LP))'
(for X from ifrom to ito by iby do (PRINT "HI"))'
82←DRIBBLE]'


Workaround: 

Test Case: 

Edit-By: Masinter

Edit-Date:  1-Sep-84 15':56':42