Hi all,<div><br></div><div>I'm new to scheme and I was trying to better understand the 'call-with-current-continuation' feature. I was surprised of the imperative style used in the examples with set!. I've actually written a purely functional example and I was willing to have your opinion about this style of programming.</div>
<div><br></div><div>---------------</div><div>(define (parcour test? lst return)</div><div><div> (define f-return (foldl</div><div> (lambda (element c-return)</div><div> (call/cc (lambda (here) </div><div> (if (test? element) </div>
<div> (c-return (cons element here)) </div><div> c-return))))</div><div> return lst))</div><div> (f-return 'end))</div><div><br></div><div>(define (add-odd-number lst)</div>
<div> (define (iter-rec p accu)</div><div> (match p</div><div> ['end accu]</div><div> [(cons v k-new) (let ([p-new (call/cc k-new)])</div><div> (iter-rec p-new (+ accu v)))]))</div>
<div> (define p0 (call/cc (lambda(k) (parcour odd? lst k))))</div><div> (iter-rec p0 0)</div><div>)</div><div><br></div><div>(add-odd-number '(0 1 2 3 4 5 6 7 8 9 13 27 98 101))</div><div>-------------------</div><div>
<br></div><div>Othewise I have a question:</div><div>Python feature the 'yield' keyword that allows to create very easily coroutines and use them in a for loop. I understood that scheme allows this kind of programming with call/cc but it seems to me that it does require a significant amout of boiler-plate code and I was wondering if there is a short direct syntax similar to the 'yield' of Python.</div>
<div><br></div><div>Best regards,</div><div>Francesco</div></div>