如何檢查列表中是否存在某個元素,兩者都作爲函數調用的輸入,而不使用lambda?我正在嘗試成員?但無法得到它。檢查球拍列表中是否存在元素
(define (find-string (lst lst str ua)
(cond ((member? ua lst) #t)
(else #f))
如何檢查列表中是否存在某個元素,兩者都作爲函數調用的輸入,而不使用lambda?我正在嘗試成員?但無法得到它。檢查球拍列表中是否存在元素
(define (find-string (lst lst str ua)
(cond ((member? ua lst) #t)
(else #f))
成員的使用會起作用,它只是添加額外的「?」在功能上沒有任何的正面需要
(member 2 (list 1 2 3 4)) [1]
將返回true
另一種解決辦法是寫那些自己遞歸函數
(define (is-in-list list value)
(cond
[(empty? list) false]
[(= (first list) value) true]
[else (is-in-list (rest list) value)]))
我不確定你是否在問一個問題。請**避免在結束時需要提問的標記**。 –
?是一個操作員,不通過添加引用來更新問題 –
看來你」試圖在過程聲明中指定每個參數的類型?它不能像Racket那樣工作... –
[This](http://stackoverflow.com/questions/694669/what-is-the-scheme-function-to-find-an-element-in-a -list)可能會有所幫助。 – GDP2