← Архив: Common Lisp

defgeneric, странное поведение

Author: · 05.11.2010 00:59
· original author: pseudo-cat
я что-то не понимаю или пора выспаться?
GRAPH-ALG> (get-v-outs (car *sg-g*) 'a)
(B C)
GRAPH-ALG> (defun z () (get-v-outs (car *sg-g*) 'a))
Z
GRAPH-ALG> (z)
#|
There is no applicable method for the generic function
  #<STANDARD-GENERIC-FUNCTION GET-V-OUTS (1)>
when called with arguments
  (#S(SIMPLY-GRAPH :VERTICIES #1=(A B C) :BRANCHS (#1# #)) A).
   [Condition of type SIMPLE-ERROR]
Restarts:
 0: [RETRY] Retry calling the generic function.
 1: [RETRY] Retry SLIME REPL evaluation request.
 2: [*PROCESS-INPUT] Continue reading input.
 3: [ABORT] Return to SLIME's top level.
 4: [CLOSE-CONNECTION] Close SLIME connection.
 5: [ABORT] Exit debugger, returning to top level.
Backtrace:
  0: ((SB-PCL::FAST-METHOD NO-APPLICABLE-METHOD (T)) #<unavailable argument> #<unavailable argument> #<STANDARD-GENERIC-FUNCTION GET-V-OUTS (1)>)[:EXTERNAL]
  1: (SB-PCL::CALL-NO-APPLICABLE-METHOD #<STANDARD-GENERIC-FUNCTION GET-V-OUTS (1)> (#S(SIMPLY-GRAPH :VERTICIES #1=(A B C) :BRANCHS (#1# #)) A))
  2: (SB-INT:SIMPLE-EVAL-IN-LEXENV (Z) #<NULL-LEXENV>)
|#
; Evaluation aborted on #<SIMPLE-ERROR "~@<There is no applicable method for the generic function ~2I~_~S~
         ~I~_when called with arguments ~2I~_~S.~:>" {2416B6D9}>.
GRAPH-ALG> (get-v-outs (car *sg-g*) 'a)
; Evaluation aborted on #<SIMPLE-ERROR "~@<There is no applicable method for the generic function ~2I~_~S~
         ~I~_when called with arguments ~2I~_~S.~:>" {24AF2A09}>.
GRAPH-ALG>
windows, sbcl-1.0.43-threads 
· original author: pseudo-cat
и забыл:
;; #################################
;; generic functions to work with graphs
(defgeneric verticies (graph))
 
(defgeneric get-v-outs (graph vertex))
(defgeneric same-vertex? (v1 v2))
;; #################################
;; simply graph system
(defstruct (simply-graph (:constructor make-simply-graph ())
                         (:conc-name simply-graph-)
)

  (verticies nil)
  (branchs nil)
)

;; Methods to special cases
(defmethod verticies ((graph simply-graph))
  (simply-graph-verticies graph)
)

(defmethod get-v-outs ((graph simply-graph) vertex)
  (with-slots (branchs) graph
    (loop for branch in branchs
       with result = (list)
       do (multiple-value-bind (el id)
              (pscat:list-find-and-id vertex branch)
            (if el
                (if (> id 0)
                    (push (car branch) result)
                    (setf result (append result (cdr branch)))
)
)
)

       finally (return (delete-duplicates result))
)
)
)
· original author: dmitry_vk
А можешь привести полный код в виде одного файла, в том числе с кодом по объявлению и инициализации переменной *sg-g*?
· original author: pseudo-cat
http://pastebin.com/zaKSDQVh
http://pastebin.com/8BJtscyq
· original author: pseudo-cat
http://pastebin.com/zaKSDQVh
http://pastebin.com/8BJtscyq
· original author: pseudo-cat
а у меня это, всё заработало сегодня с утра, ничего не менял. O0
· original author: dmitry_vk
Возможно, что код перекомпилировался несколько раз. В SBCL, если перекомпилировать форму (defstruct ...), то в коде будут существовать _оба_ определения - и старое, и новое. Выглядеть они будут одинаково, но не будут равны друг другу. В частности, это может проявиться в ненахождении методов.
· original author: Jax
>В частности, это может проявиться в ненахождении методов.
И как от этого избавляются (перезапуск sbcl это слишком грубое решение)?
· original author: dmitry_vk
>И как от этого избавляются (перезапуск sbcl это слишком грубое решение)?

В случае с изменением определения структуры все просто просто следует перекомпилировать все зависимые от нее места.
· original author: slav
> В случае с изменением определения структуры все просто просто следует перекомпилировать все зависимые от нее места.
И sbcl, кстати, при переопределении структуры честно генерит ворнинг, предупреждая, чем такое действие грозит.
· original author: dmitry_vk
Да, предупреждает. Но есть соблазн применить изменения, а потом можно забыть, где структура была использована.