From norman.werner at web.de Sun Dec 4 10:03:17 2005 From: norman.werner at web.de (norman werner) Date: Sun, 04 Dec 2005 11:03:17 +0100 Subject: [cl-unification-devel] copy-env Message-ID: <700463679@web.de> Hello While writing a library with prolog like capabilities on top of cl-unification and a home brewn nondeterministic library I need a way to copy environments. There is a (internal) function copy-env in cl-unification. So I exported it. The problem is that this function returns a new environment which actually still shares objects with its original argument. Is this intentional? If not I propose the following (code will certainly contain bug, because i write it from memory only) (defun copy-env (e) (make-environment :frames (mapcar #'copy-frame (frames e)))) (defun copy-frame (f) (make-frame :bindings (mapcar #'copy-binding (binding f)))) (defun copy-binding (b) (mapcar #'(lambda (cell) (cons (car cell) (cdr cell))) b)) Norman ______________________________________________________________ Verschicken Sie romantische, coole und witzige Bilder per SMS! Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193 From jacobian at gmail.com Sun Dec 4 11:25:32 2005 From: jacobian at gmail.com (Gavin Mendel-Gleason) Date: Sun, 4 Dec 2005 11:25:32 +0000 Subject: [cl-unification-devel] copy-env In-Reply-To: <700463679@web.de> References: <700463679@web.de> Message-ID: Hello, I had the same problem and I don't think it was intentional. I think it is because it is mostly used for deterministic code. You don't really need to copy everything anyhow if you are using a standard unification algorithm since changes should be monotonic. You just need to branch. You can effect this with the following change: (defun make-shared-environment (env) (make-environment :frames (environment-frames env))) => (defun make-shared-environment (env) (make-environment :frames (cons (make-frame) (environment-frames env)))) Or some alteration that is similar that branches the environments at choice points. Gavin On 12/4/05, norman werner wrote: > Hello > > While writing a library with prolog like capabilities on top of cl-unification and a home brewn nondeterministic library > I need a way to copy environments. > > There is a (internal) function copy-env in cl-unification. So I exported it. > The problem is that this function returns a new environment which actually still shares > objects with its original argument. > > Is this intentional? > If not I propose the following (code will certainly contain bug, because i write it from memory only) > > (defun copy-env (e) > (make-environment :frames (mapcar #'copy-frame (frames e)))) > > (defun copy-frame (f) > (make-frame :bindings (mapcar #'copy-binding (binding f)))) > > (defun copy-binding (b) > (mapcar #'(lambda (cell) (cons (car cell) > (cdr cell))) b)) > > > > Norman > ______________________________________________________________ > Verschicken Sie romantische, coole und witzige Bilder per SMS! > Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193 > > _______________________________________________ > cl-unification-devel site list > cl-unification-devel at common-lisp.net > http://common-lisp.net/mailman/listinfo/cl-unification-devel > From marcoxa at cs.nyu.edu Sun Dec 4 15:30:40 2005 From: marcoxa at cs.nyu.edu (Marco Antoniotti) Date: Sun, 4 Dec 2005 10:30:40 -0500 Subject: [cl-unification-devel] copy-env In-Reply-To: References: <700463679@web.de> Message-ID: On Dec 4, 2005, at 6:25 AM, Gavin Mendel-Gleason wrote: > Hello, > > I had the same problem and I don't think it was intentional. I think > it is because it is mostly used for deterministic code. I had not given too much thought indeed to non-determinism. As per the actual copy operations, if people are interested in deep copy operations then they can be added, but I would keep them alongside the shallow copy operations. > > You don't really need to copy everything anyhow if you are using a > standard unification algorithm since changes should be monotonic. You > just need to branch. You can effect this with the following change: > > (defun make-shared-environment (env) > (make-environment :frames (environment-frames env))) > > => > > (defun make-shared-environment (env) > (make-environment :frames (cons > (make-frame) > (environment-frames env)))) > > Or some alteration that is similar that branches the environments at > choice points. MAKE-SHARED-ENVIRONMENT was provided as is because the augmentation of the environment (branches) was supposed to be done by other functions. But maybe ensuring that the extra frame is there is a good idea. Cheers -- Marco > > On 12/4/05, norman werner wrote: >> Hello >> >> While writing a library with prolog like capabilities on top of >> cl-unification and a home brewn nondeterministic library >> I need a way to copy environments. >> >> There is a (internal) function copy-env in cl-unification. So I >> exported it. >> The problem is that this function returns a new environment which >> actually still shares >> objects with its original argument. >> >> Is this intentional? >> If not I propose the following (code will certainly contain bug, >> because i write it from memory only) >> >> (defun copy-env (e) >> (make-environment :frames (mapcar #'copy-frame (frames e)))) >> >> (defun copy-frame (f) >> (make-frame :bindings (mapcar #'copy-binding (binding f)))) >> >> (defun copy-binding (b) >> (mapcar #'(lambda (cell) (cons (car cell) >> (cdr cell))) b)) >> >> >> >> Norman >> ______________________________________________________________ >> Verschicken Sie romantische, coole und witzige Bilder per SMS! >> Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193 >> >> _______________________________________________ >> cl-unification-devel site list >> cl-unification-devel at common-lisp.net >> http://common-lisp.net/mailman/listinfo/cl-unification-devel >> > _______________________________________________ > cl-unification-devel site list > cl-unification-devel at common-lisp.net > http://common-lisp.net/mailman/listinfo/cl-unification-devel > -- Marco Antoniotti http://bioinformatics.nyu.edu/~marcoxa NYU Courant Bioinformatics Group tel. +1 - 212 - 998 3488 715 Broadway 10th FL fax. +1 - 212 - 998 3484 New York, NY, 10003, U.S.A.