Help with error :value Nil is not of expected type structure

Discussion of Common Lisp
Post Reply
jasmeetsajmani
Posts: 3
Joined: Tue Mar 30, 2010 11:16 am

Help with error :value Nil is not of expected type structure

Post by jasmeetsajmani » Tue Mar 30, 2010 11:24 am

Hi,

I am new to Common lisp and I am developing a model for ACT-UP. It involves making chunks that can be learned and then they are retrieved to solve a problem. Anyways my problem lies with this lisp error I keep on getting; my code goes something like this -

Code: Select all

(load "act-up.lisp")

(require "act-up" "act-up.lisp")
(use-package :act-up)

;;;; chunk-types
(define-chunk-type additionfact addend1 addend2 sum)
(define-chunk-type carryfact total rem carry)

;;;; defining chunks here

;;;; committing chunks to memory
(loop for a from 0 to 9 do
      (loop for b from 0 to 9 do
	    (learn-chunk (make-additionfact
			  :addend1 a
			  :addend2 b
			  :sum (+ a b)))))

(loop for s from 10 to 18 do
      (learn-chunk (make-carryfact 
		    :total s
		    :rem (- s 10)
		    :carry (mod s 10))))

Code: Select all

(defrule add-digit2 (ten1 one1 ten2 one2) 
(setq sumones (additionfact-sum (retrieve-chunk (list :chunk-type 'additionfact :addend1 one1 :addend2 one2))))
(setq sumtens (additionfact-sum (retrieve-chunk (list :chunk-type 'additionfact :addend1 ten1 :addend2 ten2))))
(cond ((> sumones 9)
(setq sumones (carryfact-rem (retrieve-chunk (list :chunk-type 'carryfact :total sumones))))
(setq carr (carryfact-carry (retrieve-chunk (list :chunk-type 'carryfact :total sumones))))
(setf sumtens (+ sumtens carr))))
(list sumtens sumones))
when i execute (add-digit2 4 5 6 7) - i get an error stating that value Nil is not of expected type structure.
Can anyone please help ?

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: Help with error :value Nil is not of expected type structure

Post by ramarren » Tue Mar 30, 2010 11:44 am

I have never heard of ACT-UP. Is there a link to that? Without knowing what the macros expand to it is hard to tell, but you seem to be using a lot of undefined variables, which has undefined behaviour. Other than that, I can only guess that 'retrieve-chunk' doesn't find your facts, perhaps because the query keys are by unkeywordified identity.

Also, use code tags to maintain formatting and mark your code as code.

jasmeetsajmani
Posts: 3
Joined: Tue Mar 30, 2010 11:16 am

Re: Help with error :value Nil is not of expected type structure

Post by jasmeetsajmani » Tue Mar 30, 2010 11:58 am

Thanks for the reply ! I am new to Lisp and I am guessing the problem lies in undefined variables, can you tell me how should I come over that problem? and ACT-UP is a cognitive architecture similar to ACT-R; I am not sure if you can find documentation on that.

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: Help with error :value Nil is not of expected type structure

Post by nuntius » Tue Mar 30, 2010 12:10 pm

Here's a link to ACT-R. http://act-r.psy.cmu.edu/actr6/

How similar is ACT-UP? Would the code you posted have the same behavior under ACT-R?

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: Help with error :value Nil is not of expected type structure

Post by ramarren » Tue Mar 30, 2010 12:33 pm

jasmeetsajmani wrote:Thanks for the reply ! I am new to Lisp and I am guessing the problem lies in undefined variables, can you tell me how should I come over that problem? and ACT-UP is a cognitive architecture similar to ACT-R; I am not sure if you can find documentation on that.
Actually, I doubt that it is undefined variables, because while it is undefined, most implementations will create a global for those, which would sort of work for that case. You can create local variables with LET. That is assuming that the body of DEFRULE is just generic Common Lisp code, and not an embedded language of some sort.

I think you are misusing RETRIEVE-CHUNK, but it is impossible to say without knowing how it is supposed to work. Does it really take a property list as a single argument? And how are slot names associated with slots?

gugamilare
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil
Contact:

Re: Help with error :value Nil is not of expected type structure

Post by gugamilare » Tue Mar 30, 2010 12:39 pm

I've found ACT-R on wikipedia and the official homepage. Its goal is to understand human cognition. Sounds neat :D, but looks different from your code.

About undefined variables, you need to declare local variables using let:

Code: Select all

(defrule add-digit2 (ten1 one1 ten2 one2)
  (let ((sumones (additionfact-sum (retrieve-chunk (list :chunk-type 'additionfact
                                                         :addend1 one1 :addend2 one2))))
        (sumtens (additionfact-sum (retrieve-chunk (list :chunk-type 'additionfact
                                                         :addend1 ten1 :addend2 ten2)))))
    (cond ((> sumones 9)
           (setq sumones (carryfact-rem (retrieve-chunk (list :chunk-type 'carryfact :total sumones))))
           (setq carr (carryfact-carry (retrieve-chunk (list :chunk-type 'carryfact :total sumones))))
           (setf sumtens (+ sumtens carr))))
    (list sumtens sumones)))
But that does not seem to be your problem. Try calling (add-digit2 1 2 6 7) instead of (add-digit2 4 5 6 7). It seems that your model is only able to deal with two digit numbers, and the sum 45 + 67 = 112 requires more than 2 digits. Other than that, you might be using ACT-UP in an incorrect manner, and we can't help you with that because we don't know how it works.

jasmeetsajmani
Posts: 3
Joined: Tue Mar 30, 2010 11:16 am

Re: Help with error :value Nil is not of expected type structure

Post by jasmeetsajmani » Tue Mar 30, 2010 3:33 pm

As I said I am working on ACT-UP not ACT-R that is why you will see that the code in ACT-R is different from ACT-UP. ACT-UP code is more dependent upon Lisp as compared to ACT-R which has productions and chunks.

Anyways thanks gugamilare, your suggestion really helped. I included that in my code and included a few more changes and it worked. :D

Post Reply