0

I'm trying to compile the following code:

    (defun nextStates (st)
  "generate all possible states"
  (setf N 0)
  (setf states-list (make-list 9))
  (setf list-actions (possible-actions))

  (loop for x in list-actions do

     (setf aux (nextState st x))
     (when (not(member aux (states-list) :test #'equalp))
         (progn
            (setf (nth N states-list) aux)
            (setf N (+ N 1))
         )
     )
  )

    (values states-list)
  )

nextState is a function and states-list is a list, both of which are defined. I'm getting "undefined reference to states-list". I don't know what I'm doing wrong. Any help will be greatly appreciated

7
  • Did you forgot do? Commented Nov 5, 2016 at 17:07
  • @Sylwester I tried to, but it didn't compile. How can I put multiple statements inside do? Commented Nov 5, 2016 at 17:17
  • It should take multiple forms Eg. (loop :for var :in list :do expr1 expr2...). If you don't have a then clause you should (when (not (member...) expr1 expr2...) Commented Nov 5, 2016 at 17:38
  • @Sylwester So just adding do after (loop for x in list-actions should do the trick right? I tried to compile it that way and now I'm getting "Undefined function states-list. Why is is seeing states-list as a function? Commented Nov 5, 2016 at 17:45
  • 1
    Still missing do: (loop for x in list-actions do (setf aux (nextState st x)) (when (not (member aux states-list :test #'equalp)) (setf (nth N states-list) aux) (setf N (+ N 1)))) but N and aux must exist though or you should add it as variables in the loop. Commented Nov 5, 2016 at 17:52

1 Answer 1

1

Renaming the badly camel case to lisp case I'm left with this.

(defun next-states (st)
  "generate all possible states"
  (loop :for action :in (possible-actions)
        :for aux := (next-state st action) :then (next-state st action)
        :when (not (member aux states-list :test #'equalp))
          :collect aux :into states-list
        :finally (return states-list)))

As a test here is what I had:

(defun possible-actions ()
  "have duplicates to see not member in action"
  '(0 1 3 3 4))

(defun next-state (st action)
  "Simple version for test"
  (+ st action))

(next-states 3) ; ==> (3 4 6 7)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.