From: Pedro M. C. Pina
Subject: how to concatenae two symbols???
Date: 
Message-ID: <1029374394.970955@spynews3>
Can someone help me in that question:

I need a funcion that recive two  symbols and return one, that are the
resultt of concatenate the arguments. For example:

(concatenate-symb 'pedro '-pina) -> pedro-pina

I lost 2 days traing to do that can someone help me?

Thank you, Pedro.

From: Vijay L
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <1eaf81aa.0208142223.3650d713@posting.google.com>
"Pedro M. C. Pina" <·····@netcabo.pt> wrote in message news:<·················@spynews3>...
> Can someone help me in that question:
> 
> I need a funcion that recive two  symbols and return one, that are the
> resultt of concatenate the arguments. For example:
> 
> (concatenate-symb 'pedro '-pina) -> pedro-pina
> 
> I lost 2 days traing to do that can someone help me?
> 
> Thank you, Pedro.

Try using this function:
(defun make-atom (&rest args)
  (progn ;this is to avoid the multiple values returned by INTERN
    (intern (format nil "~{~A~}" args))))

Thanks,
Vijay
From: Hannah Schroeter
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <ajftjh$vu4$1@c3po.schlund.de>
Hello!

Vijay L <······@lycos.com> wrote:
>[...]

>Try using this function:
>(defun make-atom (&rest args)
>  (progn ;this is to avoid the multiple values returned by INTERN
>    (intern (format nil "~{~A~}" args))))

But progn does NOT "avoid" the multiple values.

However, why do you want to avoid them (i.e. cut all further
values off) in the first place? If there's really a good reason,
you could use prog1, though.

Kind regards,

Hannah.
From: Vijay L
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <1eaf81aa.0208150922.2b50248b@posting.google.com>
······@schlund.de (Hannah Schroeter) wrote in message news:<············@c3po.schlund.de>...
> Hello!
> 
> Vijay L <······@lycos.com> wrote:
> >[...]
>  
> >Try using this function:
> >(defun make-atom (&rest args)
> >  (progn ;this is to avoid the multiple values returned by INTERN
> >    (intern (format nil "~{~A~}" args))))
> 
> But progn does NOT "avoid" the multiple values.
> 
> However, why do you want to avoid them (i.e. cut all further
> values off) in the first place? If there's really a good reason,
> you could use prog1, though.
> 
> Kind regards,
> 
> Hannah.

"avoid" was the wrong word I guess; I dont know how PROGN works
exactly, I'm hoping you'll elaborate. I learnt about the existence of
MULTIPLE-VALUE-PROG1 and then found that (progn
(function-returning-multiple-values)) returned only the first value.
The reason I use it in MAKE-ATOM is that i dont need to know if the
INTERNing was one of the 3 possible values it usually takes and the
multiple values are a bloody pain (here) when debugging.

Thanks,

Vijay L
From: Tim Bradshaw
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <ey3hehvx1s2.fsf@cley.com>
* Vijay L wrote:
> I learnt about the existence of
> MULTIPLE-VALUE-PROG1 and then found that (progn
> (function-returning-multiple-values)) returned only the first value.

No, this is wrong.  PROGN's values are all the values of the past
expression in its body.  I think the idiomatic ways of getting the
just the first value are either:

   (VALUES mvf)

or (possibly, but I don't like it)

   (NTH-VALUE 0 mvf)

Something like

   (PROG1 mvf)

I'd regard as horrible.  However this is all a taste issue, they will
all work.

--tim
From: Erik Naggum
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <3238436747006793@naggum.no>
* Vijay L
| I learnt about the existence of MULTIPLE-VALUE-PROG1 and then found that
| (progn (function-returning-multiple-values)) returned only the first value.

* Tim Bradshaw
| No, this is wrong.

  Not to mention that it is wrong to discard these values in the first place.

-- 
Erik Naggum, Oslo, Norway

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.
From: Vijay L
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <1eaf81aa.0208151948.6e53c7a6@posting.google.com>
<····@naggum.no> wrote in message news:<················@naggum.no>...
> * Vijay L
> | I learnt about the existence of MULTIPLE-VALUE-PROG1 and then found that
> | (progn (function-returning-multiple-values)) returned only the first value.
> 
> * Tim Bradshaw
> | No, this is wrong.
> 
> * Erik Naggum
>   Not to mention that it is wrong to discard these values in the first place.

I don't understand. Why is it *wrong* to discard the values? I don't
care about the second value returned by INTERN. Why should I bother if
it is :INTERNAL :EXTERNAL or whatever? I don't program on that scale.
I've just started off. Nevertheless, by what Tim Bradshaw says if the
usage of PROGN is incorrect, and VALUES is a better choice, I stand
corrected on that aspect (please tell me why it is wrong though).

(defun make-atom (&rest args)
  (values ;to return only the first value returned by INTERN
   (intern (format nil "~{~A~}" args))))

Thanks,
Vijay L
From: Tim Bradshaw
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <ey3it2bdu8d.fsf@cley.com>
* Vijay L wrote:

> (defun make-atom (&rest args)
>   (values ;to return only the first value returned by INTERN
>    (intern (format nil "~{~A~}" args))))

This function has a catastrophic defect. This is often a defect which
happens in real code (as in: I've fixed bugs like this in at least two
large commercially available Lisp systems).

    > (defun make-atom (&rest syms)
        (intern (format nil "~{~A~}" syms)))
    make-atom

    (make-atom 'foo '- 'bar)
    |foo-bar|
    nil

Oops.  I have *PRINT-CASE* set to :DOWNCASE in my environment.

The way to fix this is to never rely on printing symbols.  This is a
better version of the same function.

    (defun make-atom (&rest syms/strings)
      (intern (format nil "~{~A~}"
                      (mapcar #'(lambda (s)
                                  (etypecase s
                                    (symbol (symbol-name s))
                                    (string s)))
                               syms/strings))))


--tim
From: Pierpaolo BERNARDI
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <Zk579.216718$Jj7.5090247@news1.tin.it>
"Tim Bradshaw" <···@cley.com> ha scritto nel messaggio ····················@cley.com...

> The way to fix this is to never rely on printing symbols.  This is a
> better version of the same function.
>
>     (defun make-atom (&rest syms/strings)
>       (intern (format nil "~{~A~}"
>                       (mapcar #'(lambda (s)
>                                   (etypecase s
>                                     (symbol (symbol-name s))
>                                     (string s)))
>                                syms/strings))))

Or even with

(mapcar #'string syms/strings)

Instead of

>                       (mapcar #'(lambda (s)
>                                   (etypecase s
>                                     (symbol (symbol-name s))
>                                     (string s)))
>                                syms/strings)

There should be no reason to be so exclusive.

P.
From: Tim Bradshaw
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <ey3vg6brq7n.fsf@cley.com>
* Pierpaolo BERNARDI wrote:

> There should be no reason to be so exclusive.

Depends on whether you can live with the `additional
implementation-defined' bit in STRING.  I generally wouldn't want to,
but that's just me, being paranoid.

--tim
From: Carl Shapiro
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <ouyn0rmoi4w.fsf@panix3.panix.com>
Tim Bradshaw <···@cley.com> writes:

> The way to fix this is to never rely on printing symbols.  This is a
> better version of the same function.
> 
>     (defun make-atom (&rest syms/strings)
>       (intern (format nil "~{~A~}"
>                       (mapcar #'(lambda (s)
>                                   (etypecase s
>                                     (symbol (symbol-name s))
>                                     (string s)))
>                                syms/strings))))

Why the specialization on type?  Calling STRING on each datum should
give you a copy of the symbol name for symbols and act as an identity
function in the case of strings.

(defun symbolconc (&rest symbols-or-strings)
  (intern (apply #'concatenate 'string (mapcar #'string symbols-or-strings))))
From: Tim Bradshaw
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <ey3u1luu3kg.fsf@cley.com>
* Carl Shapiro wrote:

> Why the specialization on type?  Calling STRING on each datum should
> give you a copy of the symbol name for symbols and act as an identity
> function in the case of strings.

Didn't I already answer this?  Sorry if I did.  STRING has
implementation-defined behaviour on things that aren't strings,
symbols or characters, and I didn't want that.

--tim
From: Carl Shapiro
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <ouy8z36qzpc.fsf@panix3.panix.com>
Tim Bradshaw <···@cley.com> writes:

> Didn't I already answer this?  Sorry if I did.  

Yes, you followed-up to another post (unsurprisingly at the same level
in this thread) regarding your issue with STRING.  I don't think those
messages were available to me when I had replied.

Sorry about that!
From: Thomas A. Russ
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <ymiptwil6ls.fsf@sevak.isi.edu>
Tim Bradshaw <···@cley.com> writes:

> The way to fix this is to never rely on printing symbols.  This is a
> better version of the same function.
> 
>     (defun make-atom (&rest syms/strings)
>       (intern (format nil "~{~A~}"
>                       (mapcar #'(lambda (s)
>                                   (etypecase s
>                                     (symbol (symbol-name s))
>                                     (string s)))
>                                syms/strings))))

A simpler form of this, which also handles characters and 
similarly throws error by bad input can use the STRING function:

  (defun make-atom (&rest syms/strings)
     (intern (format nil "~{~A~}" (mapcar #'string syms/strings))))



-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu    
From: Coby Beck
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <ut979.10859$Gl2.283321@wagner.videotron.net>
"Vijay L" <······@lycos.com> wrote in message
·································@posting.google.com...
> <····@naggum.no> wrote in message news:<················@naggum.no>...
> >   Not to mention that it is wrong to discard these values in the first
place.
>
> I don't understand. Why is it *wrong* to discard the values? I don't
> care about the second value returned by INTERN. Why should I bother if
> it is :INTERNAL :EXTERNAL or whatever? I don't program on that scale.

As a general principal, it is wrong to throw away information.  If you don't
need it (now at least!) just don't use it.  It takes special effort to
capture the second value anyway.  But why take pains to block it from any
potential future uses?  Assume it is returned for a good reason but you just
don't know why yet.

It is easier and better to just ignore any additional return values.

--
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")
From: Erik Naggum
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <3238508280043614@naggum.no>
* Vijay L
| I don't understand. Why is it *wrong* to discard the values? I don't care
| about the second value returned by INTERN. Why should I bother if it is
| :INTERNAL :EXTERNAL or whatever?

  Because you write your function also for others who might value these
  additional values from `intern�.

| I don't program on that scale.  I've just started off.

  Additional values will never get in your way unless you look for them.  What
  you do amounts to looking for them only to discard them.  This is stupid.

-- 
Erik Naggum, Oslo, Norway

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.
From: Vijay L
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <1eaf81aa.0208170435.3e033074@posting.google.com>
Erik Naggum <····@naggum.no> wrote in message news:<················@naggum.no>...
> * Vijay L
> | I don't understand. Why is it *wrong* to discard the values? I don't care
> | about the second value returned by INTERN. Why should I bother if it is
> | :INTERNAL :EXTERNAL or whatever?
> 
>   Because you write your function also for others who might value these
>   additional values from `intern�.

Yes I see that now. Here is my new version of the same function: (it
is the same one floating around written by Tim Bradshaw, and improved
by Pierpaolo Bernardi and others who I believe did it independantly
albeit later)
(defun make-atom (&rest strs/syms)
  (intern (format nil "~{~A~}"
                 (mapcar #'(lambda (x)
                             (if (or (stringp x) (symbolp x))
                                 (string x)
                               x))
                         strs/syms))))

>   Additional values will never get in your way unless you look for them.  
> ****** What you do amounts to looking for them only to discard them. ******
Well said.
 >This is stupid.

As I stated I threw them out because they were irritating when the
function was newly written. After finishing it I should have done so.
I now stand corrected.

Thanks everyone for you help again,

Vijay L
From: Tim Bradshaw
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <ey3hehwmm40.fsf@cley.com>
* Hannah Schroeter wrote:

> However, why do you want to avoid them (i.e. cut all further
> values off) in the first place? If there's really a good reason,
> you could use prog1, though.

I think VALUES is a better way of doing this:

   (VALUES form_1 form1_2 ...)

returns exactly one value from each of the form_i.

--tim
From: Coby Beck
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <cfF69.28177$Fa1.640752@wagner.videotron.net>
"Pedro M. C. Pina" <·····@netcabo.pt> wrote in message
······················@spynews3...
>
> Can someone help me in that question:
>
> I need a funcion that recive two  symbols and return one, that are the
> resultt of concatenate the arguments. For example:
>
> (concatenate-symb 'pedro '-pina) -> pedro-pina
>
> I lost 2 days traing to do that can someone help me?
>
> Thank you, Pedro.

The naive answer would be something like this:

(defun concatenate-symbols (&rest symbols)
    (intern (apply #'concatenate
                   'string  (mapcar #'symbol-name symbols))))


--
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")
From: Pascal Bourguignon
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <87it2az20g.fsf@thalassa.informatimago.com>
"Coby Beck" <·····@mercury.bc.ca> writes:

> "Pedro M. C. Pina" <·····@netcabo.pt> wrote in message
> ······················@spynews3...
> >
> > Can someone help me in that question:
> >
> > I need a funcion that recive two  symbols and return one, that are the
> > resultt of concatenate the arguments. For example:
> >
> > (concatenate-symb 'pedro '-pina) -> pedro-pina
> >
> > I lost 2 days traing to do that can someone help me?
> >
> > Thank you, Pedro.
> 
> The naive answer would be something like this:
> 
> (defun concatenate-symbols (&rest symbols)
>     (intern (apply #'concatenate
>                    'string  (mapcar #'symbol-name symbols))))
 

What makes you imagine that  he wants the symbol interned? make-symbol
is what he asked for.

-- 
__Pascal_Bourguignon__                   http://www.informatimago.com/
----------------------------------------------------------------------
 The name is Baud,...... James Baud.
From: Erik Naggum
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <3238543994620536@naggum.no>
* Pascal Bourguignon <·············@example.com>
| What makes you imagine that  he wants the symbol interned?

  That it was a clueless question?

-- 
Erik Naggum, Oslo, Norway

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.
From: Kaz Kylheku
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <ajls72$mvg$1@luna.vcn.bc.ca>
In article <··············@thalassa.informatimago.com>, Pascal Bourguignon
wrote:
> "Coby Beck" <·····@mercury.bc.ca> writes:
> 
>> "Pedro M. C. Pina" <·····@netcabo.pt> wrote in message
>> ······················@spynews3...
>> >
>> > I need a funcion that recive two  symbols and return one, that are the
>> > resultt of concatenate the arguments. For example:
>> >
>> > (concatenate-symb 'pedro '-pina) -> pedro-pina
>> 
>> The naive answer would be something like this:
>> 
>> (defun concatenate-symbols (&rest symbols)
>>     (intern (apply #'concatenate
>>                    'string  (mapcar #'symbol-name symbols))))
>  
> 
> What makes you imagine that  he wants the symbol interned?

What makes you imagine that Perdo had any clue about interned
versus uninterned symbols at the time the question was written? But the example
shows an interned symbol:

>> > (concatenate-symb 'pedro '-pina) -> pedro-pina

Note that the inputs are interned symbols, and so is the output. There is no #:
notation anywhere, so unless he operates with *print-escape* set to nil, that
output is an interned symbol.
From: Coby Beck
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <zjE79.11468$B5.110736@weber.videotron.net>
"Pascal Bourguignon" <·············@example.com> wrote in message
···················@thalassa.informatimago.com...
> "Coby Beck" <·····@mercury.bc.ca> writes:
>
> > "Pedro M. C. Pina" <·····@netcabo.pt> wrote in message
> > ······················@spynews3...
> > >
> > > Can someone help me in that question:
> > >
> > > I need a funcion that recive two  symbols and return one, that are the
> > > resultt of concatenate the arguments. For example:
> > >
> > > (concatenate-symb 'pedro '-pina) -> pedro-pina
> > >
> > > I lost 2 days traing to do that can someone help me?
> > >
> > > Thank you, Pedro.
> >
> > The naive answer would be something like this:
> >
> > (defun concatenate-symbols (&rest symbols)
> >     (intern (apply #'concatenate
> >                    'string  (mapcar #'symbol-name symbols))))
>
>
> What makes you imagine that  he wants the symbol interned? make-symbol
> is what he asked for.

Given the choice between giving an obvious newbie what he asks for versus
what he wants, I prefer to give him what he wants.  I qualified my answer
with "naive" and plenty of others brought up all the complications...

--
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")
From: Paul F. Dietz
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <3D5B0A49.B749DF29@dls.net>
"Pedro M. C. Pina" wrote:
> 
> Can someone help me in that question:
> 
> I need a funcion that recive two  symbols and return one, that are the
> resultt of concatenate the arguments. For example:
> 
> (concatenate-symb 'pedro '-pina) -> pedro-pina
> 
> I lost 2 days traing to do that can someone help me?

If the symbols are in different packages, which one do you want
it to be in?

  (concatenate-symb 'p1::a 'p2::b) -->  ?

Beyond that: use symbol-name, (concatenate 'string ...), symbol-package,
and intern.  And remember to specify a package argument to intern.  Although
that argument is optional, leaving it off is usually wrong.

	Paul
From: Christopher C. Stacy
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <ur8h0oi02.fsf@dtpq.com>
>>>>> On Thu, 15 Aug 2002 02:21:39 +0100, Pedro M C Pina ("Pedro") writes:
 Pedro> I need a funcion that recive two symbols and return one,
 Pedro> that are the resultt of concatenate the arguments.

This is the kind of question that makes experienced Lispers
want to ask you, "Why would you want to do that?"

It's a reasonable thing to want to do for a variety of reasons, 
but if you are new enough to Lisp to not already know how to
accomplish it, it is likely that you are going down the wrong
path in wanting to do it.

Here are two questions I would ask back to you: 
Why have you chosen the SYMBOL data type for these things
that you're sticking together?   Are you sure you don't
want to use a STRING?
From: Pascal Bourguignon
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <87hehw96w5.fsf@thalassa.informatimago.com>
"Pedro M. C. Pina" <·····@netcabo.pt> writes:

> Can someone help me in that question:
> 
> I need a funcion that recive two  symbols and return one, that are the
> resultt of concatenate the arguments. For example:
> 
> (concatenate-symb 'pedro '-pina) -> pedro-pina
> 
> I lost 2 days traing to do that can someone help me?
> 
> Thank you, Pedro.

(make-symbol (concatenate 'string (symbol-name 'pedro) (symbol-name '-pina)))

(defun concatenate-symb (&rest args)
    (make-symbol (apply 'concatenate 
                     (cons 'string  (mapcar 'symbol-name args)))))


-- 
__Pascal_Bourguignon__                   http://www.informatimago.com/
----------------------------------------------------------------------
 The name is Baud,...... James Baud.
From: Kaz Kylheku
Subject: Re: how to concatenae two symbols???
Date: 
Message-ID: <aji2l6$nu2$3@luna.vcn.bc.ca>
In article <·················@spynews3>, Pedro M. C. Pina wrote:
> 
> Can someone help me in that question:
> 
> I need a funcion that recive two  symbols and return one, that are the
> resultt of concatenate the arguments. 

You should be made aware of the silliness of what you are asking for.

A Lisp symbol is a data structure, not a string.  It carries a multitude of
properties. 

One of those properties is a symbol's *name*, which is a string.

You can catenate two strings, but what does it mean to catenate two symbols?
Their names can be catenated, but what about the rest of the properties?

If you think that your Lisp program needs to pull out the names of two symbols,
catenate them, and then manufacture a new symbol whose name is the resulting
string, you are probably thinking wrongly. Symbols are not the best data
structure for your problem; it is more likely that strings are, since you are
really doing text processing, rather than symbol manipulation.

> (concatenate-symb 'pedro '-pina) -> pedro-pina
> 
> I lost 2 days traing to do that can someone help me?

;;
;; really silly thing to do
;;
(intern (concatenate 'string 
                     (symbol-name 'pedro)
                     (symbol-name '-pina)))

Interning lots of symbols at run time can perform poorly and waste lots of
space. Once a symbol is interned, it will stay interned until it is explicitly
uninterned, because its home package acts as a reference to it.

Unless you really know what you are doing, the only kinds of symbols you should
ever need to manufacture at run time in your Lisp program are
uninterned-symbols, which are not entered into any package and consequently
subject to storage reclamation when they become unreachable, like other
ordinary objects. You can make one of these using make-symbol:

  (make-symbol "PEDRO")
  ==> #:PEDRO

The gensym function makes uninterned symbols, whose names are derived
by converting an incrementing counter to a string, and prepending a prefix.

  (gensym)  => #:G246
  (gensym)  => #:G247
  (gensym "FOO-") => #:FOO-248

Even so, you have to be a Lisp guru to find a use for making gensyms
other than at macroexpansion time.