Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Haskell.

Name: Anonymous 2011-01-30 13:46

This obscure language represents a peculiar corner of the programming language world called functional languages. One of the peculiar things about such languages is that they don’t have variables. Although Haskell isn’t widely known among programmers, those who know of functional languages suspect that they, too, are rather slow

Name: Anonymous 2011-01-30 19:30

>>12
IMHO that's one of those idiotic CL misconceptions. You either:
1. Unwind and can't re-enter anymore, getting the same behaviour as in CL unwind-protect.
Or
2. Set a finalizer on an object and let the GC handle it, which is the right thing to do in 90% of the cases anyway.

Creating a difference between ``final'' and ``temporary'' exits really seems like a solution looking for a problem.

Further reading:
http://www.nhplace.com/kent/PFAQ/unwind-protect-vs-continuations-overview.html
http://mumble.net/~campbell/blag.txt 2009-03-28

To end on a positive note, let me recite the beautiful dynamic-wind implementation from http://www.cs.hmc.edu/~fleck/envision/scheme48/meeting/node7.html . Understanding it is satori.

(define *here* (list #f))

(define original-cwcc call-with-current-continuation)

(define (call-with-current-continuation proc)
  (let ((here *here*))
    (original-cwcc
     (lambda (cont)
       (proc
        (lambda results
          (reroot! here)
          (apply cont results)))))))

(define (dynamic-wind before during after)
  (let ((here *here*))
    (reroot! (cons (cons before after) here))
    (call-with-values
     during
     (lambda results
       (reroot! here)
       (apply values results)))))

(define (reroot! there)
  (if (not (eq? *here* there))
      (begin
        (reroot! (cdr there))
        (let ((before (caar there))
              (after (cdar there)))
          (set-car! *here* (cons after before))
          (set-cdr! *here* there)
          (set-car! there #f)
          (set-cdr! there '())
          (set! *here* there)
          (before)))))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List