Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "Sylvain BOULM'E" <Sylvain.Boulme@lip6.fr>
To: Serge Fantino <fantino@math.unice.fr>
Cc: caml-list@inria.fr, Vyskocil Vladimir <vyskocil@math.unice.fr>,
	caml-light@inria.fr
Subject: Re: port des d finitions des variables de classe
Date: Tue, 06 Oct 1998 14:35:01 +0200	[thread overview]
Message-ID: <199810061235.OAA13442@ventoux.lip6.fr> (raw)
In-Reply-To: Your message of "Mon, 05 Oct 1998 16:10:07 BST." <3618E14F.217B0EE1@math.unice.fr>

Bonjour,

Il me semble que c'est dans la semantique des classes
de Ocaml, qui supportent desormais les "variables statiques de classes"
partagees par tous les objets de la classe. (Les gens de Ocaml me
corrigeront ...)

Ainsi,

class test1 =
object
    val v = ref 5
    method get = !v
    method set x = v:=x
end;;

est equivalent a

class test1 = let v1=ref 5 in
object
    val v=v1
    ...


Dans les 2 cas,

let a=new test1 and b=new test1 in (b#set 4; a#get);;

retourne 4.



Par contre c'est different de 

class test2 () = let v1=ref 5 in
object
    val v=v1
    ...

let a=new test2 () and b=new test2 () in (b#set 4; a#get);;

retourne 5.


Encore mieux,

let f=new test2;;
retourne 
val f : unit -> test2 = <fun>

Une classe sert en fait a generer (au travers du new) des fonctions
a valeur dans les objets (de cette classe). Et comme pour les autres
fonctions de Caml, on a la possibilite d'utiliser des variables locales...


Sylvain.



PS: j'aurai pu ecrire aussi test2 sous la forme

class test2 () =
object 
  val v=ref 5
  ...


Il est aussi interessant de remarquer que

class test3 =
object
    val mutable v = 5
    method get = v
    method set x = v<-x
end;;

let a = new test3 and b=new test3 in (b#set 4; a#get);;

retourne 5







  reply	other threads:[~1998-10-06 13:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-10-05 15:10 porté des définitions " Serge Fantino
1998-10-06 12:35 ` Sylvain BOULM'E [this message]
1998-10-06 16:12   ` porte des definitions " Serge Fantino
1998-10-07  7:30     ` Pierre Weis
1998-10-07 13:03       ` porte des definitions / initialisation " Serge Fantino
1998-10-07 21:25         ` Jerome Vouillon
1998-10-08 13:42           ` Serge Fantino
1998-10-09 13:12             ` Sylvain BOULM'E
1998-10-07 10:16     ` porte des definitions " Sylvain BOULM'E
1998-10-08  7: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=199810061235.OAA13442@ventoux.lip6.fr \
    --to=sylvain.boulme@lip6.fr \
    --cc=caml-light@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=fantino@math.unice.fr \
    --cc=vyskocil@math.unice.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