caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Oliver Bandel <oliver@first.in-berlin.de>
To: caml-list@inria.fr
Subject: Re: [Caml-list] multiple inheritance, bug or feature ?
Date: Sat, 25 Feb 2006 12:48:59 +0100	[thread overview]
Message-ID: <20060225114859.GA460@first.in-berlin.de> (raw)
In-Reply-To: <440038EC.5060302@yahoo.fr>

On Sat, Feb 25, 2006 at 12:01:00PM +0100, sejourne_kevin wrote:
> Hello :
> 
> 
> Consider the following sample :
> 
> class a =
> object
>   val mutable x = 0
>   method set v = Printf.printf "%d\n" x;x <- v
> end
> ;;
[...]
 
> class c :
>   object
>     val mutable x : int
>     val mutable y : int
>     method set : int -> unit
>     method set_x_a : int -> unit
>     method set_x_a' : int -> unit
>     method set_y : int -> unit
>   end
> 
> let d = new c;;
> val d : c = <obj>
> 
> d#set_x_a 3;;
> 0
> - : unit = ()
> 
> d#set_x_a' 2;;
> 0
> - : unit = ()
> 
> 
> When I wrote this program I expect this behavior but
> according to the warnings M the result should be 3.

Why do you think the expected behaviour should be
printing the 3?

Your method prints the old value, not the new value.

=======================
# let o = new c;;
val o : c = <obj>
# o#set_x_a 10;;
0
- : unit = ()
# o#set_x_a 20;;
10
- : unit = ()
# o#set_x_a 30;;
20
- : unit = ()
# 
=======================


If you want to print the current value after update,
you should also write your code in the way it it does this.
So, you should write it in this way:

  method set v = x <- v; Printf.printf "%d\n" x


Ciao,
   Oliver


  parent reply	other threads:[~2006-02-25 11:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-25 11:01 sejourne_kevin
2006-02-25 11:44 ` [Caml-list] " Jacques Garrigue
2006-02-25 11:55   ` Oliver Bandel
2006-02-25 11:48 ` Oliver Bandel [this message]
2006-02-25 12:09   ` sejourne_kevin
2006-02-25 12:16     ` Oliver Bandel
2006-02-25 12:33       ` Oliver Bandel

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=20060225114859.GA460@first.in-berlin.de \
    --to=oliver@first.in-berlin.de \
    --cc=caml-list@inria.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;
as well as URLs for NNTP newsgroup(s).