From: Mike Eggleston
Subject: backquote a symbol?
Date: 
Message-ID: <slrn9oks3f.al1.mikee@kensho.eggtech.com>
I'm playing with lisp some and am trying to make a macro.
What I want is to hand a symbol to a function and have
that function print a readable form of the symbol out to
stdout or a stream. I'm not looking for the open file
symantics just yet, only the macro.

(defmacro psexp (sym)
	(print ,'sym)
	(print sym))

(setq test1 '(1 2 3 4))
(psexp 'sym)
 =>
 	(setq test1 '(1 2 3 4))


Mike

From: Coby Beck
Subject: Re: backquote a symbol?
Date: 
Message-ID: <yZvi7.78475$0X.15185668@typhoon.tampabay.rr.com>
"Mike Eggleston" <·····@kensho.eggtech.com> wrote in message
·························@kensho.eggtech.com...
> I'm playing with lisp some and am trying to make a macro.
> What I want is to hand a symbol to a function and have
> that function print a readable form of the symbol out to
> stdout or a stream. I'm not looking for the open file
> symantics just yet, only the macro.
>

CL-USER 3 > (defmacro psexp (sym)
                          `(print ',sym))
PSEXP

CL-USER 4 > (psexp foo)

FOO
FOO

Like that?

Coby
--
(remove #\space "coby . beck @ opentechgroup . com")
From: Christopher Stacy
Subject: Re: backquote a symbol?
Date: 
Message-ID: <ubsl141p9.fsf@spacy.Boston.MA.US>
>>>>> On Mon, 27 Aug 2001 16:08:14 GMT, Mike Eggleston ("Mike") writes:
 Mike> I'm playing with lisp some and am trying to make a macro.

 Mike> What I want is to hand a symbol to a function and have
 Mike> that function print a readable form of the symbol out to
 Mike> stdout or a stream. I'm not looking for the open file
 Mike> symantics just yet, only the macro.

Mike,

You're trying to make this a lot more complicated than necessary.  
You don't need a macro do this.  Symbols are an ordinary type of data,
and Lisp functions can manipulate them as easily as any other thing.
A symbol (like most anything else) can be output to a file with PRINT,
and input with READ.

Here is a function that does what you are asking.  I have included 
the file stream protocol in it, because otherwise there would be
nothing to the function --  all it does is call PRINT!

(defun psexp (sym file)
   (with-open-file (o file :direction :output)
     (print sym o)))

The corresponding input function simply needs to call READ.
(In a real program, you might be concerned with controlling
certain parameters of READ, but you can ignore all that for now.)

Of course, the above function will PRINT anything to the file,
not just symbols.  However, not every piece of Lisp data can be 
reconstructed by READ, and there can be other issues involving
object identity that are important in many applications.
But for very simple purposes, you can just PRINT/READ to a file.

You would call the PSEXP function above like this:

  (PSEXP 'CHEESE-PIZZA)

Now let's look at the example code from your message...

 Mike> (defmacro psexp (sym)
 Mike> 	 (print ,'sym)
 Mike> 	 (print sym))
 Mike> (setq test1 '(1 2 3 4))
 Mike> (psexp 'sym)
 Mike>  =>
 Mike>  (setq test1 '(1 2 3 4))

This doesn't make any sense, and looks like you are somewhat confused
and mixed up about many basic elements of Lisp, including functions,
symbols, variables, and quoting.  Rather than trying to explain
everything all at once, I'll let you consider what I've already
written and ask more questions from that point.

Chris
From: Coby Beck
Subject: Re: backquote a symbol?
Date: 
Message-ID: <EaPi7.86125$0X.16418963@typhoon.tampabay.rr.com>
> I tried with the (print), but am looking for something that can
> receive a symbol and print the full (setq) line for that symbol
> so that a (read) and (eval) reloads the symbol definition into core.
>
> Mike
>

How about:

CL-USER 17 > (setf foo 27)
27

CL-USER 18 > (defun print-setf-form (symbol &optional (stream
*standard-output*))
              (print `(setf ,symbol ,(symbol-value symbol)) stream))
PRINT-SETF-FORM

CL-USER 19 > (print-setf-form 'foo)

(SETF FOO 27)
(SETF FOO 27)

Coby
--
(remove #\space "coby . beck @ opentechgroup . com")
From: Barry Margolin
Subject: Re: backquote a symbol?
Date: 
Message-ID: <ShPi7.11$4j1.260@burlma1-snr2>
In article <·······················@typhoon.tampabay.rr.com>,
Coby Beck <·····@mercury.bc.ca> wrote:
>CL-USER 18 > (defun print-setf-form (symbol &optional (stream
>*standard-output*))
>              (print `(setf ,symbol ,(symbol-value symbol)) stream))

Your function won't work properly if the value of the symbol isn't a
self-evaluating object.  See my earlier post.

-- 
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.