Newsgroups: comp.lang.beta Path: news.daimi.aau.dk!news.uni-c.dk!nntp-oslo.UNINETT.no!nntp-trd.UNINETT.no!online.no!Norway.EU.net!EU.net!newsfeed.internetmci.com!news.mathworks.com!uunet!in2.uu.net!nwnews.wa.com!nwfocus.wa.com!news-wa16!lego.wes.mot.com!mothost.mot.com!schbbs!news From: shang@corp.mot.com (David L. Shang) Subject: Re: THIS and COMPONENTs Reply-To: shang@corp.mot.com Organization: MOTOROLA Date: Mon, 29 Jul 1996 15:00:24 GMT Message-ID: <1996Jul29.150024.13027@schbbs.mot.com> References: <4tadg9$smm@gjallar.daimi.aau.dk> Sender: news@schbbs.mot.com (SCHBBS News Account) Nntp-Posting-Host: 129.188.128.126 Lines: 98 In article <4tadg9$smm@gjallar.daimi.aau.dk> "S\xren Brandt" writes: > Ah, well. It seems that I misunderstood your request. Below is the requested > "objectToComponent". Please ignore that objectToComponent exploits undocumented > low-level features of the compiler. If the entered object is not a component, > "objectToComponent" will return NONE. > > INCLUDE '~beta/sysutils/v1.4/objinterface'; > ---lib:attributes--- > objectToComponent: > (# o: ^Object; > c: ^|Object; > ato: @addressToObject; > enter o[] > do (if o[]<>NONE then > (if (o[]->getGCField)//-6 then > (if ((@@o->tos'%AdrGetLong')-24->tos'%AdrGetLong') > //ComponentPTvalue then > (@@c,(@@o->tos'%AdrGetLong')-24)->assignRef > if); > if); > if); > exit c[] > #); 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? 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