Browse thread
Object Attribute Accessor Syntax Extension
- Will M. Farr
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Will M. Farr <farr@M...> |
| Subject: | Object Attribute Accessor Syntax Extension |
-----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-----