Menu

#3191 parsing problem: thru 3 for i in [a,b]

None
closed
8
2024-06-22
2016-07-20
No

thru 3 for i in [2,4] do print(i);
parses as
((MDOIN SIMP) $I ((MLIST SIMP) 2 4) NIL NIL 3 NIL (($PRINT SIMP) $I))
which prints as
for i in [2,3,4] thru 3 do print(i);

When executed, it prints 2 and 3

It is apparently equivalent to
for i in [2,3,4] while i<=3 do print(i)
or
while i<=3 for i in [2,3,4] do print(i)

On the other hand,
for i in [2,4] thru 3 do print(i)
says "A do cannot have a thru with a [sic] in field"

The first version should cause the same parse error.

Maxima branch_5_37_base_528_g802ae7f on SBCL 1.2.11

Discussion

  • Robert Dodier

    Robert Dodier - 2024-06-03
    • labels: --> parser, do
     
  • Kris Katterjohn

    Kris Katterjohn - 2024-06-19
    • assigned_to: Kris Katterjohn
     
  • Kris Katterjohn

    Kris Katterjohn - 2024-06-19
    diff --git a/src/nparse.lisp b/src/nparse.lisp
    index b32a03fd4..c2de06e0a 100644
    --- a/src/nparse.lisp
    +++ b/src/nparse.lisp
    @@ -1558,7 +1558,7 @@
       ($do    . ())
       ($for    . ($for))
       ($from   . ($in $from))
    -  ($in     . ($in $from $step $next))
    +  ($in     . ($in $from $step $next $thru))
       ($step   . ($in       $step $next))
       ($next   . ($in  $step $next))
       ($thru   . ($in $thru)) ;$IN didn't used to get checked for
    

    No problems with the test suite, share test suite or rtest_translator.

    Before:

    (%i1) '(thru 3 for i in [1, 2, 3, 4] do print (i));
    (%o1) for i in [1,2,3,4] thru 3 do print(i)
    
    (%i2) thru 3 for i in [1, 2, 3, 4] do print (i);
    
    1
    2
    3
    (%o2) done
    
    (%i3) '(for i in [1, 2, 3, 4] thru 3 do print (i));
    
    incorrect syntax: A do cannot have a thru with a in field.
    n [1, 2, 3, 4] thru
                      ^
    

    After:

    (%i4) '(thru 3 for i in [1, 2, 3, 4] do print (i));
    
    incorrect syntax: A do cannot have a in with a thru field.
    '(thru 3 for i in
                    ^
    (%i4) '(for i in [1, 2, 3, 4] thru 3 do print (i));
    
    incorrect syntax: A do cannot have a thru with a in field.
    n [1, 2, 3, 4] thru
                      ^
    
     
  • Kris Katterjohn

    Kris Katterjohn - 2024-06-22
    • status: open --> closed
     
  • Kris Katterjohn

    Kris Katterjohn - 2024-06-22

    Fixed by commit [f2a4dd].

     

    Related

    Commit: [f2a4dd]


Log in to post a comment.