Jump to content

Please explain this error handler to me


guitarguy1685

Recommended Posts

I've been using this error handler in lisps where I modify system variables for a while now. I can't remember where I found this code below.

 

  (setq *error*
    (lambda (msg)
      (setvar "CMDECHO" CRcecho)
      (setvar "CLAYER" CRlayr)
      (setvar "ATTREQ" CRattreq)
      (princ msg)
      (princ)))

 

What's going here? I've read LEE Mac's tutorial where it's used as a function. Lee Mac seems to use a pretty different method for error hadling. How is setq being used to reset all the sysvar?

Link to comment
Share on other sites

(setq *error* (lambda ( ... ) ... ) is merely an alternative to (defun *error* ( ... ) ... ) and just another way of assigning a function accepting a single argument to the *error* symbol.

Link to comment
Share on other sites

As far I understand the *error* (handler) function works as a callback function, when the code crashes/errors out

and accepts only one argument - the error message ( msg symbol in that example ).

It took me quite a while to understand the callback functions (most oftenly used in Reactors and DCL (action_tile)).

 

So overall it looks like a pseudo-reactor... with a :vlr-LispWillError event.

Link to comment
Share on other sites

As far I understand the *error* (handler) function works as a callback function, when the code crashes/errors out

and accepts only one argument - the error message ( msg symbol in that example ).

It took me quite a while to understand the callback functions (most oftenly used in Reactors and DCL (action_tile)).

 

So overall it looks like a pseudo-reactor... with a :vlr-LispWillError event.

 

 

I suppose I don't really understand callback functions. I'll read it up on it over the weekend. Thanks.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...