我正在尝试根据对的权重排序对流 - 对中两个数字的总和。(我不排除重复项。)我的代码似乎不起作用
(define (merge-weighted s1 s2 weight)
(let ((h1 (stream-car s1))
(h2 (stream-car s2)))
(if ((weight h1) < (weight h2))
(cons-stream h1 (merge-weighted (stream-cdr s1) s2 weight))
(cons-stream h2 (merge-weighted new1 (stream-cdr s2) weight)))))
当使用另一个整数流 (s2) 对整数流 (s1) 调用合并加权并使用以下 weight1 时:
(define (weight1 pair)
(+ (car pair) (cdr pair)))