Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Giving Up! (was "UNWIND_PROTECT in Scheme")
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mark Conrad  
View profile  
 More options May 13 2003, 4:59 pm
Newsgroups: comp.lang.lisp
From: Mark Conrad <nos...@iam.invalid>
Date: Tue, 13 May 2003 21:00:01 GMT
Local: Tues, May 13 2003 5:00 pm
Subject: Giving Up! (was "UNWIND_PROTECT in Scheme")
(Willaim D. Clinger observed in another thread):

> Recall that this conversation started when someone used
> call/cc as an example of excessive expressive power.  Kent
> didn't accept that argument.  He tried to argue instead that
> call/cc and dynamic-wind have insufficient expressive power.
> That's nonsense: the theorists believe that, when combined
> with side effects and the rest of Scheme, call/cc is powerful
> enough to implement every deterministic sequential control
> structure that has ever been proposed.

In my naive newbie opinion, I agree wholeheartedly, but what the heck,
newbies opinions like mine count for less than nothing, right.

I am actually such a new newbie, that I don't even know the difference
between unwind-protect (in CL) supporting "downward" escapes, and some
Scheme procedures that support "upward" escapes.

Just repeating what I read, please don't pounce on me.

...but all that esotoric stuff is beyond my comprehension anyhow,
because I have smaller fish to fry - - - newbie sized fish :)

I am "into" CL strictly for recreation.

BTW, whatever  _did_  happen to the days when computing was fun, and
newbie mistakes were tolerated instead of being flamed?

Anyhow, onwards and upwards to my Big Newbie Problem, the one that
broke my back and caused me to Give Up.

Kent M. Pitman, a CL expert, made some sort of statement to me to the
effect that it was a "trivial" matter to do what I am attempting to do.

Forgive me Mr. Pitman if I interpreted this all wrong.

Anyhow, in my newbie zeal, I am trying to do with Graham's CL
"continuations" what is normally done by CL built-in thingies, like
this long list below - - - (I wanted to get the "scope" and "extent"
considerations on the below list of thingies below correct, also)

catch, throw, tag, return, return-from, unwind-protect, toplevel, go,
prog, eval-when, define-symbol-macro, block, and numerous other
flow-of-control constructs that I can't think of right this moment.

Now to my specific newbie example, and the immense problems I ran into.

To make this code as portable as possible in implementations such as
CMUCL, the newbie device of "creating my own lexible toplevel" was used
here, by throwing the whole mess of code into an all-encompassing
"let".

This created the huge problem (huge to me) of my not being able to
escape to "real" toplevel, by some method of using ordinary functions
instead of having to use constructs from that long list above.

Now I have seen it stated in CL literature that any CL construct can be
"broken-down" into simple core-lisp terms like car, cdr, cons, etc.

...indeed, it has to be, inside of the CL implementation itself, before
the CL code is transformed into anything resembling machine-code.

I don't know if this is CL "propaganda", or if it indeed is correct.

But I digress, back to my Big Problem.

Remembering that all my code is enclosed in an all-encompassing "let"...

(let ()...
   (+
      2
          <== I want to escape to "real" toplevel by using simple
                     core-lisp at this point.
       3
       5
       22))

I have pretty well given up on this, I can't see how to escape to
toplevel using simple code techniques, without resorting to catch/throw
and its cousins.

Anyhow, I am just starting to use Paul Graham's six macros.

The two most important of his six macros, IMO, are "=bind" and
"=values", so these two are the only one's used in the newbie-altered
mess I subjected Graham's excellent code to, below - - -

FWIW, this code should work across all ANSI conforming applications.

Just remember to compile it at least two-three times after loading it
into your CL in order to get rid of the various warnings and even
errors that are characteristic when dealing with the loading of macros.

Once loaded and compiled, type  (demo)  to run the code,

Copy and paste everything here to your CL, only if you are inclined to
play with Graham's "continuations".

(defvar %cont%)
(setq %cont% 'foo)

;; All the code is "within the body" of the 'let' form below;
;; with the exception of the two lines above,

(let (( %cont%   #'(lambda (&rest args)
                               (if (cdr args)
                                   args
                                   (car args)) )))

  %cont%

;; Start of Paul Graham's six macros, taken
;; from his 1994 book titled "On Lisp"

;; *************************************
  (defmacro  =lambda (parms &body body)
    `#'(lambda (%cont% ,@parms) ,@body))

  (defmacro  =defun (name parms &body body)
    (let ((f (gensym)))
      `(progn
        (defmacro ,name ,parms
          `(,',f %cont% ,,@parms))
        (defun ,f (%cont% ,@parms) ,@body) )))

  (defmacro  =bind (parms expr &body body)
    `(let ((%cont%  #'(lambda ,parms ,@body))) ,expr))

  (defmacro  =values (&rest retvals)
    `(funcall %cont% ,@retvals))

  (defmacro  =funcall (fn &rest args)
    `(funcall ,fn %cont% ,@args))

  (defmacro  =apply (fn &rest args)
    `(apply ,fn %cont% ,@args))
;; *************************************

(defvar h)

(let ((n 12000000))
   (defun delay ()
      (if (= n 0)
          (setq n 12000000)
          (progn
            (setq n (- n 1))
            (delay)) )))

(defun elsewhere ()
   (terpri)
   (princ "Jumped out of \"+\" function")
   (princ " after adding 2 and 3")
   (terpri)
   (terpri)
   (delay)
   (princ "Went to \"elsewhere\" function")
   (terpri)
   (terpri)
   (delay)
   (princ "Returned to \"+\" function\,")
   (princ " to \'continue\' our delayed ")
   (terpri)
   (princ "addition with our \"continuation\" ")
   (terpri)
   (terpri)
   (delay)
   (delay))

(defun demo ()
   (+ 2
         3
               (=bind () (=values)
                   (setq h #'(lambda ()
         4
         5
        22))
                  (elsewhere)
                  (funcall h))) ))


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.