0
A
回答
1
定義自定義函數:
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>
或消息處理程序中使用的剪輯** ** OOP(面向對象編程)
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>
相關問題
- 1. 如何在python中添加換行符?
- 2. 如何在app.config中添加換行符?
- 3. 如何在TextView中添加換行符
- 4. 如何在render()中添加換行符?
- 5. 添加字符在句子
- 6. 如何在if語句中添加子字符串?
- 7. 如何在字符串中添加換行符?
- 8. 如何在Unix中添加分隔符後的換行符?
- 9. 如何在LOG語句後添加換行/空行?
- 10. 添加換行符
- 11. 如何向TextView添加換行符?
- 12. TreeView和SiteMap:如何添加換行符?
- 13. 如何在MySQL插入語句中添加where子句?
- 14. 如何在LINQ的WHERE子句中添加IF語句?
- 15. 在循環中添加換行符
- 16. FileUtils.mv在Windows中添加換行符
- 17. 在列表中添加換行符
- 18. 如何在PowerShell中添加換行符到命令輸出中?
- 19. PHP:如何在純文本電子郵件中添加換行符 - 跨平臺
- 20. Emacs:如何在遇到換行符時結束句子
- 21. 如何在SQL Server存儲過程中添加換行符?
- 22. 如何在Wx中添加換行符:: textCtrl
- 23. 如何在iPhone編程中添加換行符?
- 24. 如何在draw2d中添加強制換行符TextFlow
- 25. 如何在Android中向TextView添加換行符?
- 26. 如何在Google羣組說明字段中添加換行符?
- 27. Android Studio:如何在git commit消息中添加換行符?
- 28. 如何在RSS Feed中添加換行符?
- 29. 如何使用LWUIT在標籤中添加換行符?
- 30. 如何在TextView中添加換行符和空格?
I'm。我相信我不能使用你分享的** deffunction **。任何其他想法? –
使用defmessage-handler而不是deffunction。 –