From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA18282; Wed, 21 Jan 2004 14:07:07 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA17837 for ; Wed, 21 Jan 2004 14:07:06 +0100 (MET) Received: from web60606.mail.yahoo.com (web60606.mail.yahoo.com [216.109.118.244]) by nez-perce.inria.fr (8.11.1/8.11.1) with SMTP id i0LD75v02580 for ; Wed, 21 Jan 2004 14:07:05 +0100 (MET) Message-ID: <20040121130704.38016.qmail@web60606.mail.yahoo.com> Received: from [200.137.225.199] by web60606.mail.yahoo.com via HTTP; Wed, 21 Jan 2004 10:07:04 ART Date: Wed, 21 Jan 2004 10:07:04 -0300 (ART) From: =?iso-8859-1?q?ANDR=FFffffc9=20MOURA?= Subject: [Caml-list] Collateral effect with pointers To: caml-list@inria.fr MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1788317889-1074690424=:35500" Content-Transfer-Encoding: 8bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; collateral:99 pointers:01 3.07:01 delaunay:01 pointers:01 collateral:99 improper:01 dereference:01 val:01 val:01 orient:99 0.0:01 0.0:01 edg:99 orient:99 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk --0-1788317889-1074690424=:35500 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Hi to all! I am trying to implement in OCaml version 3.07 the Delaunay triangulation contained in the program 'Triangle' of J.R. Shewchuk for divide-and-conquer, but the results differ from those produced by the original program. After exhausting tests, I believe that the problem is related to the structure of pointers. Or either, with some moment the values of 'farleft' and 'farright' intervene one in another one. Please, it would like to know as to hinder collateral effect (improper propagation) provoked by pointers for the following situation: type 'a pointer = Null | Pointer of 'a ref;; let ( !^ ) = function | Null -> invalid_arg "Attempt to dereference the null pointer" | Pointer r -> !r;; (*val ( !^ ) : 'a pointer -> 'a = *) let ( ^:= ) p v = match p with | Null -> invalid_arg "Attempt to assign the null pointer" | Pointer r -> r := v;; (*val ( ^:= ) : 'a pointer -> 'a -> unit = *) let new_pointer x = Pointer (ref x);; (*val new_pointer : 'a -> 'a pointer = *) ... let dummytri = new_pointer ({tr_adjtri=(Array.init 3 (fun x -> {te_ptri=Null; ta_orient=0})); tr_no=(Array.init 3 (fun x -> dummypoint)); tr_adjedg=(Array.init 3 (fun x -> dummysh)); tr_area=0.0});; let dummypoint = new_pointer {po_x = 0.0; po_y = 0.0; po_marker = 0};; let dummysh = new_pointer {sh_edg=(Array.init 2 (fun x -> Null)); sh_no=(Array.init 2 (fun x -> dummypoint)); sh_adjtri=(Array.init 2 (fun x -> Null)); sh_marker=0};; let triangleloop = ref [||];; ... ... let farleft = ref (new_pointer {te_tri={tr_adjtri=(Array.init 3 (fun x -> {te_ptri=dummytri; ta_orient=0})); tr_no=(Array.init 3 (fun x -> dummypoint)); tr_adjedg=(Array.init 3 (fun x -> dummysh)); tr_area=0.0}; te_orient=0}) and farright = ref (new_pointer {te_tri={tr_adjtri=(Array.init 3 (fun x -> {te_ptri=dummytri; ta_orient=0})); tr_no=(Array.init 3 (fun x -> dummypoint)); tr_adjedg=(Array.init 3 (fun x -> dummysh)); tr_area=0.0}; te_orient=0}) in ... maketriangle farleft; maketriangle farright; (* It has advanced, geometric primitives modify values of farleft and farright and connect they. *) ... (* It adds an element to the 'triangleloop' array and returns a pointer for its last element *) let maketriangle newtriedge = let l = Array.length !triangleloop in aumenteTriangulos triangleloop 1; newtriedge ^:= !triangleloop.(l);; (*val maketriangle : triedge pointer -> unit = *) (* It increases the size of 'triangleloop' *) let aumenteTriangulos trianguloArray aumento = trianguloArray := Array.append !trianguloArray (Array.init aumento (fun x -> {te_tri={tr_adjtri=(Array.init 3 (fun x -> {te_ptri=dummytri; ta_orient=0})); tr_no=(Array.init 3 (fun x -> dummypoint)); tr_adjedg=(Array.init 3 (fun x -> dummysh)); tr_area=0.0}; te_orient=0}));; (*val aumenteTriangulos : triedge array ref -> int -> unit = *) Yours truly, André Luiz Moura --------------------------------- Yahoo! GeoCities: a maneira mais fácil de criar seu web site grátis! --0-1788317889-1074690424=:35500 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit
Hi to all!
 
I am trying to implement in OCaml version 3.07 the Delaunay triangulation contained in the program 'Triangle' of  J.R. Shewchuk for divide-and-conquer,  but the results differ from those produced by the
original program. After exhausting tests, I believe that the problem is related to the structure of pointers. Or either, with some moment the values of  'farleft' and 'farright' intervene one in another one. Please, it would like to know as to hinder collateral effect (improper propagation) provoked by pointers for the following situation:
 
type 'a pointer = Null | Pointer of 'a ref;;
let ( !^ ) = function
    | Null -> invalid_arg "Attempt to dereference the null pointer"
    | Pointer r -> !r;;
(*val ( !^ ) : 'a pointer -> 'a = <fun>*)
let ( ^:= ) p v =
    match p with
    | Null -> invalid_arg "Attempt to assign the null pointer"
    | Pointer r -> r := v;;
(*val ( ^:= ) : 'a pointer -> 'a -> unit = <fun>*)
let new_pointer x = Pointer (ref x);;
(*val new_pointer : 'a -> 'a pointer = <fun>*)
...
let dummytri = new_pointer ({tr_adjtri=(Array.init 3 (fun x -> {te_ptri=Null; ta_orient=0})); tr_no=(Array.init 3 (fun x -> dummypoint)); tr_adjedg=(Array.init 3 (fun x -> dummysh)); tr_area=0.0});;
let dummypoint = new_pointer {po_x = 0.0; po_y = 0.0; po_marker = 0};;
let dummysh = new_pointer {sh_edg=(Array.init 2 (fun x -> Null)); sh_no=(Array.init 2 (fun x -> dummypoint)); sh_adjtri=(Array.init 2 (fun x -> Null)); sh_marker=0};;
let triangleloop = ref [||];;
...

...
let farleft  = ref (new_pointer {te_tri={tr_adjtri=(Array.init 3 (fun x -> {te_ptri=dummytri; ta_orient=0})); tr_no=(Array.init 3 (fun x -> dummypoint)); tr_adjedg=(Array.init 3 (fun x -> dummysh)); tr_area=0.0}; te_orient=0})
and farright = ref (new_pointer {te_tri={tr_adjtri=(Array.init 3 (fun x -> {te_ptri=dummytri; ta_orient=0})); tr_no=(Array.init 3 (fun x -> dummypoint)); tr_adjedg=(Array.init 3 (fun x -> dummysh)); tr_area=0.0}; te_orient=0}) in
...
maketriangle farleft;
maketriangle farright;
(* It has advanced, geometric primitives modify values of farleft and farright and connect they. *)
...
 

(* It adds an element to the 'triangleloop' array and returns a pointer for its last element *)
let maketriangle newtriedge =
   let l = Array.length !triangleloop in
   aumenteTriangulos triangleloop 1;
   newtriedge ^:= !triangleloop.(l);;
(*val maketriangle : triedge pointer -> unit = <fun>*)
 

(* It increases the size of  'triangleloop' *)
let aumenteTriangulos trianguloArray aumento =
   trianguloArray := Array.append !trianguloArray
                             (Array.init aumento (fun x -> {te_tri={tr_adjtri=(Array.init 3 (fun x ->
                             {te_ptri=dummytri; ta_orient=0})); tr_no=(Array.init 3 (fun x -> dummypoint));
                             tr_adjedg=(Array.init 3 (fun x -> dummysh)); tr_area=0.0}; te_orient=0}));;
(*val aumenteTriangulos : triedge array ref -> int -&! gt; unit = <fun>*)
 

Yours truly,
 
André Luiz Moura



Yahoo! GeoCities: a maneira mais fácil de criar seu web site grátis! --0-1788317889-1074690424=:35500-- ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners