Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Object Attribute Accessor Syntax Extension
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-03-24 (08:13)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] Object Attribute Accessor Syntax Extension
> 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