Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!ceylon!wizard.pn.com!Germany.EU.net!EU.net!howland.reston.ans.net!swrinde!pipex!uknet!festival!edcogsci!jeff
From: jeff@aiai.ed.ac.uk (Jeff Dalton)
Subject: Re: Macros vs. Special opertors (was Re: SETQ is to SET as LET is to ???)
Message-ID: <CzqCq5.MnB@cogsci.ed.ac.uk>
Keywords: lisp, common lisp, progv, let, unwind-protect, special form
Sender: usenet@cogsci.ed.ac.uk (C News Software)
Nntp-Posting-Host: bute-alter.aiai.ed.ac.uk
Organization: AIAI, University of Edinburgh, Scotland
References: <3aiuup$t04@tools.near.net> <CzopDG.M06@cogsci.ed.ac.uk> <3atror$6i3@tools.near.net>
Date: Wed, 23 Nov 1994 17:03:41 GMT
Lines: 57

In article <3atror$6i3@tools.near.net> barmar@nic.near.net (Barry Margolin) writes:
>In article <CzopDG.M06@cogsci.ed.ac.uk> jeff@aiai.ed.ac.uk (Jeff Dalton) writes:
>>I'm pretty sure that nothing prevents PROGV from begin defined as
>>
>>  (defmacro progv (&rest whatever)
>>    `(do-a-progv-somehow ',whatever))
>>
>>  (defun do-a-progv-somehow (args)
>>    (whatever-magic-internal-stuff-you-want args))
>
>True.  In fact, I believe the standard explicitly says that special forms
>may be implemented as macros.
>
>But a program analysis program would probably have to know about PROGV
>specially, so it would never bother expanding this macro.
>
>>But suppose the intent you mention above had been realized
>>in spirit as well as in letter.  (My do-a-progv-somehow is
>>consistent with the letter).
>
>The above isn't what I said.  I said that the expansions of standard macros
>should eventually reach functions or standard special forms.  I didn't
>address expansions of special operators that happen to be implemented as
>macros.

I know that.  My point was that you may not be able to analzye the
code even if macro expansion eventually reaches functions of
standard special forms.  So in practice, standard macros may
have to be treated as special cases, just as if they were special
forms.  So what's actually accomplished by making something *be*
a special form?

>>Why would PROGV then have to be a special form?
>
>If PROGV were documented in the standard as being a macro, there would have
>to be a special form for it to expand into.   I.e. we would have to
>standardize something that plays the role of your operator
>WHATEVER-MAGIC-INTERNAL-STUFF-YOU-WANT.

Perhaps not.  For instance, in a shallow-binding implementation, you could
use unwind-protect and set.  Or consider this one:

  (defmacro *progv (syms vals &rest forms)
     (let ((thunk (gensym "THUNK-")))
      `(let ((,thunk #'(lambda () ,@forms)))
         (declare (special ,thunk))
         (eval 
           (make-a-let ,syms ,vals ',thunk)))))

  (defun make-a-let (syms vals thunk)
    `(let ,(mapcar #'(lambda (s v) `(,s ',v)) syms vals)
       (declare (special ,@syms))
       (funcall 
         (locally (declare (special ,thunk))
           ,thunk))))

-- jeff
