Lisp HUG Maillist Archive

A solution?

Here's one attempt at a solution...

(defmacro with-package-symbols (symbols package &body body)
  `(symbol-macrolet ,(mapcar (lambda (sym)
                               `(,sym ,(intern (symbol-name sym) (symbol-name package))))
                             symbols)
     ,@body))

(defun integrate (f a b)
  (with-package-symbols
      (within relerror accelerate-series euler integrate) lzs

    (within (relerror 1d-8)
            (accelerate-series #'euler
                               (integrate f a b)))))

Dr. David McClain
Chief Technical Officer
Refined Audiometrics Laboratory
4391 N. Camino Ferreo
Tucson, AZ  85750

email: dbm@refined-audiometrics.com
phone: 1.520.390.3995
web: http://refined-audiometrics.com



Re: A solution?

On Wed, Jul 09, 2008 at 10:50:46AM -0700, David McClain wrote:
> Here's one attempt at a solution...
> 
> (defmacro with-package-symbols (symbols package &body body)
>   `(symbol-macrolet ,(mapcar (lambda (sym)
>                                `(,sym ,(intern (symbol-name sym)  
> (symbol-name package))))
>                              symbols)
>      ,@body))
> 
> (defun integrate (f a b)
>   (with-package-symbols
>       (within relerror accelerate-series euler integrate) lzs
> 
>     (within (relerror 1d-8)
>             (accelerate-series #'euler
>                                (integrate f a b)))))

I was testing a similar solution, but I don't think it'll work.  E.g.:

  CL-USER 44 > (define-symbol-macro qwer progn)
  QWER

  CL-USER 45 > (qwer 1 2)

  Error: Undefined operator QWER in form (QWER 1 2).
  [snip]

I think you'll need to use local macros, not local symbol macros.

-- L


Re: A solution?

On 9 Jul 2008, at 18:50, David McClain wrote:

Here's one attempt at a solution...

(defmacro with-package-symbols (symbols package &body body)
  `(symbol-macrolet ,(mapcar (lambda (sym)
                               `(,sym ,(intern (symbol-name sym) (symbol-name package))))
                             symbols)
     ,@body))


You can't do this with macros, because it is far too late by then.  You need something that happens at read time, which is a long time before macros get expanded.  The hack of mine that Edi referred to does what you want, although it is not particularly attractive. I remember spending some time trying to find something more attractive (I was trying to copy what Genera allowed which was syntax like package:(this is all read in "PACKAGE")) but failed.

--tim
Updated at: 2020-12-10 08:42 UTC