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