From: Joe
Subject: Newbie's question --- GENSYM
Date: 
Message-ID: <9srgfu$i45$1@news.seed.net.tw>
Hi,

I read a book, it says the function GENSYM can generate a symbol. But it
does not discuss more about how to use it.
Therefore, I made some trials to test this function want to know more about
it:

(gensym) => #:G1252
(setq #:G1252 "value") => "value"
#:G1252 => *** - EVAL: variable #:G1252 has no value

I found I can't assign a value to #:G1252
so, I continue testing

(setq var '#:G1252)
(symbol-name var) => "G1252"

I found the name of the symbol is "G1252" rather than "#:G1252"
so, I tried to make other test

(setq #:my-variable "value") => "value"
#:my-variable => *** - EVAL: variable #:MY-VARIABLE has no value

I found even if I use a brand-new symbol name(it wasn't generated by GENSYM)
but precede with `#:', I can't sill get the value...
then I got some questions:

1) What does `#:' means? If I try to assign a value to any symbol that
precede with `#:' then I can't get the symbol's value.

2) Is it possible to design a function FUNC, so that it will get the same
results as following:

(setq Str1 "HELLO-") => "HELLO-"
(setq Str2 "WORLD") => "WORLD"

(setq var (FUNC Str1 Str2)) => HELLO-WORLD
(set var "value") => "value"
hello-world => "value"

Thank you
Joe

From: Barry Margolin
Subject: Re: Newbie's question --- GENSYM
Date: 
Message-ID: <ddcI7.13$CG2.512@burlma1-snr2>
In article <············@news.seed.net.tw>, Joe <······@kimo.com.tw> wrote:
>I found even if I use a brand-new symbol name(it wasn't generated by GENSYM)
>but precede with `#:', I can't sill get the value...
>then I got some questions:
>
>1) What does `#:' means? If I try to assign a value to any symbol that
>precede with `#:' then I can't get the symbol's value.

#: is a prefix used to enter an uninterned symbol.  Each time you type it,
a new symbol will be created.

>2) Is it possible to design a function FUNC, so that it will get the same
>results as following:
>
>(setq Str1 "HELLO-") => "HELLO-"
>(setq Str2 "WORLD") => "WORLD"
>
>(setq var (FUNC Str1 Str2)) => HELLO-WORLD
>(set var "value") => "value"
>hello-world => "value"

(defun func (str1 str2)
  (intern (concatenate 'string str1 str2)))

-- 
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: Vladimir Zolotykh
Subject: Re: Newbie's question --- GENSYM
Date: 
Message-ID: <3BF1516B.D837BAE@eurocom.od.ua>
Joe wrote:
> 
> I found I can't assign a value to #:G1252

puzzle(195): (let ((sym (gensym))) (setq sym "value") sym)
"value"
puzzle(196): (let ((sym (gensym))) (eq sym sym))
t


-- 
Vladimir Zolotykh                         ······@eurocom.od.ua
From: Barry Margolin
Subject: Re: Newbie's question --- GENSYM
Date: 
Message-ID: <I_cI7.15$CG2.418@burlma1-snr2>
In article <················@eurocom.od.ua>,
Vladimir Zolotykh  <······@eurocom.od.ua> wrote:
>Joe wrote:
>> 
>> I found I can't assign a value to #:G1252
>
>puzzle(195): (let ((sym (gensym))) (setq sym "value") sym)
>"value"

What's the point of that?  You assign to SYM and then assign to it again.
The gensym is never used.  I suspect you meant:

(let ((sym (gensym)))
  (set sym "value")
  (symbol-value sym))

-- 
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: Vladimir Zolotykh
Subject: Re: Newbie's question --- GENSYM
Date: 
Message-ID: <3BF173AE.39A393D2@eurocom.od.ua>
Barry Margolin wrote:

> (let ((sym (gensym)))
>   (set sym "value")
>   (symbol-value sym))

Of course(let ((sym (gensym))) (set sym "value") (symbol-value sym))
Sorry for mistake.
From: Steve Long
Subject: Re: Newbie's question --- GENSYM
Date: 
Message-ID: <3BF1EDC1.C768172@isomedia.com>
Create-and-assign-a-value

#'(lambda(value)(let ((sym (gensym))) (set symbol value) sym))

Retrieve-the-value

#'(lambda(sym)(when (boundp sym) (symbol-value sym))

Joe wrote:

> Hi,
>
> I read a book, it says the function GENSYM can generate a symbol. But it
> does not discuss more about how to use it.
> Therefore, I made some trials to test this function want to know more about
> it:
>
> (gensym) => #:G1252
> (setq #:G1252 "value") => "value"
> #:G1252 => *** - EVAL: variable #:G1252 has no value
>
> I found I can't assign a value to #:G1252
> so, I continue testing
>
> (setq var '#:G1252)
> (symbol-name var) => "G1252"
>
> I found the name of the symbol is "G1252" rather than "#:G1252"
> so, I tried to make other test
>
> (setq #:my-variable "value") => "value"
> #:my-variable => *** - EVAL: variable #:MY-VARIABLE has no value
>
> I found even if I use a brand-new symbol name(it wasn't generated by GENSYM)
> but precede with `#:', I can't sill get the value...
> then I got some questions:
>
> 1) What does `#:' means? If I try to assign a value to any symbol that
> precede with `#:' then I can't get the symbol's value.
>
> 2) Is it possible to design a function FUNC, so that it will get the same
> results as following:
>
> (setq Str1 "HELLO-") => "HELLO-"
> (setq Str2 "WORLD") => "WORLD"
>
> (setq var (FUNC Str1 Str2)) => HELLO-WORLD
> (set var "value") => "value"
> hello-world => "value"
>
> Thank you
> Joe