我需要编写一个执行以下操作的函数方法:
然后根据以下规则转换每个单词:
如果单词是奇数,则删除其中间字母。
结果显示在屏幕上和文本文件中。
答案 0 :(得分:0)
答案 1 :(得分:0)
这是一个函数,它将为您提供不同单词的列表:
CLIPS>
(deffunction munge (?text)
(bind ?w1 (explode$ ?text))
(bind ?w2 (create$))
(progn$ (?w ?w1)
(bind ?len (str-length ?w))
(if (oddp ?len)
then
(bind ?nw (str-cat (sub-string 1 (div ?len 2) ?w)
(sub-string (+ (div ?len 2) 2) ?len ?w)))
(bind ?w2 (create$ ?w2 ?nw))
else
(bind ?w2 (create$ ?w2 (str-cat ?w)))))
(bind ?first (nth$ 1 ?w2))
(bind ?rest (rest$ ?w2))
(bind ?w3 (create$))
(progn$ (?w ?w2)
(if (neq ?w ?first)
then
(bind ?w3 (create$ ?w3 ?w))))
?w3)
CLIPS> (munge "red green blue purple brown green white red black blue")
("gren" "blue" "purple" "brwn" "gren" "whte" "blck" "blue")
CLIPS>