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. 如何在每个句柄中添加尾随换行符?
- 2. 如何在PHP中添加换行符?
- 3. 如何在render()中添加换行符?
- 4. 如何在python中添加换行符?
- 5. 如何在app.config中添加换行符?
- 6. 如何在TextView中添加换行符
- 7. 添加字符在句子
- 8. 如何添加换行符
- 9. 如何在elasticsearch中添加where子句
- 10. 如何添加换行符中的RDoc
- 11. 如何在ViewText上添加换行符?
- 12. 如何在SQL字符串中添加'if子句'?
- 13. 如何在if语句中添加子字符串?
- 14. 在字符串中添加换行符
- 15. 如何为子查询中的每一行添加WHERE子句?
- 16. 电子邮件添加换行符?
- 17. 如何在Unix中添加分隔符后的换行符?
- 18. 如何在字符串中添加换行符?
- 19. 如何在LOG语句后添加换行/空行?
- 20. 添加换行符
- 21. TreeView和SiteMap:如何添加换行符?
- 22. 如何使用printf添加换行符?
- 23. 如何向TextView添加换行符?
- 24. 如何在MySQL插入语句中添加where子句?
- 25. 如何在LINQ的WHERE子句中添加IF语句?
- 26. 在where子句中添加子条件
- 27. 如何在PowerShell中添加换行符到命令输出中?
- 28. 谁在wordpress'the_date'中添加换行符?
- 29. 在Twitter中添加换行符(Android/Java)
- 30. 在CodenameOne的SpanLabel中添加换行符
I'm。我相信我不能使用你分享的** deffunction **。任何其他想法? –
使用defmessage-handler而不是deffunction。 –