Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "Will M. Farr" <farr@MIT.EDU>
To: caml-list@yquem.inria.fr
Subject: Object Attribute Accessor Syntax Extension
Date: Wed, 23 Mar 2005 15:00:55 -0500	[thread overview]
Message-ID: <eb565b700ace2c0c96303c31515066f4@mit.edu> (raw)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

I would like to learn more about camlp4, so I thought I would undertake 
a simple project, but I would like some comment on my ideas first (in 
the hope that my project would be useful to others, too).  It has 
always irked me that when defining a class which is essentially an 
extensible data-container, one has to specify the data accessor 
functions in addition to the data values:

class body (m : float) (qq : float array) (pp : float array) =
object
   val mutable m = m
   val q = qq
   val p = pp
   val mutable f = Array.make (Array.length pp) 0.0
   method q = q
   method p = p
   method m = m
   method set_m mm = m <- mm
   method set_f ff = f <- ff
   (* etc *)
end

I think it would be nice to have accessor functions defined 
automatically for simple datatypes (sort of a simplified version of the 
:accessor q properties of a data member in CLOS -- Ruby does something 
like this with its :attr_accessor a,b,c notes in the class definiton, 
too, and Python probably has something similar).  The sytax I was 
thinking of using was:

class body (m : float) (qq : float array) (pp : float array) =
object
   val mutable accessor m = m
   val reader q = qq
   val reader p = pp
   val writer f = Array.make (Array.length pp) 0.0
   (* etc *)
end

If anyone would like to comment on this idea (because you hate the 
syntax, or love the syntax, or think it's been done before, or think 
it's a bad idea, etc) before I go ahead and write it, let me know.

Will 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (Darwin)

iD8DBQFCQcr+jFCrhUweU3MRArHIAJoC68xlm5Plr6brtXhnmwkDZ5D6tgCaAy5d
BcHYs6KXDrBhbssPxGDoPmM=
=iy74
-----END PGP SIGNATURE-----


             reply	other threads:[~2005-03-23 20:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-23 20:00 Will M. Farr [this message]
2005-03-24  8:13 ` [Caml-list] " Jacques Garrigue
2005-03-24  9:00   ` Alex Baretta
2005-03-24 10:33     ` Jacques Garrigue

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=eb565b700ace2c0c96303c31515066f4@mit.edu \
    --to=farr@mit.edu \
    --cc=caml-list@yquem.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