caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: leary@nwlink.com
To: Vitaly Lugovsky <vsl@ontil.ihep.su>
Cc: caml <caml-list@inria.fr>
Subject: Re: [Caml-list] Newbie: declarations
Date: Sun, 17 Jun 2001 19:19:03 -0700	[thread overview]
Message-ID: <20010617191903.D2105@jean> (raw)
In-Reply-To: <Pine.LNX.4.30.0106171406290.20599-100000@ontil.ihep.su>; from vsl@ontil.ihep.su on Sun, Jun 17, 2001 at 02:08:28PM +0400

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


  reply	other threads:[~2001-06-18  2:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-17  0:09 leary
2001-06-17 10:08 ` Vitaly Lugovsky
2001-06-18  2:19   ` leary [this message]
2001-06-18 15:18     ` Remi VANICAT
2001-06-18 20:19       ` [Caml-list] Good introduction for the working programmer in Objective CAML Mattias Waldau
2001-06-18 20:35         ` Miles Egan
2001-06-18 20:49         ` leary
2001-06-17 15:33 ` [Caml-list] Newbie: declarations David Fox
2001-06-18 14:52   ` FabienFleutot
2001-06-19  8:11 ` Frédéric van der Plancke
2001-06-19 10:22   ` Sven LUTHER
2001-06-19 12:25     ` Frank Atanassow

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=20010617191903.D2105@jean \
    --to=leary@nwlink.com \
    --cc=caml-list@inria.fr \
    --cc=vsl@ontil.ihep.su \
    /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;
as well as URLs for NNTP newsgroup(s).