Path: news.daimi.aau.dk!jlk From: jlk@daimi.aau.dk (Jorgen Lindskov Knudsen) Newsgroups: comp.lang.beta Subject: Re: leaving a pattern? Date: 21 Aug 1997 21:25:44 GMT Organization: DAIMI, Computer Science Dept. at Aarhus University Lines: 90 Distribution: all Message-ID: <5tiboo$2h6$1@gjallar.daimi.aau.dk> References: <5tguc5$r4n$1@gjallar.daimi.aau.dk> Reply-To: jlknudsen@daimi.aau.dk (Jorgen Lindskov Knudsen) NNTP-Posting-Host: adelphi.daimi.aau.dk X-Newsreader: NN version 6.5.1 (NOV) Xref: news.daimi.aau.dk comp.lang.beta:11244 In <5tguc5$r4n$1@gjallar.daimi.aau.dk> jojo@daimi.aau.dk (Johanna Wiederhold) writes: >transaction: > (# > abort :(# do leave transaction #); > ... > do > INNER > #); >The compiler comes with the following error message: >leave transaction >***** "leave P" or "restart P", where "P" is a pattern, > is only legal in the do-part of "P" > >If you know a solution, let me know. >Johanna (email: jojo@daimi.aau.dk) >-- >Johanna Wiederhold >Comp. Sci. Department of Aarhus University, Denmark. There is no real good solution to this. Why does this not work as one might expect (as you definitely thought). Let us elaborate a little on your example: (# myTrans: @transaction; ... do ... myTrans.abort; ... #) This shows why...when executing myTrans.about, myTrans is not on the execution stack, leaving the semantics of 'leave transaction' undefined (what should it 'leave'). This restriction in the compiler is inserted to avoid these (and similar) problems. An alternative would have been to allow the construct, but then insert a run-time test for these improper usages. This is duable, but would imply overhead on all 'leave' (and 'restart') imperatives. So what could you do? Depends on your situation, but often one can do something like: transaction: (# aborted: @boolean; abort :(# do true->aborted #); ... do INNER #); and then a startegic places in the 'transaction' implementation have tests for the 'aborted' attribute. In your case, I doubt, however, that this is doable. Another solution is to leave a little more work to the users of 'transaction' by: transaction: (# abort:< (# do INNER #); ... do INNER #); and then demand all users of 'transaction' to use the following design pattern: do ... myTrans: transaction (# abort:: (# do leane myTrans #) ... #); ... This is very similar to what you intend with the original proposal. Regards, Jorgen Lindskov Knudsen -- * Jorgen Lindskov Knudsen | Phone: +45 8942 3188 * * Dept. of Computer Science | Direct: +45 8942 3233 * * University of Aarhus | Fax: +45 8942 3255 * * Ny Munkegade, Building 540 | GSM: +45 2099 7357 *