Re: Initialization
- From: Rainer Joswig <joswig@xxxxxxx>
- Date: Mon, 27 Mar 2006 22:27:15 +0200
In article <1143489645.775745.67760@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"Rob Thorpe" <robert.thorpe@xxxxxxxxxxxx> wrote:
I don't think that it is the best solution though. In C++ Scopeguard
you can write code like this:-
void User::AddFriend(User& newFriend)
{
friends_.push_back(&newFriend); // Add user
ScopeGuard guard = MakeObjGuard( // register pop_back as undo
friends_, &UserCont::pop_back);
pDB_->AddFriend(GetName(), newFriend.GetName()); // Add to database
guard.Dismiss(); // dismiss undo
}
That is the undo code and guarded code can be written as normal code.
The code does not have to be structured in any particular way as it
does with my blocks-with-undos above. The capability to add undos to
actions is available everywhere.
My question is: Is it possible to do the same thing with lisp, and if
so how?
And, is it a useful thing to do or are there reasons to avoid it?
Personally I would think in two directions.
a) I would use a Lisp with transactions (say, a relational
Lisp like AP5).
Btw., for those interested in language comparisons,
they may read this classic paper:
http://www.cs.chalmers.se/Cs/Research/Functional/Fudgets/haskell-vs-ada-abstract.html
Note the performance of the users of 'Relational Lisp'. ;-)
It is worth for a good laughs, too.
b) I would use CLOS' Generic Functions with a special
Method Combination.
User code might look like this:
(defgeneric do-something-possibly-failing (user registry)
(:method-combination :recoverable))
(defmethod do-something-possibly-failing
((user webserver-user) (registry server-registry))
(do-something user registry))
(defmethod do-something-possibly-failing :save
((user webserver-user) (registry server-registry))
...)
(defmethod do-something-possibly-failing :restore-on-error
((user webserver-user) (registry server-registry))
...)
I would implement the method combination with some
special error handler wrapping the methods.
For some inspiration how to write these method combinations
(beware, this is advanced CLOS) see this
example how to implement an Eiffel-like Design-by-Contract
method combination in Common Lisp:
http://www.gauss.muc.de/tools/dbc/dbc-intro.html
--
http://lispm.dyndns.org/
.
- References:
- Initialization
- From: Rob Thorpe
- Initialization
- Prev by Date: Re: Initialization
- Next by Date: Re: How to convert data for use by Ironclad?
- Previous by thread: Re: Initialization
- Next by thread: Re: Initialization
- Index(es):
Relevant Pages
|