2017-08-26 19 views
0

私はbind関数を使用していますが、バインドするテキストは非常に大きいです。CLIPS:文に改行を追加する方法

私はprint outコマンドを使用すると、テキストをより多くの行に分割したいので、画面に適切に収まるようにします。

どのようにすればいいですか?

答えて

1

はdeffunctionを定義:** ** OOP(オブジェクト指向プログラミング)を用い

CLIPS>  
(deffunction print-to-width (?log-name ?width ?str) 
    (if (<= ?width 0) 
    then 
    (printout ?log-name ?str crlf) 
    (return)) 
    (bind ?w ?width) 
    (while (neq ?str "") 
    (bind ?pos (str-index " " ?str)) 
    (if (or (not ?pos) 
      (> ?pos (+ ?w 1))) 
     then 
     (if (and (not ?pos) (<= (str-length ?str) ?w)) 
      then 
      (printout ?log-name ?str) 
      (bind ?str "") 
      else 
      (if (!= ?w ?width) 
       then 
       (printout ?log-name crlf) 
       (bind ?w ?width) 
       else 
       (printout ?log-name (sub-string 1 ?w ?str)) 
       (bind ?str (sub-string (+ ?w 1) (str-length ?str) ?str)) 
       (if (neq ?str "") then (printout ?log-name crlf)) 
       (bind ?w ?width))) 
     else 
     (printout ?log-name (sub-string 1 ?pos ?str)) 
     (bind ?str (sub-string (+ ?pos 1) (str-length ?str) ?str)) 
     (bind ?w (- ?w ?pos))) 
    (if (eq ?str "") then (printout ?log-name crlf))) 
    (return)) 
CLIPS> (print-to-width t 0 "the quick brown fox jumped over the lazy dogs") 
the quick brown fox jumped over the lazy dogs 
CLIPS> (print-to-width t 80 "the quick brown fox jumped over the lazy dogs") 
the quick brown fox jumped over the lazy dogs 
CLIPS> (print-to-width t 40 "the quick brown fox jumped over the lazy dogs") 
the quick brown fox jumped over the lazy 
dogs 
CLIPS> (print-to-width t 20 "the quick brown fox jumped over the lazy dogs") 
the quick brown fox 
jumped over the lazy 
dogs 
CLIPS> (print-to-width t 10 "the quick brown fox jumped over the lazy dogs") 
the quick 
brown fox 
jumped 
over the 
lazy dogs 
CLIPS> 

またはメッセージハンドラ

CLIPS> 
(defmessage-handler STRING print-to-width (?log-name ?width) 
    (bind ?str ?self) 
    (if (<= ?width 0) 
    then 
    (printout ?log-name ?str crlf) 
    (return)) 
    (bind ?w ?width) 
    (while (neq ?str "") 
    (bind ?pos (str-index " " ?str)) 
    (if (or (not ?pos) 
      (> ?pos (+ ?w 1))) 
     then 
     (if (and (not ?pos) (<= (str-length ?str) ?w)) 
      then 
      (printout ?log-name ?str) 
      (bind ?str "") 
      else 
      (if (!= ?w ?width) 
       then 
       (printout ?log-name crlf) 
       (bind ?w ?width) 
       else 
       (printout ?log-name (sub-string 1 ?w ?str)) 
       (bind ?str (sub-string (+ ?w 1) (str-length ?str) ?str)) 
       (if (neq ?str "") then (printout ?log-name crlf)) 
       (bind ?w ?width))) 
     else 
     (printout ?log-name (sub-string 1 ?pos ?str)) 
     (bind ?str (sub-string (+ ?pos 1) (str-length ?str) ?str)) 
     (bind ?w (- ?w ?pos))) 
    (if (eq ?str "") then (printout ?log-name crlf))) 
    (return)) 
CLIPS>  
(send "the quick brown fox jumped over the lazy dogs" print-to-width t 0) 
the quick brown fox jumped over the lazy dogs 
CLIPS> (send "the quick brown fox jumped over the lazy dogs" print-to-width t 80) 
the quick brown fox jumped over the lazy dogs 
CLIPS> (send "the quick brown fox jumped over the lazy dogs" print-to-width t 40) 
the quick brown fox jumped over the lazy 
dogs 
CLIPS> (send "the quick brown fox jumped over the lazy dogs" print-to-width t 20) 
the quick brown fox 
jumped over the lazy 
dogs 
CLIPS> (send "the quick brown fox jumped over the lazy dogs" print-to-width t 10) 
the quick 
brown fox 
jumped 
over the 
lazy dogs 
CLIPS> 
+0

- 私のクリップに。あなたが共有している**機能を使用することはできません。他のアイデア? –

+0

deffunctionの代わりにdefmessage-handlerを使用してください。 –

関連する問題