我的Scheme医疗数据库有问题。我想编写一个带有X症状的函数,并在我的数据库中搜索与诊断匹配的函数。
这是我到目前为止所做的:
(define helper-match
(lambda (ls)
(reverse
(let loop ([ls ls] [found '()] [acc '()])
(cond
[(null? ls)
acc]
[(memq (car ls) found)
(loop (cdr ls)
found
(if (memq (car ls) acc)
acc
(cons (car ls) acc)))]
[else
(loop (cdr ls)
(cons (car ls) found)
acc)])))))
上面是一个检查重复项的函数,但我不知道如何编写它以便与我的数据库进行比较。
数据库的结构如下所示:
(define *medical-db-2*
'((1
(disease (meningit)
(symptom (fever) (headache) (vertigo) (vomiting) (stiffness) (light sensitivity))))
(2
(disease (encefalit)
(symptom (fever) (headache) (vertigo) (vomiting) (disorientation) (cramps))))