caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* "pointers" to methods
@ 2001-02-06 17:26 Mattias Waldau
  2001-02-07 22:27 ` John Prevost
  2001-02-07 23:23 ` Gerd Stolpmann
  0 siblings, 2 replies; 4+ messages in thread
From: Mattias Waldau @ 2001-02-06 17:26 UTC (permalink / raw)
  To: Caml-List

In the following code I would like to apply the method inc or dec to the
object obj. However, what is the syntax I should use? At all comments below
the compilation fails.

class class1 =
  object (self)
    val mutable x = 1
    method inc step = x <- x+step    
    method dec step = x <- x+step
    method get () = x
  end

let main () =
  let method_to_call =
    if Random.int 2 = 0 then 
      inc   (* pointer to inc-method in class1 *)
    else
      dec   (* pointer to dec-method in class1 *)
  in
  let obj = new class1 in
  obj#method_to_call 2;    (* apply pointer to method in class1 *)
  obj#get ()

/mattias



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-02-08 19:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-02-06 17:26 "pointers" to methods Mattias Waldau
2001-02-07 22:27 ` John Prevost
2001-02-08 17:00   ` John Max Skaller
2001-02-07 23:23 ` Gerd Stolpmann

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).