Path: news.daimi.aau.dk!news.uni-c.dk!sunic!sunic.sunet.se!trane.uninett.no!Norway.EU.net!EU.net!howland.reston.ans.net!news.moneng.mei.com!uwm.edu!lll-winken.llnl.gov!venus.sun.com!news2me.EBay.Sun.COM!engnews2.Eng.Sun.COM!olm From: olm@Eng.Sun.COM (Ole Lehrmann Madsen) Newsgroups: comp.object,comp.lang.beta Subject: Re: Beta example (Was: Pointers to classes?) Date: 28 Jun 1995 06:47:02 GMT Organization: Sun Microsystems Inc., Mountain View, CA Lines: 126 Message-ID: <3sqtt6$qtf@engnews2.Eng.Sun.COM> References: <3s80ek$rou@horus.infinet.com> <3s8k3t$n6e@engnews2.Eng.Sun.COM> <3sdvam$pfg@engnews2.Eng.Sun.COM> NNTP-Posting-Host: det.eng.sun.com X-Newsreader: NN version 6.5.0 #21 (NOV) Xref: news.daimi.aau.dk comp.object:32271 comp.lang.beta:427 Scott Wheeler writes: >In Article <3sdvam$pfg@engnews2.Eng.Sun.COM> Ole Lehrmann Madsen >writes: >>...[text omitted] >>I can also recommend that you obtain a personal edition of the Mjolner >>Beta System from Mjolner Informatics. I think the current price >>is only US$ 60 plus shipping. Contact addresses are given below. >> >>Here is, however, a small complete Beta program that can be compiled >>an run. The example and its output is given after the following >>(long) explanation. >Thanks for the example, Ole. I hadn't realised there was a "personal" >version available, and I'll look into getting that. >[In library text] >> list: (# ... >> scan: >> (# current: ^element >> do loop: >> (if moreElements then >> nextElement[] -> current[]; >> inner; >> restart loop >> if) >> #); >> #) >[In the example program] >> courses.scan(#do current.display; newline #); >I don't entirely follow the way "inner" is used here: I'd have thought >that it would refer to the body of any extension to "scan" defined in a >descendant of "list". Instead, if I understand correctly, here you are >making up an anonymous pattern (a singleton?), which is then acted on >by the scan pattern. It looks reminiscent of the use of lamdas in Lisp >- can you store this anonymous pattern in a variable for separate use? You seem to "follow' correctly what is going on. The problems might be due to my attempt to explain too much in a small example. Basically INNER is used to combine do-parts of patterns. Consider A: (# ... do imp1; inner; imp2 #); B: A(# ... do imp3; inner; imp4; #); Execution of an instance of B results in the following actions being executed imp1; imp3; ; imp4; imp2 No virtual patterns are used here. Inner is the basic mechanism for combining do-parts of a super pattern and its subpatterns. You may compare it to a lambda parameter. You may also think of inner as an anonymous virtual function of A. The scan example is just making use of this basic mechanism. Note, however, than scan is a local pattern of a list object. In general Beta supports nested patterns in the form of block structure The inner mechanism is also used to combine do-parts of virtual functions. Consider T: (# V:< (# ... do imp1; inner; imp2 #); ... #); TT: T(# V::< (# ... do imp3; inner; imp4; #); ... #); S: ^TT Execution of S.V will as above result in execution of imp1; imp3; ; imp4; imp2 (It is assumed that S refers to a TT-instance and not a subpattern of TT. If S refers some subpattern of TT, then inner in TT will not be empty) The TT::V is considered a subpattern of the T::V. In fact the following is an alternative way of obtaining the same effect: T: (# V:< A; ... #); TT: T(# V::< B; ... #); I.e. virtual patterns may be qualified by named patterns in general. This makes it possible to bind virtual functions to non-local functions and is essential when using virtual patterns to define parameterized class pattersn. You also ask if an anonymous pattern like R.scan(# ... #) can be stored in a value for future use. The answer should have been yes, but due to a stupid mistake in the Beta grammar this is currently not possible. A future version of the compiler will e.g. allow R: ##object R.scan(# ... #)## -> R## and then R may be executed when needed. You will currently have to declare it as a pattern F: R.scan(# ... #) and then do F## -> R## There are no problems in implementing the anonymous version. It is only a syntactic problem since the basic mechanism is the same as for patterns. It will be fixed the next time we update the grammar. ---olm >Scott