Path: news.daimi.aau.dk!olevi From: olevi@daimi.aau.dk (Ole Villumsen) Newsgroups: comp.lang.beta Subject: Re: Two question on assignement Date: 14 Jun 1995 14:41:15 GMT Organization: DAIMI, Computer Science Dept. at Aarhus University Lines: 54 Message-ID: <3rmseb$4d6@belfort.daimi.aau.dk> References: <3rmqq1$3sj@belfort.daimi.aau.dk> NNTP-Posting-Host: lithium.daimi.aau.dk There are pretty easy solutions to your questions. Dario Gerosa writes: >Im implementing a Dictionary pattern with heterogeneous >keys and values (association). To return a value I need >to assign a less qualified object (ref-to-Object) to >a more qualified object (es. ref-to-Text). In theory >this is wrong. Does it exist a legal BETA method to do >that assignment ? In Beta, it is not wrong, provided the actual object is a text object. The method is the usual one: myObjRef[] -> myTextRef[]; The compiler will tell you that it inserts a runtime qua check (qualification check) (unless you use the -noquawarn switch). >Since I manage heterogeneous return value I have another >question. Can I know at run-time if an object support >a specific (by-name) attribute (message) ? >I can implement the same attribute (message) for each >pattern it is also a possible return value from >Dictionary, but sometimes it is useful know at run-time >the interface protocol of an object. You are absolutely right. What you can know (and what you need to know, really), is the qualification of an object to which you have a reference. (if myObjRef## <= text## then (* myObjRef is a text or a subpattern of text *) myObjRef[] -> myTextRef[]; ' more text' -> myTextRef.append; else (* myObjRef is not a text *) ... if); You need to do the assignment before you can use any of the attributes (methods) defined only for the lower class (text in the example). (If you simply wrote myObjRef.append the compiler would refuse to believe you.) Possible comparisons include: a## < b## a is a subclass of b? a## = b## a and b are the same class? a## <= b## a is the same class as b or a subclass of it? In the above each of a and b can be a pattern name or an object reference (or a pattern variable, for those who use those). Ole V.