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

Shiitchan can't be shittier

Name: Anonymous 2010-08-31 8:10

Discuss.

Name: Anonymous 2010-09-01 7:04

>>31
Of course it could, I'll show an example here (this is in Lisp, but it can just as easily be done in C, C++, C#, Java or any more "traditional" imperative languages):

(defun some-function (signal-error) 
  (block nil
    (ignore-errors 
      (unwind-protect
           ;; the return form is unneeded as
           ;; returns are implicit in CL, but I've
           ;; included it to illustrate the point
           (return
             (prog1
                 (print "In RETURN")
               (when signal-error
                 (error "Oh no. Something bad happened."))
               (print "In PROG1")))
        (print "In protected area")))))

(some-function nil)
; Prints
;"In RETURN"
;"In PROG1"
;"In protected area"
(some-function t)
; Prints
;"In RETURN"
;"In protected area"

As you can see, the function finished just find after a return "statement" was executed, not only that, things located lexically after the return statement were also executed. (In case you didn't figure it by now, UNWIND-PROTECT is like try{}finally{} in more imperative languages. It's code which is ALWAYS executed, regardless if some form of transfer of execution happened or not (like conditions(similar to what you call exceptions) or go(to))).

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