From: PierreAntoine Delsart <delsart@LPS.UMontreal.CA>  20051003 21:16:33

Hello people, Is it normal that I can't have Dllist.skip work as I expect using negative arguments ? Here is an exemple of what I'm trying with extlib 1.4 : > ocaml I /<path_to_extlib>/ /<path_to_extlib>/extLib.cma let ll = Dllist.create 0;; Dllist.add ll 4;; Dllist.add ll 8;; Dllist.add ll 5012;; let printl a = print_string ((string_of_int a)^"\n");; Dllist.iter printl ll;; let ll1 = Dllist.skip ll 1;; Dllist.iter printl ll1;; let ll1m = Dllist.skip ll (1);; Dllist.iter printl ll1m;; I expect the operation on ll1 and ll1m to behave differently, however I have exactly the same result ... as if the negative sign was not taken into account. Am I doing something wrong ? Thanks for your help. PA. 
From: Amit Dubey <amit.dubey@gm...>  20051004 12:32:26
Attachments:
Message as HTML

Looking at Dllist.skip, this looks like a bug. A better implementation of skip might be: let skip node idx =3D let rec loop idx n =3D if idx =3D=3D 0 then n else if idx>0 then loop (idx 1) n.next else loop (idx + 1) n.prev in loop idx node (The current version doesn't use n.prev for negative arguments). If there are no complains, I'll make this change. On 10/3/05, PierreAntoine Delsart <delsart@...> wrote: > > > Hello people, > > Is it normal that I can't have Dllist.skip work as I expect using > negative arguments ? > > Here is an exemple of what I'm trying with extlib 1.4 : > > > ocaml I /<path_to_extlib>/ /<path_to_extlib>/extLib.cma > > let ll =3D Dllist.create 0;; > Dllist.add ll 4;; > Dllist.add ll 8;; > Dllist.add ll 5012;; > let printl a =3D print_string ((string_of_int a)^"\n");; > Dllist.iter printl ll;; > let ll1 =3D Dllist.skip ll 1;; > Dllist.iter printl ll1;; > let ll1m =3D Dllist.skip ll (1);; > Dllist.iter printl ll1m;; > > > I expect the operation on ll1 and ll1m to behave differently, however I > have exactly the same result ... as if the negative sign was not taken > into account. > > Am I doing something wrong ? > > Thanks for your help. > > PA. > > >  > This SF.Net email is sponsored by: > Power Architecture Resource Center: Free content, downloads, discussions, > and more. http://solutions.newsforge.com/ibmarch.tmpl > _______________________________________________ > ocamllibdevel mailing list > ocamllibdevel@... > https://lists.sourceforge.net/lists/listinfo/ocamllibdevel > 
From: Brian Hurt <bhurt@sp...>  20051004 16:18:17

On Tue, 4 Oct 2005, Amit Dubey wrote: > Looking at Dllist.skip, this looks like a bug. A better implementation of > skip might be: > > let skip node idx = > let rec loop idx n = > if idx == 0 then > n > else if idx>0 then > loop (idx 1) n.next > else > loop (idx + 1) n.prev > in > loop idx node > > (The current version doesn't use n.prev for negative arguments). If there > are no complains, I'll make this change. I'm wondering if it might not be better to split the two loops, to avoid taking repeated branchs: let skip node idx = let rec floop idx n = if idx == 0 then n else floop (idx1) n.next in let rec bloop idx n = if idx == 0 then n else bloop (idx1) n.prev in if idx == 0 then n else if idx > 0 then floop (idx1) n.next else bloop ((idx)1) n.prev ;; Brian 
From: Amit Dubey <amit.dubey@gm...>  20051004 19:54:03
Attachments:
Message as HTML

Good point. I'll use this version. Hmmm... maybe I should add a unit test for skip as well... Amit On 10/4/05, Brian Hurt <bhurt@...> wrote: > > > > On Tue, 4 Oct 2005, Amit Dubey wrote: > > > Looking at Dllist.skip, this looks like a bug. A better implementation > of > > skip might be: > > > > let skip node idx =3D > > let rec loop idx n =3D > > if idx =3D=3D 0 then > > n > > else if idx>0 then > > loop (idx 1) n.next > > else > > loop (idx + 1) n.prev > > in > > loop idx node > > > > (The current version doesn't use n.prev for negative arguments). If > there > > are no complains, I'll make this change. > > I'm wondering if it might not be better to split the two loops, to avoid > taking repeated branchs: > > let skip node idx =3D > let rec floop idx n =3D > if idx =3D=3D 0 then > n > else > floop (idx1) n.next > in > let rec bloop idx n =3D > if idx =3D=3D 0 then > n > else > bloop (idx1) n.prev > in > if idx =3D=3D 0 then > n > else if idx > 0 then > floop (idx1) n.next > else > bloop ((idx)1) n.prev > ;; > > Brian > > 