> 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.
-- __Pascal_Bourguignon__ http://www.informatimago.com/ ---------------------------------------------------------------------- The name is Baud,...... James Baud.
>>>>> 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?
> 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))))
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.
* 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.
> >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.
* 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.
* 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.
<e...@naggum.no> wrote in message <news: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.
> * 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))))
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.
* 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).
* 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.
> <e...@naggum.no> wrote in message <news:3238436747006793@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.
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.
* 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.
* 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.
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.
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.
Erik Naggum <e...@naggum.no> wrote in message <news: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´.
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.