From russell_mcmanus at yahoo.com Thu Jun 5 15:22:30 2008 From: russell_mcmanus at yahoo.com (Russell McManus) Date: Thu, 5 Jun 2008 08:22:30 -0700 (PDT) Subject: [cl-unification-devel] simple question Message-ID: <157136.98657.qm@web37102.mail.mud.yahoo.com> I'm just learning how to use cl-unification. I have written some code that doesn't work the way I expect, but of course this probably means that my expectations are wrong. Can one of the cl-unification gurus take a look, and let me know what I'm doing wrong? Thanks, -russ (defpackage :unification-demo (:use :cl :CL.EXT.DACF.UNIFICATION)) (in-package :unification-demo) (declaim (optimize (debug 3) (speed 0))) (defclass call-expr () ((rator :reader rator) (rands :reader rands))) (defmethod initialize-instance :after ((call-expr call-expr) &key form) (with-slots (rator rands) call-expr (destructuring-bind (rator-form &rest rand-forms) form (setf rator rator-form rands (mapcar (lambda (rand-form) (parse-expr rand-form)) rand-forms))))) (defclass var-ref () ((var :initarg :var :reader var))) (defclass let-binding () ((var :reader let-binding-var :initarg :var) (expr :reader let-binding-expr :initarg :expr))) (defmethod initialize-instance :after ((let-binding let-binding) &key form) (with-slots (var expr) let-binding (destructuring-bind (var-form expr-form) form (setf var var-form expr (parse-expr expr-form))))) (defclass let-expr () ((bindings :reader bindings) (body :reader body))) (defmethod initialize-instance :after ((let-expr let-expr) &key form) (with-slots (bindings body) let-expr (destructuring-bind (binding-forms body-form) (cdr form) (setf bindings (mapcar (lambda (form) (make-instance 'let-binding :form form)) binding-forms) body (parse-expr body-form))))) (defun parse-expr (form) (flet ((car-match (indicator) (and (consp form) (eql (car form) indicator))) (constant-match () (or (stringp form) (numberp form)))) (cond ((constant-match) form) ((car-match 'let) (make-instance 'let-expr :form form)) ((car-match 'lambda) (make-instance 'lambda-expr :form form)) ((consp form) (make-instance 'call-expr :form form)) ((symbolp form) (make-instance 'var-ref :var form)) (t (error "unhandled form ~A" form))))) ;; this works (find-variable-value '?bs (unify #T(let-expr bindings ?bs) (parse-expr '(let ((x 1) (y 2)) (+ x y))))) ;; this fails, why? (find-variable-value '?b (unify #T(let-expr bindings (list ?b &rest ?bs)) (parse-expr '(let ((x 1) (y 2)) (+ x y))))) From russell_mcmanus at yahoo.com Thu Jun 5 21:38:58 2008 From: russell_mcmanus at yahoo.com (Russell McManus) Date: Thu, 5 Jun 2008 14:38:58 -0700 (PDT) Subject: [cl-unification-devel] a simpler example Message-ID: <935470.52246.qm@web37108.mail.mud.yahoo.com> Here are some examples: ;; this works (find-variable-value '?s (unify #T(list ?f ?s) '(a (b c)))) ;; this works (find-variable-value '?s1 (unify #T(list ?f (?s1 ?s2)) '(a (b c)))) ;; this fails (find-variable-value '?s1 (unify #T(list ?f (list ?s1 ?s2)) '(a (b c)))) I was expecting the meaning of LIST to be the same whether it is encountered at top level in a template, or at a nested level. Is this a bug, or are my expectations wrong? -russ From marcoxa at cs.nyu.edu Tue Jun 10 08:51:44 2008 From: marcoxa at cs.nyu.edu (Marco Antoniotti) Date: Tue, 10 Jun 2008 11:51:44 +0300 Subject: [cl-unification-devel] a simpler example In-Reply-To: <935470.52246.qm@web37108.mail.mud.yahoo.com> References: <935470.52246.qm@web37108.mail.mud.yahoo.com> Message-ID: <0A29C690-7DE4-43E4-8A86-2AFD97585686@cs.nyu.edu> On Jun 6, 2008, at 24:38 , Russell McManus wrote: > > Here are some examples: > > ;; this works > (find-variable-value > '?s > (unify #T(list ?f ?s) '(a (b c)))) Yes. > > ;; this works > (find-variable-value > '?s1 > (unify #T(list ?f (?s1 ?s2)) '(a (b c)))) Yes. > > ;; this fails > (find-variable-value > '?s1 > (unify #T(list ?f (list ?s1 ?s2)) '(a (b c)))) As it should. What you want is (unify #T(list ?f #T(list ?s1 ?s2)) '(a (b c))) In your case you are trying to unify a template of type LIST with a variable in FIRST and a list (LIST ?s1 ?s2) in SECOND. The second element cannot unify with (B C), hence the failure. > > I was expecting the meaning of LIST to be the same whether > it is encountered at top level in a template, or at a nested level. > > Is this a bug, or are my expectations wrong? Sorry. It is your expectations. If you look at the most general syntax for templates, you will see that it is #T( . ). This is because it would be a nightmare to do otherwise. Suppose you have a (unify #T(list 42 (foo)) (list 42 (list 'foo))) should unify. But is next you do (defstruct foo a s d) then (unify #T(list 42 (foo)) (list 42 (list 'foo))) may or may not unify pending interpretation. Hope this clarifies things. Let me know if there are other pitfalls or bugs in the code. Cheers Marco > -- Marco Antoniotti From russell_mcmanus at yahoo.com Wed Jun 11 14:04:18 2008 From: russell_mcmanus at yahoo.com (Russell McManus) Date: Wed, 11 Jun 2008 07:04:18 -0700 (PDT) Subject: [cl-unification-devel] a simpler example Message-ID: <759139.75164.qm@web37102.mail.mud.yahoo.com> I'm pretty sure that I tried repeating the #T before sending my first email, but it failed with an error. I just tried again on sbcl 1.0.10.16 and got the following: (unify #T(list ?f #T(list ?s1 ?s2)) '(a (b c))) Cannot unify two different symbols: B MAKE-TEMPLATE. [Condition of type CL.EXT.DACF.UNIFICATION::UNIFICATION-FAILURE] Restarts: 0: [ABORT] Return to SLIME's top level. 1: [TERMINATE-THREAD] Terminate this thread (#) Any ideas what I should try next? -russ ----- Original Message ---- > From: Marco Antoniotti > To: cl-unification-devel at common-lisp.net > Sent: Tuesday, June 10, 2008 3:51:44 AM > Subject: Re: [cl-unification-devel] a simpler example > > > On Jun 6, 2008, at 24:38 , Russell McManus wrote: > > > > > Here are some examples: > > > > ;; this works > > (find-variable-value > > '?s > > (unify #T(list ?f ?s) '(a (b c)))) > > Yes. > > > > > ;; this works > > (find-variable-value > > '?s1 > > (unify #T(list ?f (?s1 ?s2)) '(a (b c)))) > > Yes. > > > > > > ;; this fails > > (find-variable-value > > '?s1 > > (unify #T(list ?f (list ?s1 ?s2)) '(a (b c)))) > > As it should. What you want is > > (unify #T(list ?f #T(list ?s1 ?s2)) '(a (b c))) > > In your case you are trying to unify a template of type LIST with a > variable in FIRST and a list (LIST ?s1 ?s2) in SECOND. The second > element cannot unify with (B C), hence the failure. > > > > > I was expecting the meaning of LIST to be the same whether > > it is encountered at top level in a template, or at a nested level. > > > > Is this a bug, or are my expectations wrong? > > Sorry. It is your expectations. If you look at the most general > syntax for templates, you will see that it is #T(. > ). This is because it would be a nightmare to do otherwise. > > > Suppose you have a > > (unify #T(list 42 (foo)) (list 42 (list 'foo))) > > should unify. But is next you do > > (defstruct foo a s d) > > then > > (unify #T(list 42 (foo)) (list 42 (list 'foo))) > > may or may not unify pending interpretation. > > Hope this clarifies things. Let me know if there are other pitfalls > or bugs in the code. > > Cheers > > Marco > > > > > > -- > Marco Antoniotti > > > _______________________________________________ > cl-unification-devel site list > cl-unification-devel at common-lisp.net > http://common-lisp.net/mailman/listinfo/cl-unification-devel From russell_mcmanus at yahoo.com Wed Jun 11 19:10:16 2008 From: russell_mcmanus at yahoo.com (Russell McManus) Date: Wed, 11 Jun 2008 12:10:16 -0700 (PDT) Subject: [cl-unification-devel] a simpler example Message-ID: <683707.84330.qm@web37106.mail.mud.yahoo.com> I tried the attached version, and the problem persists. Thanks for looking into it, -russ ----- Original Message ---- > From: Marco Antoniotti > To: cl-unification-devel at common-lisp.net > Cc: Russell McManus > Sent: Wednesday, June 11, 2008 11:02:56 AM > Subject: Re: [cl-unification-devel] a simpler example > > There may be a misalignment with my version (which works on LW) and > the CVS version, or it may be a problem which SBCL raises due to its > version (more strict) of MAKE-LOAD-FORM. > > I'll look into it. > > Thanks for raising the issue. > > Meanwhile try the version attached on SBCL. > > Cheers > -- > Marco > > > > > > > On Jun 11, 2008, at 16:04 , Russell McManus wrote: > > > I'm pretty sure that I tried repeating the #T before sending my > > first email, but it failed with an error. > > > > I just tried again on sbcl 1.0.10.16 and got the following: > > > > (unify #T(list ?f #T(list ?s1 ?s2)) '(a (b c))) > > > > > > Cannot unify two different symbols: B MAKE-TEMPLATE. > > [Condition of type CL.EXT.DACF.UNIFICATION::UNIFICATION-FAILURE] > > > > Restarts: > > 0: [ABORT] Return to SLIME's top level. > > 1: [TERMINATE-THREAD] Terminate this thread (# > > "worker" {1008AB0C91}>) > > > > Any ideas what I should try next? > > > > -russ > > > > > > > > ----- Original Message ---- > >> From: Marco Antoniotti > >> To: cl-unification-devel at common-lisp.net > >> Sent: Tuesday, June 10, 2008 3:51:44 AM > >> Subject: Re: [cl-unification-devel] a simpler example > >> > >> > >> On Jun 6, 2008, at 24:38 , Russell McManus wrote: > >> > >>> > >>> Here are some examples: > >>> > >>> ;; this works > >>> (find-variable-value > >>> '?s > >>> (unify #T(list ?f ?s) '(a (b c)))) > >> > >> Yes. > >> > >>> > >>> ;; this works > >>> (find-variable-value > >>> '?s1 > >>> (unify #T(list ?f (?s1 ?s2)) '(a (b c)))) > >> > >> Yes. > >> > >> > >>> > >>> ;; this fails > >>> (find-variable-value > >>> '?s1 > >>> (unify #T(list ?f (list ?s1 ?s2)) '(a (b c)))) > >> > >> As it should. What you want is > >> > >> (unify #T(list ?f #T(list ?s1 ?s2)) '(a (b c))) > >> > >> In your case you are trying to unify a template of type LIST with a > >> variable in FIRST and a list (LIST ?s1 ?s2) in SECOND. The second > >> element cannot unify with (B C), hence the failure. > >> > >>> > >>> I was expecting the meaning of LIST to be the same whether > >>> it is encountered at top level in a template, or at a nested level. > >>> > >>> Is this a bug, or are my expectations wrong? > >> > >> Sorry. It is your expectations. If you look at the most general > >> syntax for templates, you will see that it is #T(. > >> ). This is because it would be a nightmare to do otherwise. > >> > >> > >> Suppose you have a > >> > >> (unify #T(list 42 (foo)) (list 42 (list 'foo))) > >> > >> should unify. But is next you do > >> > >> (defstruct foo a s d) > >> > >> then > >> > >> (unify #T(list 42 (foo)) (list 42 (list 'foo))) > >> > >> may or may not unify pending interpretation. > >> > >> Hope this clarifies things. Let me know if there are other pitfalls > >> or bugs in the code. > >> > >> Cheers > >> > >> Marco > >> > >> > >>> > >> > >> -- > >> Marco Antoniotti > >> > >> > >> _______________________________________________ > >> cl-unification-devel site list > >> cl-unification-devel at common-lisp.net > >> http://common-lisp.net/mailman/listinfo/cl-unification-devel > > > > -- > Marco Antoniotti From marcoxa at cs.nyu.edu Thu Jun 12 14:44:06 2008 From: marcoxa at cs.nyu.edu (Marco Antoniotti) Date: Thu, 12 Jun 2008 16:44:06 +0200 Subject: [cl-unification-devel] a simpler example In-Reply-To: <683707.84330.qm@web37106.mail.mud.yahoo.com> References: <683707.84330.qm@web37106.mail.mud.yahoo.com> Message-ID: <1040C302-6A12-4A69-846C-A658553C7099@cs.nyu.edu> Thanks Russell, I think I know where the problem is and I think that, while the example works on LW and other Lisps, the problem signaled by SBCL should be solved. I'll definitively look into it. Cheers Marco On Jun 11, 2008, at 21:10 , Russell McManus wrote: > I tried the attached version, and the problem persists. > > Thanks for looking into it, > -russ > > ----- Original Message ---- >> From: Marco Antoniotti >> To: cl-unification-devel at common-lisp.net >> Cc: Russell McManus >> Sent: Wednesday, June 11, 2008 11:02:56 AM >> Subject: Re: [cl-unification-devel] a simpler example >> >> There may be a misalignment with my version (which works on LW) and >> the CVS version, or it may be a problem which SBCL raises due to its >> version (more strict) of MAKE-LOAD-FORM. >> >> I'll look into it. >> >> Thanks for raising the issue. >> >> Meanwhile try the version attached on SBCL. >> >> Cheers >> -- >> Marco >> >> >> >> >> >> >> On Jun 11, 2008, at 16:04 , Russell McManus wrote: >> >>> I'm pretty sure that I tried repeating the #T before sending my >>> first email, but it failed with an error. >>> >>> I just tried again on sbcl 1.0.10.16 and got the following: >>> >>> (unify #T(list ?f #T(list ?s1 ?s2)) '(a (b c))) >>> >>> >>> Cannot unify two different symbols: B MAKE-TEMPLATE. >>> [Condition of type CL.EXT.DACF.UNIFICATION::UNIFICATION-FAILURE] >>> >>> Restarts: >>> 0: [ABORT] Return to SLIME's top level. >>> 1: [TERMINATE-THREAD] Terminate this thread (# >>> "worker" {1008AB0C91}>) >>> >>> Any ideas what I should try next? >>> >>> -russ >>> >>> >>> >>> ----- Original Message ---- >>>> From: Marco Antoniotti >>>> To: cl-unification-devel at common-lisp.net >>>> Sent: Tuesday, June 10, 2008 3:51:44 AM >>>> Subject: Re: [cl-unification-devel] a simpler example >>>> >>>> >>>> On Jun 6, 2008, at 24:38 , Russell McManus wrote: >>>> >>>>> >>>>> Here are some examples: >>>>> >>>>> ;; this works >>>>> (find-variable-value >>>>> '?s >>>>> (unify #T(list ?f ?s) '(a (b c)))) >>>> >>>> Yes. >>>> >>>>> >>>>> ;; this works >>>>> (find-variable-value >>>>> '?s1 >>>>> (unify #T(list ?f (?s1 ?s2)) '(a (b c)))) >>>> >>>> Yes. >>>> >>>> >>>>> >>>>> ;; this fails >>>>> (find-variable-value >>>>> '?s1 >>>>> (unify #T(list ?f (list ?s1 ?s2)) '(a (b c)))) >>>> >>>> As it should. What you want is >>>> >>>> (unify #T(list ?f #T(list ?s1 ?s2)) '(a (b c))) >>>> >>>> In your case you are trying to unify a template of type LIST with a >>>> variable in FIRST and a list (LIST ?s1 ?s2) in SECOND. The second >>>> element cannot unify with (B C), hence the failure. >>>> >>>>> >>>>> I was expecting the meaning of LIST to be the same whether >>>>> it is encountered at top level in a template, or at a nested >>>>> level. >>>>> >>>>> Is this a bug, or are my expectations wrong? >>>> >>>> Sorry. It is your expectations. If you look at the most general >>>> syntax for templates, you will see that it is #T(. >>>> ). This is because it would be a nightmare to do otherwise. >>>> >>>> >>>> Suppose you have a >>>> >>>> (unify #T(list 42 (foo)) (list 42 (list 'foo))) >>>> >>>> should unify. But is next you do >>>> >>>> (defstruct foo a s d) >>>> >>>> then >>>> >>>> (unify #T(list 42 (foo)) (list 42 (list 'foo))) >>>> >>>> may or may not unify pending interpretation. >>>> >>>> Hope this clarifies things. Let me know if there are other >>>> pitfalls >>>> or bugs in the code. >>>> >>>> Cheers >>>> >>>> Marco >>>> >>>> >>>>> >>>> >>>> -- >>>> Marco Antoniotti >>>> >>>> >>>> _______________________________________________ >>>> cl-unification-devel site list >>>> cl-unification-devel at common-lisp.net >>>> http://common-lisp.net/mailman/listinfo/cl-unification-devel >>> >> >> -- >> Marco Antoniotti > > _______________________________________________ > cl-unification-devel site list > cl-unification-devel at common-lisp.net > http://common-lisp.net/mailman/listinfo/cl-unification-devel -- Marco Antoniotti From marcoxa at cs.nyu.edu Wed Jun 11 16:04:02 2008 From: marcoxa at cs.nyu.edu (Marco Antoniotti) Date: Wed, 11 Jun 2008 16:04:02 -0000 Subject: [cl-unification-devel] a simpler example In-Reply-To: <759139.75164.qm@web37102.mail.mud.yahoo.com> References: <759139.75164.qm@web37102.mail.mud.yahoo.com> Message-ID: There may be a misalignment with my version (which works on LW) and the CVS version, or it may be a problem which SBCL raises due to its version (more strict) of MAKE-LOAD-FORM. I'll look into it. Thanks for raising the issue. Meanwhile try the version attached on SBCL. Cheers -- Marco -------------- next part -------------- A non-text attachment was scrubbed... Name: cl-unification.zip Type: application/zip Size: 511454 bytes Desc: not available URL: -------------- next part -------------- On Jun 11, 2008, at 16:04 , Russell McManus wrote: > I'm pretty sure that I tried repeating the #T before sending my > first email, but it failed with an error. > > I just tried again on sbcl 1.0.10.16 and got the following: > > (unify #T(list ?f #T(list ?s1 ?s2)) '(a (b c))) > > > Cannot unify two different symbols: B MAKE-TEMPLATE. > [Condition of type CL.EXT.DACF.UNIFICATION::UNIFICATION-FAILURE] > > Restarts: > 0: [ABORT] Return to SLIME's top level. > 1: [TERMINATE-THREAD] Terminate this thread (# "worker" {1008AB0C91}>) > > Any ideas what I should try next? > > -russ > > > > ----- Original Message ---- >> From: Marco Antoniotti >> To: cl-unification-devel at common-lisp.net >> Sent: Tuesday, June 10, 2008 3:51:44 AM >> Subject: Re: [cl-unification-devel] a simpler example >> >> >> On Jun 6, 2008, at 24:38 , Russell McManus wrote: >> >>> >>> Here are some examples: >>> >>> ;; this works >>> (find-variable-value >>> '?s >>> (unify #T(list ?f ?s) '(a (b c)))) >> >> Yes. >> >>> >>> ;; this works >>> (find-variable-value >>> '?s1 >>> (unify #T(list ?f (?s1 ?s2)) '(a (b c)))) >> >> Yes. >> >> >>> >>> ;; this fails >>> (find-variable-value >>> '?s1 >>> (unify #T(list ?f (list ?s1 ?s2)) '(a (b c)))) >> >> As it should. What you want is >> >> (unify #T(list ?f #T(list ?s1 ?s2)) '(a (b c))) >> >> In your case you are trying to unify a template of type LIST with a >> variable in FIRST and a list (LIST ?s1 ?s2) in SECOND. The second >> element cannot unify with (B C), hence the failure. >> >>> >>> I was expecting the meaning of LIST to be the same whether >>> it is encountered at top level in a template, or at a nested level. >>> >>> Is this a bug, or are my expectations wrong? >> >> Sorry. It is your expectations. If you look at the most general >> syntax for templates, you will see that it is #T(. >> ). This is because it would be a nightmare to do otherwise. >> >> >> Suppose you have a >> >> (unify #T(list 42 (foo)) (list 42 (list 'foo))) >> >> should unify. But is next you do >> >> (defstruct foo a s d) >> >> then >> >> (unify #T(list 42 (foo)) (list 42 (list 'foo))) >> >> may or may not unify pending interpretation. >> >> Hope this clarifies things. Let me know if there are other pitfalls >> or bugs in the code. >> >> Cheers >> >> Marco >> >> >>> >> >> -- >> Marco Antoniotti >> >> >> _______________________________________________ >> cl-unification-devel site list >> cl-unification-devel at common-lisp.net >> http://common-lisp.net/mailman/listinfo/cl-unification-devel > -- Marco Antoniotti