From: ········@gmail.com
Subject: temporal functions
Date: 
Message-ID: <1186094439.643900.319190@x40g2000prg.googlegroups.com>
I'm wondering if anyone has implemented a solution to create functions
that can remember their older versions.

So you can define a function like:
CL-USER> (deftfun ins-claim (x y) (+ x y))

CL-USER> (ins-claim 1 2)
3

;; The behavior of the claim function changes
CL-USER> (deftfun ins-claim (x y) (+ 100 x y))

CL-USER> (ins-claim 1 2)
103

;; An older claim from 2006 gets old behavior
CL-USER> (ins-claim 1 2 :date (encode-universal-time 0 0 0 2 8 2006))
3

The solution I implemented uses a global hash table/persistent-btree
and stores every version of a function. When a function is invoked,
the function uses its name and a timestamp to access the correct
behavior from the global hash table/btree.

This works ok for a regular function. The problem I'm having is, I
cannot use this method to implement CLOS methods. Specifically, I
cannot use the name of a CLOS method as a key to the hash tabe/
container.

So, I was wondering if anyone has implemented this kind of mechanism
for CLOS methods or has a suggestion on how to uniquely identify a
specific CLOS method.

Thank you for your time.
Raja R.

From: Pascal Costanza
Subject: Re: temporal functions
Date: 
Message-ID: <5hg5gcF36evi8U1@mid.individual.net>
········@gmail.com wrote:
> I'm wondering if anyone has implemented a solution to create functions
> that can remember their older versions.
> 
> So you can define a function like:
> CL-USER> (deftfun ins-claim (x y) (+ x y))
> 
> CL-USER> (ins-claim 1 2)
> 3
> 
> ;; The behavior of the claim function changes
> CL-USER> (deftfun ins-claim (x y) (+ 100 x y))
> 
> CL-USER> (ins-claim 1 2)
> 103
> 
> ;; An older claim from 2006 gets old behavior
> CL-USER> (ins-claim 1 2 :date (encode-universal-time 0 0 0 2 8 2006))
> 3
> 
> The solution I implemented uses a global hash table/persistent-btree
> and stores every version of a function. When a function is invoked,
> the function uses its name and a timestamp to access the correct
> behavior from the global hash table/btree.
> 
> This works ok for a regular function. The problem I'm having is, I
> cannot use this method to implement CLOS methods. Specifically, I
> cannot use the name of a CLOS method as a key to the hash tabe/
> container.

You could use the method metaobject as a key. See the 
find-method/add-method/remove-method triplet in ANSI Common Lisp. Maybe, 
it's possible to define your method combination and encode version 
information as a qualifier - see define-method-combination for this.

If the elements provided in ANSI Common Lisp are not sufficient, you may 
have to learn about the CLOS MOP to modify how generic functions and 
methods are treated.

Another option would be to take a look at ContextL: Here, you can 
associate method definitions with layers and switch layers on and off at 
runtime. It may be possible to make layers represent different versions 
of your methods, and then use ensure-active-layer to active the one you 
want. I haven't taken a closer look at how suitable ContextL would be 
for versioning, but I would be willing to assist you here in case you 
want to try this out. [I am the main author of ContextL.]


Pascal

-- 
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: ········@gmail.com
Subject: Re: temporal functions
Date: 
Message-ID: <1186158253.305722.227480@q75g2000hsh.googlegroups.com>
> You could use the method metaobject as a key. See the
> find-method/add-method/remove-method triplet in ANSI Common Lisp. Maybe,
> it's possible to define your method combination and encode version
> information as a qualifier - see define-method-combination for this.

'find-method' was what I was looking for.

> Another option would be to take a look at ContextL: Here, you can
> associate method definitions with layers and switch layers on and off at
> runtime. It may be possible to make layers represent different versions
> of your methods, and then use ensure-active-layer to active the one you
> want. I haven't taken a closer look at how suitable ContextL would be
> for versioning, but I would be willing to assist you here in case you
> want to try this out. [I am the main author of ContextL.]
>
> Pascal
>
> --
> My website:http://p-cos.net
> Common Lisp Document Repository:http://cdr.eurolisp.org
> Closer to MOP & ContextL:http://common-lisp.net/project/closer/


ContextL is interesting because it lets me deal with the problem at a
higher level. Instead of thinking about methods and behaviours, I can
think in terms of 'claim-layer-2007' and 'claim-layer-2006'.
Of course, I would still need to version the layer-names, but that is
easy. I will definitely check it out.

Thank you
Raja R.