jayduhon / inferno-os

Automatically exported from code.google.com/p/inferno-os
2 stars 0 forks source link

lists.b delete function not working properly #257

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. compile attached testlists.b
2. run testlists.dis

What is the expected output? 

testlists

#1
a=0 b=1 c=2  

#2
a=0 b=1 c=2  
a=12 b=13 c=14  
a=9 b=10 c=11  

#3
a=0 b=1 c=2  
a=12 b=13 c=14  
a=9 b=10 c=11  

#4
a=12 b=13 c=14  
a=9 b=10 c=11  

#5
a=0 b=1 c=2  
a=12 b=13 c=14  

#6
a=0 b=1 c=2  
a=9 b=10 c=11  

#7
a=0 b=1 c=2  
a=12 b=13 c=14  
a=9 b=10 c=11

What do you see instead?

testlists

#1
a=0 b=1 c=2  

#2
a=0 b=1 c=2  
a=12 b=13 c=14  
a=9 b=10 c=11  

#3

#4
a=12 b=13 c=14  
a=9 b=10 c=11  

#5

#6
a=9 b=10 c=11  

#7

Please use labels and text to provide additional information.

here is proposed patch for
delete[T](x: T, l: list of T): list of T
(even if it was diffed against 20110302-2215, this issue is still present on 
20110404-1906)

diff -r 054335dfb712 appl/lib/lists.b
--- a/appl/lib/lists.b  Wed Mar 02 22:16:28 2011 +0000
+++ b/appl/lib/lists.b  Mon Apr 04 20:21:29 2011 +0300
@@ -92,13 +92,14 @@
    for { T =>  eq: fn(a, b: T): int; }
 {
    o: list of T;
-   for(; l != nil; l = tl l)
+   for(; l != nil; l = tl l) 
        if(T.eq(x, hd l)){
            l = tl l;
-           for(; o != nil; o = tl o)
-               l = hd o :: l;
            break;
-       }
+       } else
+           o = hd l :: o;
+   for(; o != nil; o = tl o)
+       l = hd o :: l;
    return l;
 }

Original issue reported on code.google.com by bumbudo...@gmail.com on 6 Apr 2011 at 9:15

Attachments:

GoogleCodeExporter commented 9 years ago
evidently the idea was to avoid reallocating and copying all the elements if 
there wasn't a match. try the updated version.

Original comment by Charles....@gmail.com on 6 Apr 2011 at 9:40

GoogleCodeExporter commented 9 years ago
it seems to work ok. also tested with double matches, and the result was 
deleting the first occurence (ok).

Original comment by bumbudo...@gmail.com on 7 Apr 2011 at 8:29

GoogleCodeExporter commented 9 years ago
try this new one, with added Lists->find (which is more general).

committed changeset 508:81c4555f717d

Original comment by Charles....@gmail.com on 7 Apr 2011 at 9:05

GoogleCodeExporter commented 9 years ago
works ok with the same tests.
also the implementation is much beautiful ;)

Original comment by bumbudo...@gmail.com on 7 Apr 2011 at 9:54