Scheme 球拍计划-会员?函数难题

Scheme 球拍计划-会员?函数难题,scheme,lisp,racket,Scheme,Lisp,Racket,我正在尝试使用一个成员?函数确定用户输入中是否存在特定字符串 成员?使用的功能是: (define (member? item seq) (sequence-ormap (lambda (x) (equal? item x)) seq)) 但是,我的程序结构要求我进行以下比较: (成员?’(姓名)(垒员姓名)) 其输出示例如下: > (car (car *strong-cues*)) '((the n

我正在尝试使用一个成员?函数确定用户输入中是否存在特定字符串

成员?使用的功能是:

    (define (member? item seq)
  (sequence-ormap (lambda (x)
                    (equal? item x))
                  seq))
但是,我的程序结构要求我进行以下比较:

(成员?’(姓名)(垒员姓名))

其输出示例如下:

> (car (car *strong-cues*))
'((the names) (their names))
> (car (car (car *strong-cues*)))
'(the names)
> (member? (car (car (car *strong-cues*))) '(the names of the basemen))
#f
“名称”显然在用户输入中(在本例中是“垒员的名称”),但是,我看到的问题是,这就是正在发生的情况:

(这些名字)在垒员的“或”名或“或”名中吗


有没有一种方法可以正确地进行这种比较,以便如果“名称”是用户输入中的字符串,则搜索“名称”将返回true?

这根本不是
成员,因为您正在搜索列表中的子列表。因此,您不能使用
ormap
,因为每次迭代只有一个元素,而您希望比较几个元素。我建议您使用
前缀?

(define (prefix? what lst)
  ; implementation left as exercise
  <???>)

(prefix? '(b c) '(a b c d)) ; ==> #f
(prefix? '(b c) '(b c d))   ; ==> #t

在这里,我返回带有前缀的列表,就像member一样,但它可以很容易地更改为您希望它执行的任何操作。。索引,
#t
等。

您的解释简短且信息丰富。非常感谢你!!
(define (find-sublist sub lst)
  (cond ((null? lst) #f)
        ((prefix? sub lst) lst)
        (else (find-sublist sub (cdr lst))))))

(find-sublist '(c d) '(a b c d e f)) ; ==> (c d e f)