Path: news.daimi.aau.dk!glad From: "S\xren Brandt" Newsgroups: comp.lang.beta Subject: Re: THIS and COMPONENTs Date: 1 Aug 1996 11:36:33 GMT Organization: DAIMI, Computer Science Dept. at Aarhus University Lines: 120 Approved: mailtonews@daimi.aau.dk Distribution: world Message-ID: <4tq4s1$muk@gjallar.daimi.aau.dk> NNTP-Posting-Host: daimi.daimi.aau.dk David L. Shang wrote: > My question is, if the concept of function (method) and class are > unified into "pattern" in Beta, why cann't the expression "this(P)" > represent a functional pattern or the current activity? Why should a > low-level hack be used? I agree that a low-level hack should not be necessary. The need for such a hack is caused by an incomplete compiler. Consider the declaration of two object references: aSystem: ^System; (* Reference to System *) aSystemComponent: ^|System; (* Reference to System Component *) Both of these references are qualified to point to instances of the System pattern. However, the "aSystemComponent" reference may furthermore only point to component instances of the system pattern. Hence, "aSystemComponent" is stronger qualified than "aSystem". As with other cases where one reference is stronger qualified than another, there should be no problem in statically allowing the following assignment: aSystemComponent[]->aSystem[]; However, the compiler does not implement this, although I think it should. For this reason, the "objinterface" library contains the "componentToObject" method. The opposite assignment: aSystem[]->aSystemComponent[]; is a case of "downcasting", and might or might not be correct, depending on whether the System object referred by "aSystem" is actually also a component, which is not known statically. However, the compiler does allow other cases of downcasting, subject to a runtime type check, and could do the same in the case of assignment from object references to component references, as in the example above. However, the compiler does not implement this either, although I think it should. The "objectToComponent" method I posted is therefore correctly classified as a hack that circumvents that the compiler does not implement this functionality directly. Concerning your example, the calls (this(Produce), Consume)->Wait; and (this(Consume), Produce)->Wait; are exactly the situations corresponding to the "downcast": this(produce) is statically only known to be an object, but Wait expects a component parameter. Since the compiler does not implement the necessary downcast, it must be done using "objectToComponent". As far as I understood on Kasper, this problem is exactly what made him start this news thread. -- Soren > > Consider a multi-thread task model (not exactly in Beta): > > PCGame : Task: > (# > BallQueue : Queue (#...#); // a class pattern > Consume : Thread; // predefine a procedure pattern > Produce : Thread // a procedure pattern > (# ... > enter (...) > do repeat > ( if BallQueue.Full then > (this(Produce), Consume)->Wait; > // let this(Produce) wait for a wake signal > // from the Consume thread > CreateBall->BallQueue.Append; > Produce->Wake; > // wake one of threads who are waiting for > // the Produce thread's signal > (this(Produce), two_seconds)->Sleep > ) > #) > Consume : Thread // a procedure pattern > (# ... > enter (...) > do repeat > ( if BallQueue.Empty then > (this(Consume), Produce)->Wait; > BallQueue.RemoveHead; > Consume->Wake; > (this(Consume), one_seconds)->Sleep > ) > #) > #) > > Can I have the above Beta program? Note that "Wait", "Wake" and "Sleep" > are all procedure patterns defined in the class pattern "Task": > > Task > (# > ... // waiting queues are defined here > Thread > (# ... > //protocols for threads > #) > Wait > (# who: Thread; > for_whom: class of Thread; > // "for_whom" is a class variable! > enter (who, for_whom) > do append "who" in the waiting "for-whom" queue; > #) > Wake > (# whose: class of Thread; > enter (whose) > do wake up the first one in the "whose" queue, if any; > #) > Sleep ... > #) > > David Shang