2016-11-05 47 views
0

我试图编译下面的代码:越来越未定义的引用的函数commonLISP

(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是一个功能和状态列表是一个列表,定义这两者。我得到“未定义的参考状态列表”。 我不知道我在做什么错。 任何帮助将不胜感激

+0

难道你忘了'do'? – Sylwester

+0

@Sylwester我试过,但没有编译。我怎么可以在里面放多个语句呢? –

+0

它应该采取多种形式例如。 '(loop:for var:in list:do expr1 expr2 ...)'。如果你没有then子句,你应该'(when(not(member ...)expr1 expr2 ...)' – Sylwester

回答

1

重命名严重的骆驼案件聆讯案件我留下这个。

(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))) 

此处作为一个测试是我有:

(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)