Name: Anonymous 2013-03-02 2:18
In this thread, you may post code that makes use of continuations, and I will attempt to produce code that does the same and looks reasonably similar, without using continuations.
(define (producer return)
(return 1 (lambda (return)
(return 2 (lambda (return)
(return 3 '()))))))
(define (consumer produsa)
(if (not (null? produsa))
(produsa (lambda (return-value produsa)
(display return-value)
(newline)
(consumer produsa)))))
(consumer producer)
(define (fact-normal n)
(if (= n 0)
1
(* n (fact-normal (- n 1)))))
(define (fact2 return n)
(if (= n 0)
(return 1)
(fact2 (lambda (ret-val)
(return (* n ret-val)))
(- n 1))))
amb is implemented on deterministic machines.
(if-fail (let ((x (an-element-of '(1 3 5 8))))
(require (even? x))
x)
'all-odd)
(let ((success (lambda (x) x))
(fail (lambda () 'all-odd)))
(an-element-of '(1 3 5 8) (lambda (x fail)
(if (even? x)
(success x)
(fail)))
fail))
(define (an-element-of lis success fail)
(if (null? lis)
(fail)
(success (car lis) (lambda () (an-element-of (cdr lis) success fail)))))
amb-collect-thunk which is not touched by amb itself. Could you stop holding down your period key too? It makes you look like a fucking idiot (though was that the intention and HIBT?)
XS
(require (even x))
YS
XS
(require (even x) fail (lambda ()
YS)