Re: Initialization



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/
.



Relevant Pages

  • Re: Registry cleaner ?
    ... Unknown typed: ... Did it ever occur to you your UNDO isn't needed ... There are some rather obscure parts of the registry that might require a lookup, but it's not what one would call rocket science. ... cleaners and to insult all who disagree with you. ...
    (microsoft.public.windowsxp.basics)
  • Re: Registry Backup
    ... entries from the Registry. ... If you can't undo those deletes, ... Restore back to a point before you installed Regseeker. ... I wasn't having the problem until I "cleaned" the registry, ...
    (microsoft.public.windowsxp.general)
  • Re: Help with registry key
    ... Install stuff using compatability wizard in future. ... If source files are on a HD make sure you undo it as well. ... >>Has that Registry program got an 'undo' option? ... > | I manually reset the value to "Microsoft Windows XP" using regedit but I ...
    (microsoft.public.windowsxp.configuration_manage)
  • Re: Changing icons
    ... I will be willing to work in the registry as ... let's assume that your icons are in a folder named C:\MyIcons. ... Key in the fully-qualified filename of the icon you wish to use ... > will create a .reg file that can be imported to undo the changes. ...
    (microsoft.public.office.misc)
  • Re: How to comment (and uncomment) blocks in SLIME
    ... > out (and undo this operation) a few lines. ... > commenting/uncommenting lines of Lisp code. ... Also note that commenting out several lines is less common in Common ... Lisp than in ALGOLish languages because you can comment out distinct ...
    (comp.lang.lisp)