【发布时间】:2014-05-14 12:00:38
【问题描述】:
我需要用对填充一个列表,例如:((x 10)(z 5))。
我目前的方法:
;;send the current list, and an id value pair
(define (setID idList ID VAL)
(cond
;;if the list is null, add the pair
((null? idList) (cons '(ID VAL) '()))
;; if the ID already exists, overwrite it
((equal? ID (car(car idList))) (cons '((cdr idList)) VAL))
;; continue the search
(else (setID (cdr idList) ID VAL))
)
)
我意识到我还需要使用cons 来保持列表的完整性,但第一个问题是当我执行(setID z 5) 之类的操作时,返回的列表正是:((id val))。显然,它需要是((z 10))。有没有办法做这样的事情?
【问题讨论】:
标签: recursion scheme racket r5rs