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 EAA10445; Mon, 18 Jun 2001 04:19:08 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id EAA10460 for ; Mon, 18 Jun 2001 04:19:06 +0200 (MET DST) Received: from ip208.usw4.rb1.pdx.nwlink.com (ip208.usw4.rb1.pdx.nwlink.com [209.20.133.208]) by concorde.inria.fr (8.11.1/8.10.0) with SMTP id f5I2J5T16831 for ; Mon, 18 Jun 2001 04:19:05 +0200 (MET DST) Received: (qmail 2491 invoked by uid 500); 18 Jun 2001 02:19:03 -0000 Date: Sun, 17 Jun 2001 19:19:03 -0700 From: leary@nwlink.com To: Vitaly Lugovsky Cc: caml Subject: Re: [Caml-list] Newbie: declarations Message-ID: <20010617191903.D2105@jean> References: <20010616170909.B10922@jean> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from vsl@ontil.ihep.su on Sun, Jun 17, 2001 at 02:08:28PM +0400 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sun, Jun 17, 2001 at 02:08:28PM +0400, Vitaly Lugovsky wrote: > It's an almost functional language, so please avoid variables. And use > references only when you really need 'em. Refer to the Guide about > references and named tuples. Here's what I'm doing now (comments welcome; yes, I have short cryptic names). I'm writing a robot for RealTimeBattle, and want to have access to information that isn't contained in every message the robot gets (and I'm not using threads or signals yet, fwiw). This information is updated all the time. (I'll post a link to the whole thing for criticism, once it actually does something interesting. :) type datarec = { mutable name : string; mutable color : string; mutable bt_loc : float * float * float; mutable bt_dir : float; mutable bt_rot : int; (* 1 clockwise -1 counterclockwise *) mutable cn_rot : int; (* 1 clockwise -1 counterclockwise *) mutable rd_rot : float; (* 1 clockwise -1 counterclockwise *) mutable rd_iff : int; (* 1 friend 0 foe *) mutable rd_swp : float * float; mutable rd_cnt : int; mutable rd_ang : float; mutable speed : float; mutable ca : float; mutable time : float; mutable en_loc : coord; mutable en_dir : float; mutable en_nrg : float; mutable mn_loc : coord; mutable mn_dir : float; mutable ck_loc : coord; mutable ck_dir : float; };; let data : datarec = { name = "bob"; color = "00FF00"; bt_loc = (0.0, 0.0, 0.0); bt_dir = 0.0; bt_rot = 0; cn_rot = 0; rd_rot = 1.0; rd_iff = 0; rd_swp = (90.0, 90.0); rd_cnt = 0; rd_ang = 90.0; speed = 0.0; ca = 0.0; time = 0.0; en_loc = (0.0, 0.0); en_dir = 0.0; en_nrg = 0.0; mn_loc = (0.0, 0.0); mn_dir = 0.0; ck_loc = (0.0, 0.0); ck_dir = 0.0; };; (* Better to have 'let initialize = function....' for f() on a single variable? *) let initialize i = match i with 1 -> name "Bob"; color "00FF00 FF0000"; debug "initialize 1\n"; | 0 -> data.name <- "bob"; data.color <- "00FF00"; data.bt_loc <- (0.0, 0.0, 0.0); data.bt_dir <- 0.0; data.bt_rot <- 0; data.cn_rot <- 0; data.rd_rot <- 1.0; data.rd_iff <- 0; data.rd_swp <- (90.0, 90.0); data.rd_cnt <- 0; data.rd_ang <- 90.0; data.speed <- 0.0; data.ca <- 0.0; data.time <- 0.0; data.en_loc <- (0.0, 0.0); data.en_dir <- 0.0; data.en_nrg <- 0.0; data.mn_loc <- (0.0, 0.0); data.mn_dir <- 0.0; data.ck_loc <- (0.0, 0.0); data.ck_dir <- 0.0 ; debug "initialize 0\n"; | _ -> ();; ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr