Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion labels/flet for dynamic scope
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
 
Barry Margolin  
View profile  
 More options Aug 5 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Barry Margolin <bar...@bbnplanet.com>
Date: 1999/08/05
Subject: Re: labels/flet for dynamic scope
In article <cxjpv129bic....@acs5.bu.edu>, David Bakhash  <ca...@bu.edu> wrote:

>Barry Margolin <bar...@bbnplanet.com> writes:

>> That's only feasible if you have control over the code that will be calling
>> the function.  The impression I got from his example is that this code is
>> already written and presumably unchangeable, which is why he wants to
>> change what happens when it calls certain functions.  If you had access to
>> the source code you could simply remove the call to ERROR, or have it call
>> a different function that calls ERROR conditionally.

>that's exactly right.  I was making a call to a function that is provided by
>LW.  It was returning an error for an unknown reason, and I wanted a
>work-around.  Of course, I didn't have access to the source, so I setf'd the
>function definition of 'error to return nil no matter what, and then the
>funtion call worked just fine.

As I said earlier, if ERROR is all you're concerned with, use
IGNORE-ERRORS.  You shouldn't need to redefine ERROR when a standard
mechanism is provided.

>Basically, the behavior I wanted was that which happens in Emacs Lisp.  I
>wouldn't use it in real code; maybe just at the prompt.  Something like what
>Barry wrote would work.  I just wanted to know if there was a standard way
>about it.

>> Note one thing about my solution and the ERROR example: the consequences of
>> redefining built-in functions is not defined in Common Lisp.  A CL
>> implementation is permitted to generate inline code for built-in functions,
>> so redefining ERROR might not have any effect.  It could also invoke ERROR
>> internally, at times that you didn't expect (presumably depending on
>> internal condition handlers to hide this from you), so redefining ERROR
>> (even temporarily) could cause unexpected malfunctions.

>This is really a shame.  I understand that there's a performance issue here,
>and why there might therefore be a distinction between built-in functions and
>those defined by the user.  But I don't like it.  At the same time, however,
>the ability to inline code is important, and I don't know what the compiler
>would have to do in order to make inlined code safe when you setf something
>like (fdefinition 'error).

Inlining is not the only reason to prohibit redefining standard functions.
Imagine the havoc you could create if you redefined something like LIST or
DELETE, which are used extensively in the implementation.  Even if you
think you're redefining them compatibly, it's possible that the
implementation has dependencies on undocumented features that you weren't
aware of (perhaps they've implemented some function so that it never causes
a GC, and call it from places that can't tolerate GC occurring, but your
redefined version doesn't meet that constraint).

When we were writing this section of the standard we considered the
alternative of allowing programmers to redefine standard functions, but
specifying that such redefinitions should have no impact on the behavior of
other functions.  This would effectively require all the standard functions
to be implemented something like:

(defun common-lisp:delete (&rest args)
  (apply #internal:delete args))
(defun common-lisp:cons (car cdr)
  (internal:cons car cdr))

Internally, the implementation would use the versions from the INTERNAL
package, so that redefining functions in the COMMON-LISP package wouldn't
affect them.  We decided not to do this because of all the work that it
would entail for all the implementors, for little benefit.

Had we gone in this direction, your redefinition of ERROR wouldn't work,
either, because the function whose behavior you want to change was provided
by LW, so it would presumably call INTERNAL:ERROR, not COMMON-LISP:ERROR.

--
Barry Margolin, bar...@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.


    Reply to author    Forward  
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.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google