2011-12-15 10 views
2

このコードは、警告メッセージを除き、必要に応じて機能します。 GNU Common Lispでは、他の可能な警告メッセージを抑制することなく、そのメッセージを抑制するにはどうすればいいですか? Vatineの種類の返信に応じてGNU clisp:適用できないメソッドに関する警告メッセージを表示しない

1 (defgeneric zang (x y) 
2 (:documentation "they want you to put documentation here")) 
3 (defmethod zang ((a number) (b string)) 
4 (format t "got to zang ((~s number) (~s string))~%" a b)) 
5 (defmethod zang ((a integer) (b string)) 
6 (format t "got to zang ((~s integer) (~s string))~%" a b) 
7 (when (evenp a) 
8  (format t "passing control to the other guy~%") 
9  (call-next-method (1+ a) "hoo boy") 
10  (format t "returned control from the other guy~%"))) 
11 (defmethod no-applicable-method (zang &rest args) 
12 (format t "no applicable method for (zang ~{~s~^ ~})~%" args)) 
13 (zang 3.5 "hi") 
14 (zang 3 "hi") 
15 (zang 4 "hi") 
16 (zang "hello" "world") 
WARNING: Replacing method #<STANDARD-METHOD (#<BUILT-IN-CLASS T>)> in 
     #<STANDARD-GENERIC-FUNCTION NO-APPLICABLE-METHOD> 
got to zang ((3.5 number) ("hi" string)) 
got to zang ((3 integer) ("hi" string)) 
got to zang ((4 integer) ("hi" string)) 
passing control to the other guy 
got to zang ((5 number) ("hoo boy" string)) 
returned control from the other guy 
no applicable method for (zang "hello" "world") 

EDITは:

は私がすることを試みたが、状況は致命的なエラーに警告からエスカレート:私は思う

(defgeneric zang (x y) 
    (:documentation "they want you to put documentation here")) 
(defmethod zang ((a number) (b string)) 
    (format t "got to zang ((~s number) (~s string))~%" a b)) 
(defmethod zang ((a integer) (b string)) 
    (format t "got to zang ((~s integer) (~s string))~%" a b) 
    (when (evenp a) 
    (format t "passing control to the next guy~%") 
    (call-next-method (1+ a) "hoo boy") 
    (format t "returned control from the next guy~%"))) 
;(defmethod no-applicable-method (zang &rest args) 
; (format t "no applicable method for (zang ~{~s~^ ~})~%" args)) 
(defmethod no-applicable-method ((zang eql #'zang) &rest args) 
    (format t "no applicable method for (zang ~{~s~^ ~})~%" args)) 
(zang 3.5 "hi") 
(zang 3 "hi") 
(zang 4 "hi") 
(zang "hello" "world") 
*** - DEFMETHOD NO-APPLICABLE-METHOD: Invalid specialized parameter in method 
     lambda list ((ZANG EQL #'ZANG) &REST ARGS): (ZANG EQL #'ZANG) 
+0

あなたが印刷警告 "方式の交換" を抑制したいか、しないでください "該当する方法はありません "? –

+0

"警告:置換方法"で始まる2行を表示しないようにします。 –

答えて

4

NO-APPLICABLE-METHODの正しい引数リストを指定する必要があります。 コンパイラを使用する場合(CLISP実装でもCOMPILE-FILEを使用してコンパイルできます)、コンパイル時に不正な引数リストについてのエラーメッセージも表示されます。

例えばLispWorksコンパイラは言う:

**++++ Error between functions: 
An argument is not an atom or list of two elements : (ZANG EQL (FUNCTION ZANG)) 

固定バージョン:

(defgeneric zang (x y) 
    (:documentation "they want you to put documentation here")) 
(defmethod zang ((a number) (b string)) 
    (format t "got to zang ((~s number) (~s string))~%" a b)) 
(defmethod zang ((a integer) (b string)) 
    (format t "got to zang ((~s integer) (~s string))~%" a b) 
    (when (evenp a) 
    (format t "passing control to the next guy~%") 
    (call-next-method (1+ a) "hoo boy") 
    (format t "returned control from the next guy~%"))) 
;(defmethod no-applicable-method (zang &rest args) 
; (format t "no applicable method for (zang ~{~s~^ ~})~%" args)) 

(defmethod no-applicable-method ((zang (eql #'zang)) &rest args) 
    (format t "no applicable method for (zang ~{~s~^ ~})~%" args)) 

例:

(defun test() 
(zang 3.5 "hi") 
(zang 3 "hi") 
(zang 4 "hi") 
(zang "hello" "world")) 

CL-USER 1 > (test) 
got to zang ((3.5 number) ("hi" string)) 
got to zang ((3 integer) ("hi" string)) 
got to zang ((4 integer) ("hi" string)) 
passing control to the next guy 
got to zang ((5 number) ("hoo boy" string)) 
returned control from the next guy 
no applicable method for (zang "hello" "world") 
NIL 
+1

これはうまくいった!ドキュメントを理解する私の能力は、nullではありませんが、完璧ではありません。この正しい構文の例は、私がドキュメンテーションに戻るときに役立ちます。ありがとうございました! –

+0

明確にする:解決策の一部は、置換コードの2番目の「zang」がそのまま綴られることです。しかし、私は実際にそのパラメータを使用していないので、最初の "zang"は任意に綴ることができます。例:((fred(eql 'zang)) –

+1

@Bill Evans at Mariposa:((zang(eql#' zang))&rest argsのような)パラメータリストは、最初のzangがパラメータ名であることを意味します。このメソッドが実際の引数と一致するには、関数zangの関数オブジェクトにEQLする必要があります。これは2番目のzangです –

3

適用できないメソッドのメソッドを次のように定義します。

(defmethod no-applicable-method ((zang (eql #'zang)) &rest args) 
    ...) 

これは、すべての汎用関数に適用されるメソッドを宣言しているため、既に定義されているメソッドを置き換えることをclispが指示している理由です。

+0

あなたは何かをしていると思いますが、その構文は機能しません。私の質問への編集を参照してください。とにかくありがとう。 :) –

+1

私はそれが "eql# 'zang"部分の周りにかっこを必要と思う。 – Vatine

+0

Rainerはそれを打ちました。しかし、帰ってくれてありがとう。 –

関連する問題