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

How to add characters to an atom?

7 views
Skip to first unread message

Cad Bilbao

unread,
Nov 23, 2001, 7:58:31 AM11/23/01
to
Hi again?

If I try:
(setf my-List(cons my-char my-List))

,I add an 'char-atom' (my-char) to my-List, but I would like to add a
char to an atom/word within myList.

I mean, I want to add 'n' to 'Joh' --> John
And afterwards,
(setf my-List(cons 'John my-List))

Any sugestion? Thank you very much

Erik Haugan

unread,
Nov 23, 2001, 8:48:11 AM11/23/01
to
* c...@bilbao.com (Cad Bilbao)
> (setf my-List(cons my-char my-List))

You should _really_ work on your style as several others have pointed out.
A real lisper would write your expression as (observe the spacing and case):

(setf my-list (cons my-char my-list))

Furthermore he would use push:

(push my-char my-list)

> ,I add an 'char-atom' (my-char) to my-List, but I would like to add a
> char to an atom/word within myList.
>
> I mean, I want to add 'n' to 'Joh' --> John
> And afterwards,
> (setf my-List(cons 'John my-List))

This makes no sense whatsoever, I think you must be seriously confused about
something. Can you please tell us what you think you're trying to do? In
plain English?

Erik

Dr. Edmund Weitz

unread,
Nov 23, 2001, 9:02:50 AM11/23/01
to
c...@bilbao.com (Cad Bilbao) writes:

If you want to manipulate _strings_ you should take a look at the CLHS
entries for CONCATENATE and (SETF (SUBSEQ ...) ...) for example -
remember that strings are one-dimensional arrays (i.e. vectors) and
thus sequences. You can use all functions that manipulate vectors or
sequences to manipulate your strings.

Try something like the following in your listener:

(concatenate 'string "Joh" "n")
(concatenate 'string "Joh" (coerce '(#\n) 'string))
(let ((s "Gamma"))
(setf (subseq s 0 4) "Kapp")
(print s)
(setf (aref s 0) #\Z)
s)

If you want to manipulate _symbols_ on a per-character basis you'll
have to convert them to strings and then back to symbols. See INTERN
and SYMBOL-NAME in the CLHS.

Also, try (PUSH 'JOHN MY-LIST) instead of (SETF MY-LIST (CONS 'JOHN
MY-LIST)). Your CL implementation might macroexpand the first form to
something that's similar to the second form, but obviously the
intention of the first form is easier grasp for the human reader.

HTH,
Edi.

Erik Naggum

unread,
Nov 23, 2001, 12:49:14 PM11/23/01
to
* Cad Bilbao

| If I try: (setf my-List(cons my-char my-List)) ,I add an 'char-atom'
| (my-char) to my-List, but I would like to add a char to an atom/word
| within myList.

What kind of Common Lisp tutorials are you using or have you used?

///
--
Norway is now run by a priest from the fundamentalist Christian People's
Party, the fifth largest party representing one eighth of the electorate.
--
Carrying a Swiss Army pocket knife in Oslo, Norway, is a criminal offense.

0 new messages