From: thelifter
Subject: What exactly is a symbol macro?
Date: 
Message-ID: <b295356a.0211181018.292973fe@posting.google.com>
I found the following in the hyperspec:

symbol macro n. a symbol that stands for another form. 
(http://www-2.cs.cmu.edu/Groups/AI/html/hyperspec/HyperSpec/Body/glo_s.html#symbol_macro)

As a newbie this doesn't explain that much to me. Can someone provide
a better explanation? Ok I will try it myself first:

A symbol macro is a macro without arguments?

Thanks for any feedback....

From: Barry Margolin
Subject: Re: What exactly is a symbol macro?
Date: 
Message-ID: <QpaC9.9$aO1.417@paloalto-snr1.gtei.net>
In article <····························@posting.google.com>,
thelifter <·········@gmx.net> wrote:
>I found the following in the hyperspec:
>
>symbol macro n. a symbol that stands for another form. 
>(http://www-2.cs.cmu.edu/Groups/AI/html/hyperspec/HyperSpec/Body/glo_s.html#symbol_macro)
>
>As a newbie this doesn't explain that much to me. Can someone provide
>a better explanation? Ok I will try it myself first:

Read the description of the SYMBOL-MACROLET special operator.

>A symbol macro is a macro without arguments?

That's a good start, but it doesn't really express it all.  A better
one-line summary would be: A symbol macro is a macro without arguments that
is used like a variable name.

A symbol macro is expanded whenever the symbol appears in a variable
context, i.e. either as an expression by itself, or as the target of an
assignment (and SETQ or PSETQ is automatically treated as if it were SETF
or PSETF, so the macro can expand into a SETF-able place).

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, 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.
From: Barry Margolin
Subject: Re: What exactly is a symbol macro?
Date: 
Message-ID: <HraC9.10$aO1.742@paloalto-snr1.gtei.net>
In article <···············@paloalto-snr1.gtei.net>,
Barry Margolin  <······@genuity.net> wrote:
>In article <····························@posting.google.com>,
>thelifter <·········@gmx.net> wrote:
>>I found the following in the hyperspec:
>>
>>symbol macro n. a symbol that stands for another form. 
>>(http://www-2.cs.cmu.edu/Groups/AI/html/hyperspec/HyperSpec/Body/glo_s.html#symbol_macro)
>>
>>As a newbie this doesn't explain that much to me. Can someone provide
>>a better explanation? Ok I will try it myself first:
>
>Read the description of the SYMBOL-MACROLET special operator.

Also see section 3.1.2.1.1 Symbols as Forms.  The second paragraph
describes how symbol macros are expanded.

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, 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.
From: Tim Bradshaw
Subject: Re: What exactly is a symbol macro?
Date: 
Message-ID: <ey3of8moglo.fsf@cley.com>
* thelifter  wrote:

> A symbol macro is a macro without arguments?

I think the hyperspec glossary is pretty good actually.  A symbol
macro is precisely a symbol which `stands for another form'.  So
whenever it's seen the other form is substituted.  So, if I do:

 (let ((x (cons 1 2)))
   (symbol-macrolet ((carx (car x)))
     (setf carx 3)
     x))

It's *exactly* as if I'd typed:

 (let ((x (cons 1 2)))
   (setf (car x) 3)
   x)

- it's just trivial substitution.  There is one rule that you need to
know (and some more as well, actually), and that is that if you say:

 (symbol-macrolet ((x ...))
   ...
   (setq x ...)                  ;SETQ
   ...)

This is treated as if you'd said:

 (symbol-macrolet ((x ...))
   ...
   (setf x ...)                  ;SETF
   ...)

This is needed so that assignment `works right'.

The reason symbol macros were invented, I think, is to implement
WITH-SLOTS & friends in CLOS.  For WITH-SLOTS you want the `variables
bound to slots' to be equivalent to SLOT-VALUE forms, and that is
exactly what symbol macros let you do.  So CLOS doesn't need special
magic (or rather: the special magic is available for other purposes
too).

Your `macro without arguments' is kind of right, but to me it could be
confused with something like

 (macrolet ((x () ...))

--tim
From: Kent M Pitman
Subject: Re: What exactly is a symbol macro?
Date: 
Message-ID: <sfwsmxyi8mn.fsf@shell01.TheWorld.com>
Tim Bradshaw <···@cley.com> writes:

> * thelifter  wrote:
> 
> > A symbol macro is a macro without arguments?
> 
> I think the hyperspec glossary is pretty good actually.  A symbol
> macro is precisely a symbol which `stands for another form'.  So
> whenever it's seen the other form is substituted.  So, if I do:
> 
>  (let ((x (cons 1 2)))
>    (symbol-macrolet ((carx (car x)))
>      (setf carx 3)
>      x))
> 
> It's *exactly* as if I'd typed:
> 
>  (let ((x (cons 1 2)))
>    (setf (car x) 3)
>    x)
> 
> - it's just trivial substitution.

(Modulo the fact that it respects enclosed let bindings.
That is, the "trivial substitution" doesn't mean "use of SUBST".)

> [...]
> Your `macro without arguments' is kind of right, but to me it could be
> confused with something like
> 
>  (macrolet ((x () ...))

I mentioned in my talk at ILC that in infix languages we talk about 
operators as

  sin x     prefix "sin"
  x+y       infix "+"
  n!        postfix "!"
  [a,b,c]   matchfix "["..."]"

and in this context we sometimes have "nofix" operators that have no
left or right component.  these often represent "active functions" that
can vary behind your back between uses. e.g., a variable whose name was
temperature might secretly read a thermometer, so

 temperature+temperature

might not always return even numbers the way a let binding would.
So

 (symbol-macrolet ((temperature (get-current-room-temperature)))
   (+ temperature temperature))

differs from 

 (macrolet ((temperature () `(get-current-room-temperature)))
   (+ (temperature) (temperature)))

in the same way that

 temperature + temperature

differs from

 temperature() + temperature()