2016-08-20 85 views
1

我可以使用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) 

回答

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") 
+0

我想有一个功能,我可以发送任何功能,只是因为我可以发送任何功能findf。我怎样才能做到这一点? – rnso

+1

将参数'neeedle'改为'f'。然后用'f'替换''(string-contains?s needle)'测试。 – soegaard