我可以使用findf根据某个过程查找列表中的元素:
(define sl '("tester" "testing" "other words" "for test of" ))
(findf (lambda (x) (string-contains? x "test")) sl)
输出:
'("tester" "testing" "for test of")
如何获得满足某些返回true和false的过程的元素的索引,例如" string-contains?"以上 ?我希望在上面的例子中有以下输出:
'(0 1 3)
答案 0 :(得分:2)
#lang racket
(define (find strings needle)
(for/list ([s strings]
[i (in-naturals)]
#:when (string-contains? s needle))
i))
(find '("tester" "testing" "other words" "for test of")
"test")