[rucksack-devel] Re: rucksack-devel Digest, Vol 2, Issue 1

Ken Tilton kentilton at gmail.com
Thu Jun 15 16:16:49 UTC 2006


> From: "Aycan iRiCAN" <aycan.irican at core.gen.tr>
> Subject: [rucksack-devel] Abstracting services
> To: rucksack-devel at common-lisp.net
> Message-ID: <87ac8emtws.fsf at core.gen.tr>
> Content-Type: text/plain; charset="us-ascii"
>
> Hi,
>
> I'm trying design a library of services that uses rucksack as a
> persistent store and I want to get your opinions about my problem.
>
> Think of an accounting service that programmers can use it via generic
> methods. This is a service for multiple usage, so it needs to gather
> some knowledge like where should accounts be stored, by which
> mechanism etc. I tried to think the simplest case, a path variable is
> sufficent for accounting to work with rucksack.
>
> My first attempt was defining methods so that they get the values via
> parameters.
>
> (defclass account ()
>   ((username) (password))
>   (:metaclass persistent-class))
>
> (defmethod make-account (uname pass rucksack)
>   (add-rucksack-root (make-instance 'account ...) rucksack))
>
> (defmethod list-accounts (... rucksack) ...)
>
> So a programmer can be able to use this package as:
>
> (in-package :p1)
> (defparameter *db-path* "/tmp/p1")
>
> (defun create-an-account-with-a-form (form)
>   (with-rucksack (rs *db-path*)
>     (with-transaction ()
>       (make-account (un form) (pw form) rs))))
>
> But I want to make more abstraction so that a program that uses this
> library doesn't know about internals of accounting package or
> persistent store package. I tried to find a better scenario and wrote
> the ideal program:
>
> (in-package :p1)
> (defparameter *db-path "/tmp/p1")
>
> (defun create-an-account-with-a-form (form)
>   (with-accounting *db-path*
>       (make-account (un form) (pw form))))
>
> This way is better because persistence and transactions are
> transparent to the programmer. But wait, to be able to reach this
> simplicity, I need to redefine my methods.
>
> (defmethod make-account (uname pass)
>   (add-rucksack-root (make-instance 'account ...) xxxx))
>
> But I can't, because these methods needs to know the rucksack instance
> that they operate on (above shown with xxxx).
>
> What do you think about this? Is this kind of abstraction possible?


Make that *xxxx* (or *sack* or *db* or *db-root*) and you are good to go.
ie, This is a classic use for special variables, in this case bound by your
with-accounting macro.

If I understood you. :)

kenny
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/rucksack-devel/attachments/20060615/34be400b/attachment.html>


More information about the rucksack-devel mailing list