Archive for January, 2008

@program = ::poem

January 23rd, 2008 | Category: Computers & 570x0FF, Personal (Espa├▒ol)

La poes├şa no es algo. La poes├şa lo es todo.

M├║sica con idea es poes├şa. M├║sica sin idea es simplemente m├║sica.

Hoy vi algo en un blog del PLT que me dej├│ anonadado. Un peque├▒o programita, tan bello y hermoso que tuve que leerlo varias veces para asimilar la experiencia est├ętica. Lo pongo aqu├ş, con cr├ędito a matthias en este post de un blog perdido por ah├ş.

;; [LISTOF X] -> ( -> X u 'you-fell-off-the-end-off-the-list)
(define (generate-one-element-at-a-time a-list)
  ;; (-> X u 'you-fell-off-the-end-off-the-list)
  ;; this is the actual generator, producing one item from a-list at a time
  (define (generator)
     (call/cc control-state))
  ;; [CONTINUATION X] -> EMPTY
  ;; hand the next item from a-list to "return" (or an end-of-list marker)'
  (define (control-state return)
     (for-each
        (lambda (an-element-from-a-list)
           (set! return ;; fixed
             (call/cc
               (lambda (resume-here)
                 (set! control-state resume-here)
                 (return an-element-from-a-list)))))
        a-list)
     (return 'you-fell-off-the-end-off-the-list))
  ;; time to return the generator
  generator)
1 comment