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 (resource-manager init n)
; Limited number of resources, for instance file descriptors
(define resources (make-list-of-n-resources init n))
(define wait-queue '())
; Return a free resource, and wait until there is one to get
(define (get-resource)
(call-with-current-continuation
(lambda (k)
(if (null? resources)
(begin
; No free resource, resume caller later
(set! waiters (cons k wait-queue))
(yield-to-event-loop))
(let ((resource (car resources)))
(set! resources (cdr resources))
resource)))))
; Free a single resource and possibly let a waiting event handler run
(define (free-resource resource)
(call-with-current-continuation
(lambda (k)
(if (null? wait-queue)
(set! resources (cons resource resources))
(let (waiter (car wait-queue))
(set! waiters (cdr wait-queue))
; Suspend the caller for a while
(push-resumable-event k)
; Resume a waiting event handler
(waiter resource)))))
#t)
; Register some event handlers
(for-each
(lambda (event)
(register-event-handler event
(lambda ()
; Here, without continuations, you end up with node.js
; get-resource, free-resource and read-from-io-device all
; yield to the event loop if necessary
(let ((device ((io-manager 'get-resource))))
(display (read-from-io-device device)
((io-manager 'free-resource) device))))))
'(event-1 event-2 event-3))
Yes and it's related to Yadira, which means friend in HEBREW.
Name:
Anonymous2013-03-02 11:34
Nikita Sadkov - JEW
Name:
Anonymous2013-03-02 11:39
Nikita Sadkov - JEW Sadkov - JEW - JEW JEW
Name:
Anonymous2013-03-02 11:40
>>34
Why is that so many language developers are MtF transgender people? Audrey Tang, some chick from PyPy if I recall correctly, now Nikita "Delicate flower" Sadkova joins the ranks.