Scheme built-in to check list containment

[亡魂溺海] 提交于 2019-12-12 10:49:49

问题


In Python I can do "x in list" to see if the list contains x. Is there any equivalent built-in in Scheme to do this?


回答1:


The R5RS, and the R6RS standard library for lists define memq, memv, and member which can be used for that purpose.




回答2:


In PLT Scheme, one has

(member whatever list)
(memv whatever list)
(memq whatever list)

from the SRFI which use, respectively, equal?, eqv?, and eq? to test for equality. There are also a number of other library functions related to searching in lists:

PLT Scheme list reference




回答3:


(define (contains? l i)
  (if (empty? l) #f
      (or (eq? (first l) i) (contains? (rest l) i))))



回答4:


No, there is no list built-in predicate that will do that for you. It's extremely easy to define a lambda or a macro to do just that though.



来源:https://stackoverflow.com/questions/1869116/scheme-built-in-to-check-list-containment

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!