* 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
* Re: [Caml-list] Object Attribute Accessor Syntax Extension
2005-03-23 20:00 Object Attribute Accessor Syntax Extension Will M. Farr
@ 2005-03-24 8:13 ` Jacques Garrigue
2005-03-24 9:00 ` Alex Baretta
0 siblings, 1 reply; 4+ messages in thread
From: Jacques Garrigue @ 2005-03-24 8:13 UTC (permalink / raw)
To: farr; +Cc: caml-list
> 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
Looks nice. I actually wrote the same extension (with the same names)
experimentally in the yacc grammar last year. Having it in camlp4
would be more modular.
Note that in a yacc grammar your syntax would require "reader" and
"writer" to be keywords, but it may be OK with camlp4.
It may also be nice to have another small extension, so that
o#f <- expr
would be handled as
o#set_f <- (expr)
Jacques Garrigue
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Object Attribute Accessor Syntax Extension
2005-03-24 8:13 ` [Caml-list] " Jacques Garrigue
@ 2005-03-24 9:00 ` Alex Baretta
2005-03-24 10:33 ` Jacques Garrigue
0 siblings, 1 reply; 4+ messages in thread
From: Alex Baretta @ 2005-03-24 9:00 UTC (permalink / raw)
To: caml-list
Jacques Garrigue wrote:
> It may also be nice to have another small extension, so that
> o#f <- expr
> would be handled as
> o#set_f <- (expr)
>
> Jacques Garrigue
Doesn't this look dangerously similar to C++? Let us not turn to the
Dark Side of object orientation...
Alex
--
*********************************************************************
http://www.barettadeit.com/
Baretta DE&IT
A division of Baretta SRL
tel. +39 02 370 111 55
fax. +39 02 370 111 54
Our technology:
The Application System/Xcaml (AS/Xcaml)
<http://www.asxcaml.org/>
The FreerP Project
<http://www.freerp.org/>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Object Attribute Accessor Syntax Extension
2005-03-24 9:00 ` Alex Baretta
@ 2005-03-24 10:33 ` Jacques Garrigue
0 siblings, 0 replies; 4+ messages in thread
From: Jacques Garrigue @ 2005-03-24 10:33 UTC (permalink / raw)
To: alex; +Cc: caml-list
From: Alex Baretta <alex@barettadeit.com>
> Jacques Garrigue wrote:
>
> > It may also be nice to have another small extension, so that
> > o#f <- expr
> > would be handled as
> > o#set_f <- (expr)
>
> Doesn't this look dangerously similar to C++? Let us not turn to the
> Dark Side of object orientation...
I just took the syntax from ruby.
Note that both in ocaml and ruby, you cannot access directly object
fields, so the above syntax is not ambiguous: it can only be syntactic
sugar for a method call.
This is not to be mixed with overloading of assignment in C++, which
changes the semantics of an existing operator.
Jacques Garrigue
^ 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