我希望在define-values
的{{1}}内p
两个整数标识符q
和for-clause
。我可以这样做吗?
for/fold
我得到了:
(define (benchmark x0 ls)
(let ([primes-generator (all-pairs-gen ls)])
(for/fold
([failures 0] [f_cost 0] [it_cost 0])
([(p q) (primes-generator)]
[r (pollard (* p q) x0)])
`((failures (+ failures (if (false? r) 0 (cadr (assq 'factor r)))))
(it_cost (+ it_cost (cadr (assq 'it_cost r))))
(f_cost (+ f_cost (cadr (assq 'f_cost r))))))))
(define (all-pairs-gen ls)
(generator ()
(for ([i (in-range (length ls))])
(for ([j (in-range (add1 i) (length ls))])
(yield (values (list-ref ls i) (list-ref ls j)))))))
EDIT2:
尝试
> (benchmark 2 (list 1 2 3))
result arity mismatch;
expected number of values not received
expected: 1
received: 2
values...:
1
2
得到了:
(define (test2)
(let ([primes-generator (all-pairs-gen (list 1 2 4))])
(for/fold ([acc 0])
([(p q) (in-producer primes-generator (void))])
(* p q))))