我很难开始这个确切的问题。以下是这些问题的说明。
示例:
STK> (define marions-vacay
(substitutebot-creator '(indonesia winter noodles)
'(texas summer steak)))
STK> (marions-vacay '(i visited indonesia this winter and ate noodles))
(i visited texas this summer and ate steak)
我尝试使用以下内容:
(define (substitutebot-creator from to)
(lambda (x) (substitutebot x from to)))
(define (substitutebot sent from to)
(define subby? (lambda (word) (equal? (recurse-first from) word)))
(cond ((and (empty? from)(empty? to)) sent)
((subby? (first sent))
(se (recurse-switch (first sent) from to
(count from)) (substitutebot (bf sent))))
(else (substitutebot (bf sent)))))
(define (recurse-first sent)
(if (empty? sent)
'()
((word(first sent))(recurse-first (bf sent)))))
但它不起作用。我想我是在错误的道路上开始这个问题,所以我想知道什么是启动这个问题的最佳方法。几乎我如何成功地使聊天机器人创建另一个聊天机器人。
答案 0 :(得分:0)
让你的想法尽可能简单可能会更好。问题的关键在于你需要制作一本字典并按照给定的单词进行查找。为此,您可以使用alist(关联列表)。
更具体的提示:
((before . after) ...)
assq
已足够)。答案 1 :(得分:0)
我可以帮助您开始使用fold-left
(define (make-alist from to)
(fold-left (lambda (acc from to) (cons (cons from to) acc)) '() from to))
(make-alist '(indonesia winter noodles) '(texas summer steak)) => ((noodles . steak) (winter . summer) (indonesia . texas))
然后您可以对assq
make-alist