Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to concatenae two symbols???

20 views
Skip to first unread message

Pedro M. C. Pina

unread,
Aug 14, 2002, 9:21:39 PM8/14/02
to

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.


Paul F. Dietz

unread,
Aug 14, 2002, 9:54:50 PM8/14/02
to

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

Pascal Bourguignon

unread,
Aug 14, 2002, 10:45:46 PM8/14/02
to

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

Coby Beck

unread,
Aug 14, 2002, 11:38:04 PM8/14/02
to

"Pedro M. C. Pina" <pp...@netcabo.pt> wrote in message
news:1029374394.970955@spynews3...

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")

Christopher C. Stacy

unread,
Aug 15, 2002, 12:36:48 AM8/15/02
to
>>>>> 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?


Vijay L

unread,
Aug 15, 2002, 2:23:21 AM8/15/02
to
"Pedro M. C. Pina" <pp...@netcabo.pt> wrote in message news:<1029374394.970955@spynews3>...

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

Hannah Schroeter

unread,
Aug 15, 2002, 5:51:45 AM8/15/02
to
Hello!

Vijay L <vij...@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.

Tim Bradshaw

unread,
Aug 15, 2002, 6:50:55 AM8/15/02
to
* 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

Vijay L

unread,
Aug 15, 2002, 1:22:17 PM8/15/02
to
han...@schlund.de (Hannah Schroeter) wrote in message news:<ajftjh$vu4$1...@c3po.schlund.de>...

"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

Tim Bradshaw

unread,
Aug 15, 2002, 5:14:37 PM8/15/02
to
* 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

Erik Naggum

unread,
Aug 15, 2002, 5:45:47 PM8/15/02
to
* 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.

Vijay L

unread,
Aug 15, 2002, 11:48:50 PM8/15/02
to
<er...@naggum.no> wrote in message news:<32384367...@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

Kaz Kylheku

unread,
Aug 16, 2002, 1:30:15 AM8/16/02
to
In article <1029374394.970955@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.

Tim Bradshaw

unread,
Aug 16, 2002, 5:32:34 AM8/16/02
to
* 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

Pierpaolo BERNARDI

unread,
Aug 16, 2002, 7:27:53 AM8/16/02
to

"Tim Bradshaw" <t...@cley.com> ha scritto nel messaggio news:ey3it2b...@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.


Tim Bradshaw

unread,
Aug 16, 2002, 7:35:40 AM8/16/02
to
* 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


Coby Beck

unread,
Aug 16, 2002, 12:17:41 PM8/16/02
to

"Vijay L" <vij...@lycos.com> wrote in message
news:1eaf81aa.02081...@posting.google.com...

> <er...@naggum.no> wrote in message news:<32384367...@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.

Carl Shapiro

unread,
Aug 16, 2002, 12:58:23 PM8/16/02
to
Tim Bradshaw <t...@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))))

Tim Bradshaw

unread,
Aug 16, 2002, 1:16:31 PM8/16/02
to
* 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

Erik Naggum

unread,
Aug 16, 2002, 1:38:00 PM8/16/02
to
* 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.

Carl Shapiro

unread,
Aug 16, 2002, 5:08:15 PM8/16/02
to
Tim Bradshaw <t...@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!

Thomas A. Russ

unread,
Aug 16, 2002, 7:35:43 PM8/16/02
to
Tim Bradshaw <t...@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 t...@isi.edu

Pascal Bourguignon

unread,
Aug 16, 2002, 9:51:11 PM8/16/02
to
"Coby Beck" <cb...@mercury.bc.ca> writes:

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

Erik Naggum

unread,
Aug 16, 2002, 11:33:14 PM8/16/02
to
* Pascal Bourguignon <too.mu...@example.com>

| What makes you imagine that he wants the symbol interned?

That it was a clueless question?

Vijay L

unread,
Aug 17, 2002, 8:35:15 AM8/17/02
to
Erik Naggum <er...@naggum.no> wrote in message news:<32385082...@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

Kaz Kylheku

unread,
Aug 17, 2002, 12:04:51 PM8/17/02
to
In article <87it2az...@thalassa.informatimago.com>, Pascal Bourguignon
wrote:

> "Coby Beck" <cb...@mercury.bc.ca> writes:
>
>> "Pedro M. C. Pina" <pp...@netcabo.pt> wrote in message
>> news:1029374394.970955@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.

Coby Beck

unread,
Aug 17, 2002, 11:13:28 PM8/17/02
to

"Pascal Bourguignon" <too.mu...@example.com> wrote in message
news:87it2az...@thalassa.informatimago.com...

> "Coby Beck" <cb...@mercury.bc.ca> writes:
>
> > "Pedro M. C. Pina" <pp...@netcabo.pt> wrote in message
> > news: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.
> >
> > 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...

0 new messages