Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!boulder!andreasg From: andreasg@boulder.Colorado.EDU (Andreas Girgensohn) Newsgroups: comp.object Subject: Re: "Sender" construct in OOLs Message-ID: <12545@boulder.Colorado.EDU> Date: 9 Oct 89 21:44:53 GMT References: <9450008@hplsla.HP.COM> <5677@portia.Stanford.EDU> Sender: news@boulder.Colorado.EDU Reply-To: andreasg@boulder.Colorado.EDU (Andreas Girgensohn) Organization: University of Colorado, Boulder Lines: 40 In article <5677@portia.Stanford.EDU> dchapman@Portia.Stanford.EDU (David Chapman) writes: >In article <9450008@hplsla.HP.COM> jima@hplsla.HP.COM (Jim Adcock) writes: >>You should be able to do this using function call overloading in C++. >>I suspect its not trivial to figure out, however. > >After thinking about this some more, I cannot conceive of a way to >implement the "sender" construct. Why? Because the "sender" is of >arbitrary type. *Anything* can send an object a message. That's the >whole point. Maybe Smalltalk or Flavors could handle this by looking >up the type of the object, but it would be horrendous to do in a >compiled language like C++. > >Comments? Remember, the original poster wanted mutual recursion - he >wanted to send messages back to the caller. In Lisp one could do it with a variable with dynamic scope: (defvar sender :no-object) ;;; within every method: (let ((sender self)) ;; message body (actually, the previous value of sender is needed within ;; the body) ) There are no variables with dynamic scope in C. A solution could be an array as a stack of senders (I don't no the C++ syntax). object *senders[200]; int senders_top = 0; senders[0] = (object *)NULL; /* within every method: */ senders[++senders_top] = self; /* message body */ senders_top--;