Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* Object Attribute Accessor Syntax Extension
@ 2005-03-23 20:00 Will M. Farr
  2005-03-24  8:13 ` [Caml-list] " Jacques Garrigue
  0 siblings, 1 reply; 4+ messages in thread
From: Will M. Farr @ 2005-03-23 20:00 UTC (permalink / raw)
  To: caml-list

-----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-----


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-03-24 10:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-23 20:00 Object Attribute Accessor Syntax Extension Will M. Farr
2005-03-24  8:13 ` [Caml-list] " Jacques Garrigue
2005-03-24  9:00   ` Alex Baretta
2005-03-24 10:33     ` Jacques Garrigue

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox