From: Peter Seibel
Subject: There's no clever way to cause LOAD to bind vars other than *PACKAGE* and *READTABLE* is there?
Date: 
Message-ID: <m3ekjq76nq.fsf@javamonkey.com>
I'm pretty sure there's no way to do this but I thought I'd ask just
in case:

I'm writing some macros whose behavior can be slightly parameterized
based on some global variables, e.g.

    (defmacro html (&body body)
      (case *html-syntax*
        (:html  (generate-html-generator body))
        (:xhtml (generate-xhtml-generator body))))

A can easily enough provide a nice way to set *HTML-SYNTAX* wrapped in
the appropriate eval-when foo:

    (defmacro using-html-syntax (syntax)
      `(eval-when (:compile-top-level :load-top-level :execute)
         (setf *html-syntax* ,syntax)))

But this has the problem that a call to USING-HTML-SYNTAX sets it for
everyone, everywhere. So my question is, is there some clever trick
I'm missing to cause LOAD to bind *HTML-SYNTAX* the same way it binds
*PACKAGE* and *READTABLE* so calls to USING-HTML-SYNTAX in one file
don't affect code in other files? Or some other way of achieving the
same affect without wrapping my whole file in a big WITH-HTML-SYNTAX
macro?

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp

From: Thomas A. Russ
Subject: Re: There's no clever way to cause LOAD to bind vars other than  *PACKAGE* and *READTABLE* is there?
Date: 
Message-ID: <ymism868f4u.fsf@sevak.isi.edu>
Peter Seibel <·····@javamonkey.com> writes:

>  So my question is, is there some clever trick
> I'm missing to cause LOAD to bind *HTML-SYNTAX* the same way it binds
> *PACKAGE* and *READTABLE* so calls to USING-HTML-SYNTAX in one file
> don't affect code in other files? Or some other way of achieving the
> same affect without wrapping my whole file in a big WITH-HTML-SYNTAX
> macro?

Sadly, no.

You are pretty much reduced to shadowing LOAD or using a different name
and having that function do the variable binding for you.

Actually, a non-portable solution is available in those CL systems that
allow you to ADVISE functions.  You can effectively wrap the functions
in the advice wrappers that will do the bindings for you.

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Pascal Costanza
Subject: Re: There's no clever way to cause LOAD to bind vars other than   *PACKAGE* and *READTABLE* is there?
Date: 
Message-ID: <clc1re$9sv$1@newsreader2.netcologne.de>
Peter Seibel wrote:

> A can easily enough provide a nice way to set *HTML-SYNTAX* wrapped in
> the appropriate eval-when foo:
> 
>     (defmacro using-html-syntax (syntax)
>       `(eval-when (:compile-top-level :load-top-level :execute)
>          (setf *html-syntax* ,syntax)))
> 
> But this has the problem that a call to USING-HTML-SYNTAX sets it for
> everyone, everywhere. So my question is, is there some clever trick
> I'm missing to cause LOAD to bind *HTML-SYNTAX* the same way it binds
> *PACKAGE* and *READTABLE* so calls to USING-HTML-SYNTAX in one file
> don't affect code in other files? Or some other way of achieving the
> same affect without wrapping my whole file in a big WITH-HTML-SYNTAX
> macro?

Either

(defmacro using-html-syntax (syntax)
   `(eval-when (:compile-top-level :load-top-level :execute)
      (warn "html syntax changed")
      (setf *old-html-syntax* *html-syntax*
            *html-syntax* ,syntax)))

(defmacro reset-html-syntax ()
   `(eval-when (:compile-top-level :load-top-level :execute)
      (setf *html-syntax* *old-html-syntax*)))

Use reset-html-syntax at the end of the file. When this is missed, at 
least you have seen the warning.

Or

(let ((*html-syntax* *html-syntax*))
   (load ...))


Pascal

-- 
Tyler: "How's that working out for you?"
Jack: "Great."
Tyler: "Keep it up, then."
From: Peter Seibel
Subject: Re: There's no clever way to cause LOAD to bind vars other than  *PACKAGE* and *READTABLE* is there?
Date: 
Message-ID: <m3acue732m.fsf@javamonkey.com>
Pascal Costanza <········@web.de> writes:

> Peter Seibel wrote:
>
>> A can easily enough provide a nice way to set *HTML-SYNTAX* wrapped in
>> the appropriate eval-when foo:
>>     (defmacro using-html-syntax (syntax)
>>       `(eval-when (:compile-top-level :load-top-level :execute)
>>          (setf *html-syntax* ,syntax)))

>> But this has the problem that a call to USING-HTML-SYNTAX sets it
>> for everyone, everywhere. So my question is, is there some clever
>> trick I'm missing to cause LOAD to bind *HTML-SYNTAX* the same way
>> it binds *PACKAGE* and *READTABLE* so calls to USING-HTML-SYNTAX in
>> one file don't affect code in other files? Or some other way of
>> achieving the same affect without wrapping my whole file in a big
>> WITH-HTML-SYNTAX macro?
>
> Either
>
> (defmacro using-html-syntax (syntax)
>    `(eval-when (:compile-top-level :load-top-level :execute)
>       (warn "html syntax changed")
>       (setf *old-html-syntax* *html-syntax*
>             *html-syntax* ,syntax)))
>
> (defmacro reset-html-syntax ()
>    `(eval-when (:compile-top-level :load-top-level :execute)
>       (setf *html-syntax* *old-html-syntax*)))
>
> Use reset-html-syntax at the end of the file. When this is missed, at
> least you have seen the warning.

Shouldn't that be more like:

  (defmacro using-html-syntax (syntax)
     `(eval-when (:compile-top-level :load-top-level :execute)
        (when *old-html-syntax*
          (warn "html syntax previously changed and not reset"))
        (setf *old-html-syntax* *html-syntax*
              *html-syntax* ,syntax)))

  (defmacro reset-html-syntax ()
     `(eval-when (:compile-top-level :load-top-level :execute)
        (setf *html-syntax* *old-html-syntax*
              *old-html-syntax* nil)))

Or better yet:

  (defmacro using-html-syntax (syntax)
     `(eval-when (:compile-top-level :load-top-level :execute)
        (when *old-html-syntax*
          (warn "html syntax previously changed in ~a and not reset"
                *html-syntax-changed-in*))
        (setf *old-html-syntax* *html-syntax*
              *html-syntax-changed-in* (or *load-pathname* *compile-file-pathname*)
              *html-syntax* ,syntax)))

  (defmacro reset-html-syntax ()
     `(eval-when (:compile-top-level :load-top-level :execute)
        (setf *html-syntax* *old-html-syntax*
              *old-html-syntax* nil
              *html-syntax-changed-in* nil)))

> Or
>
> (let ((*html-syntax* *html-syntax*))
>    (load ...))

Sure. But now I have to go hack ASDF to do this too. Hmmm. Maybe
that's not so crazy--since the feature I really want is to be able to
specify certain variables that should be bound during a LOAD or
COMPILE-FILE and ASDF (or other any other sytem definition facility)
is responsible for loading and compile-file'ing things for me, that's
not a crazy place to put such a feature. Of course then any code that
relies on that feature becomes tied to that system definition tool.
Hmmmm.

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp