From: "ANDRÿffffc9 MOURA" <aluizmoura@yahoo.com.br>
To: caml-list@inria.fr
Subject: [Caml-list] Collateral effect with pointers
Date: Wed, 21 Jan 2004 10:07:04 -0300 (ART) [thread overview]
Message-ID: <20040121130704.38016.qmail@web60606.mail.yahoo.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 3088 bytes --]
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 -> unit = <fun>*)
Yours truly,
André Luiz Moura
---------------------------------
Yahoo! GeoCities: a maneira mais fácil de criar seu web site grátis!
[-- Attachment #2: Type: text/html, Size: 4205 bytes --]
next reply other threads:[~2004-01-21 13:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-21 13:07 ANDRÿffffc9 MOURA [this message]
2004-01-21 14:38 ` skaller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040121130704.38016.qmail@web60606.mail.yahoo.com \
--to=aluizmoura@yahoo.com.br \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox