From: M. K.
Subject: Converting a string to a symbol
Date: 
Message-ID: <3EF7E722.C1992478@ozemail.com.au>
Hi,

Is there a way to covert a string ("abcd") into a symbol ('ABCD) ???

Thanks, M.K.

From: Kent M Pitman
Subject: Re: Converting a string to a symbol
Date: 
Message-ID: <sfwisqw55ks.fsf@shell01.TheWorld.com>
"M. K." <····@ozemail.com.au> writes:

> Is there a way to covert a string ("abcd") into a symbol ('ABCD) ???

'ABCD isn't a symbol.

ABCD is a symbol whose name is "ABCD".

'ABCD is a list.

'ABCD ==is== (QUOTE ABCD)

'ABCD evaluates to ABCD.

"abcd" is a string, which evaluates to itself.

'"abcd" is the list (QUOTE "abcd") which evaluates to "abcd".

(string-upcase "abcd") =>  "ABCD"

(intern (string-upcase "abcd")) => ABCD

Adam Warner mentioned READ-FROM-STRING, but note that this is not just
moving strings to symbols, but is exercising the full lisp parser. e.g.,

(intern (string-upcase "'abcd")) => \'ABCD

(read-from-string "'abcd") => (QUOTE ABCD)

The reason that string-upcase is not needed for READ-FROM-STRING
is that READ (which is the underlying operation in READ-FROM-STRING)
naturally upcases unescaped characters.  That is,

'abc => ABC

'\abc => \aBC

'\a\b\c => |abc|

'\A\B\C => ABC

'|a|bc => \aBC

'|abc| => |abc|

'|ABC| => ABC

'|'ABC| => \'ABC
From: M. K.
Subject: Re: Converting a string to a symbol
Date: 
Message-ID: <3EF9104C.3B84D516@ozemail.com.au>
Thanks Kent.

(intern (string-upcase "abcd")) sound like the safe choice.

By the way, I noticed the following on my default installation of "clisp":

(intern "abcd") => |abcd|

I have not seen the fence symbols in any of my novice tutorials and would
love to know what they mean in lisp.

Best regards, M.K.

-----


Kent M Pitman wrote:

> "M. K." <····@ozemail.com.au> writes:
>
> > Is there a way to covert a string ("abcd") into a symbol ('ABCD) ???
>
> 'ABCD isn't a symbol.
>
> ABCD is a symbol whose name is "ABCD".
>
> 'ABCD is a list.
>
> 'ABCD ==is== (QUOTE ABCD)
>
> 'ABCD evaluates to ABCD.
>
> "abcd" is a string, which evaluates to itself.
>
> '"abcd" is the list (QUOTE "abcd") which evaluates to "abcd".
>
> (string-upcase "abcd") =>  "ABCD"
>
> (intern (string-upcase "abcd")) => ABCD
>
> Adam Warner mentioned READ-FROM-STRING, but note that this is not just
> moving strings to symbols, but is exercising the full lisp parser. e.g.,
>
> (intern (string-upcase "'abcd")) => \'ABCD
>
> (read-from-string "'abcd") => (QUOTE ABCD)
>
> The reason that string-upcase is not needed for READ-FROM-STRING
> is that READ (which is the underlying operation in READ-FROM-STRING)
> naturally upcases unescaped characters.  That is,
>
> 'abc => ABC
>
> '\abc => \aBC
>
> '\a\b\c => |abc|
>
> '\A\B\C => ABC
>
> '|a|bc => \aBC
>
> '|abc| => |abc|
>
> '|ABC| => ABC
>
> '|'ABC| => \'ABC
From: Kent M Pitman
Subject: Re: Converting a string to a symbol
Date: 
Message-ID: <sfwllvq3j6c.fsf@shell01.TheWorld.com>
"M. K." <····@ozemail.com.au> writes:

> Thanks Kent.
> 
> (intern (string-upcase "abcd")) sound like the safe choice.
> 
> By the way, I noticed the following on my default installation of "clisp":
> 
> (intern "abcd") => |abcd|
> 
> I have not seen the fence symbols in any of my novice tutorials and would
> love to know what they mean in lisp.

They mean the same as putting slash before each of the intervening chars,
that is, to treat the intervening chars as alphabetic.

 \a\b\c\d == |abcd|
 \1234    == |1234|

Unlike in previous dialects of Lisp, |...|'s in CL are not token breaks.
So |ab|cd|ef| == \a\bCD\e\f
From: Christopher Browne
Subject: Re: Converting a string to a symbol
Date: 
Message-ID: <bd9i36$qepip$2@ID-125932.news.dfncis.de>
After a long battle with technology,"M. K." <····@ozemail.com.au>, an earthling, wrote:
> Is there a way to covert a string ("abcd") into a symbol ('ABCD) ???

Yes.  See the HyperSpec.
-- 
wm(X,Y):-write(X),write(·@'),write(Y). wm('cbbrowne','ntlug.org').
http://www.ntlug.org/~cbbrowne/lisp.html
"Bother," said Pooh, as he deleted his root directory.
From: Kenny Tilton
Subject: Re: Converting a string to a symbol
Date: 
Message-ID: <3EF85FB2.5090804@nyc.rr.com>
Christopher Browne wrote:
> After a long battle with technology,"M. K." <····@ozemail.com.au>, an earthling, wrote:
> 
>>Is there a way to covert a string ("abcd") into a symbol ('ABCD) ???
> 
> 
> Yes.  See the HyperSpec.

Thx, this NG was starting to get a nasty reputation for being friendly 
and supportive. Not even providing a URL was a nice touch. Sorry for 
spoiling the fun:

  http://www-2.cs.cmu.edu/Groups/AI/html/hyperspec/HyperSpec/FrontMatter/

Bad advice, btw. I sealed off my knowledge of INTERN and went looking, 
attacking from the directions of both STRING and SYMBOL, came up empty. 
The symbol section links to "interned", but that does not mention "intern".

And what if the poor soul stumbles onto make-symbol?!

Apropos of course hasn't a prayer of finding INTERN.


-- 

  kenny tilton
  clinisys, inc
  http://www.tilton-technology.com/
  ---------------------------------------------------------------
"Everything is a cell." -- Alan Kay
From: M. K.
Subject: Re: Converting a string to a symbol
Date: 
Message-ID: <3EF90793.93DE02BD@ozemail.com.au>
I saw the Hyperspec and realized that it is great if you know the "name" of the built in
function and want to know "what it does".

The problem is that a novice knows "what it would like a function to do" but does not know
the "name".

This is when the novice turns to experienced humans for help.

M.K.
------

Christopher Browne wrote:

> After a long battle with technology,"M. K." <····@ozemail.com.au>, an earthling, wrote:
> > Is there a way to covert a string ("abcd") into a symbol ('ABCD) ???
>
> Yes.  See the HyperSpec.
> --
> wm(X,Y):-write(X),write(·@'),write(Y). wm('cbbrowne','ntlug.org').
> http://www.ntlug.org/~cbbrowne/lisp.html
> "Bother," said Pooh, as he deleted his root directory.
From: Kenny Tilton
Subject: Re: Converting a string to a symbol
Date: 
Message-ID: <3EF9C19B.4030605@nyc.rr.com>
M. K. wrote:
> I saw the Hyperspec and realized that it is great if you know the "name" of the built in
> function and want to know "what it does".
> 
> The problem is that a novice knows "what it would like a function to do" but does not know
> the "name".

apropos this last, you may already know this, but if you can at least 
guess at a portion of the name, the "apropos" function will show you a 
list of matching candidates. some IDEs offer dialogues as a convenient 
wrapper to apropos-- ACL's is excellent.

of course, apropos would not help here if you reasonably tried "string" 
and "symbol" (except you would find MAKE-SYMBOL, not what you wanted).

INTERN must be an old name. at some point (it seems to me) an ethic of 
giving functions "nice long names" was adopted by lispniks, but stuff 
from before then can still have surprising names.

btw, Google offers no support for my recollection that this was my first 
question on c.l.l. back in the mid nineties.


-- 

  kenny tilton
  clinisys, inc
  http://www.tilton-technology.com/
  ---------------------------------------------------------------
"Everything is a cell." -- Alan Kay
From: Bruce Hoult
Subject: Re: Converting a string to a symbol
Date: 
Message-ID: <bruce-CD87FF.10082926062003@copper.ipg.tsnz.net>
In article <················@nyc.rr.com>,
 Kenny Tilton <·······@nyc.rr.com> wrote:

> INTERN must be an old name. at some point (it seems to me) an ethic of 
> giving functions "nice long names" was adopted by lispniks, but stuff 
> from before then can still have surprising names.

This btw is one of the many things that got consolidated in the Dylan 
design.

Dylan has the as(type, value) generic function, with built in methods for

- as(<symbol>, myString)
- as(<string>, mySymbol)
- as(<integer>, myCharacter)
- as(<character>, myInteger)

The user can add others themselves.

-- Bruce
From: Bruce Hoult
Subject: Re: Converting a string to a symbol
Date: 
Message-ID: <bruce-0AC3DC.18224524062003@copper.ipg.tsnz.net>
In article <·················@ozemail.com.au>,
 "M. K." <····@ozemail.com.au> wrote:

> Hi,
> 
> Is there a way to covert a string ("abcd") into a symbol ('ABCD) ???

(intern "ABCD")


Note that (intern "abcd") returns a different object to (intern "ABCD"), 
but 'abcd and 'ABCD are the same object.

-- Bruce
From: Adam Warner
Subject: Re: Converting a string to a symbol
Date: 
Message-ID: <pan.2003.06.24.06.41.24.481385@consulting.net.nz>
Hi Bruce Hoult,

>> Is there a way to covert a string ("abcd") into a symbol ('ABCD) ???
> 
> (intern "ABCD")
> 
> Note that (intern "abcd") returns a different object to (intern "ABCD"),
> but 'abcd and 'ABCD are the same object.

(pedant "'abcd and 'ABCD are only the same object when the readtable case
is :downcase or :upcase. They are different objects when readtable case is
:preserve or :invert.")

Regards,
Adam
From: Bruce Hoult
Subject: Re: Converting a string to a symbol
Date: 
Message-ID: <bruce-257B55.18501124062003@copper.ipg.tsnz.net>
In article <······························@consulting.net.nz>,
 Adam Warner <······@consulting.net.nz> wrote:

> Hi Bruce Hoult,
> 
> >> Is there a way to covert a string ("abcd") into a symbol ('ABCD) ???
> > 
> > (intern "ABCD")
> > 
> > Note that (intern "abcd") returns a different object to (intern "ABCD"),
> > but 'abcd and 'ABCD are the same object.
> 
> (pedant "'abcd and 'ABCD are only the same object when the readtable case
> is :downcase or :upcase. They are different objects when readtable case is
> :preserve or :invert.")

True.  That is however the default setting on the implementations I've 
tried, and I'd suspect it may be required to be for compatability's sake.

-- Bruce
From: Kent M Pitman
Subject: Re: Converting a string to a symbol
Date: 
Message-ID: <sfwel1k55fp.fsf@shell01.TheWorld.com>
Bruce Hoult <·····@hoult.org> writes:

> > (pedant "'abcd and 'ABCD are only the same object when the readtable case
> > is :downcase or :upcase. They are different objects when readtable case is
> > :preserve or :invert.")
> 
> True.  That is however the default setting on the implementations I've 
> tried, and I'd suspect it may be required to be for compatability's sake.

Indeed.  And novice users asking the kind of question that was being asked
presumably have not altered this from the default.  It's better not to
raise this issue because it's going to further complicate matters.

There is a notion called the "felicity principle" that is used in
teaching that says you should perturb as few dimensions in a
multidimensional space as possible when teaching, allowing the user to
get used to each knob separately.  It doesn't mean you can't
eventually get to all of the things.  But getting standard Lisp syntax
down is hard enough without showing the ways in which it is able to be
flexible when you start actively setting option variables, readtable
case options, etc.
From: Adam Warner
Subject: Re: Converting a string to a symbol
Date: 
Message-ID: <pan.2003.06.24.07.31.30.625223@consulting.net.nz>
Hi Bruce Hoult,

>> >> Is there a way to covert a string ("abcd") into a symbol ('ABCD) ???
>> > 
>> > (intern "ABCD")
>> > 
>> > Note that (intern "abcd") returns a different object to (intern
>> > "ABCD"), but 'abcd and 'ABCD are the same object.
>> 
>> (pedant "'abcd and 'ABCD are only the same object when the readtable
>> case is :downcase or :upcase. They are different objects when readtable
>> case is :preserve or :invert.")
> 
> True.  That is however the default setting on the implementations I've
> tried, and I'd suspect it may be required to be for compatability's
> sake.

Thankfully you suspect wrong in regard to a readtable case of :invert. It
is 100% compatible with a readtable case of :upcase so long as source code
symbols are written in lower case (and also compatible in most cases where
symbol case is judiciously preserved, i.e. if one writes the symbol AdAm
in one place it should be written as AdAm in every place within the code).

On the other hand, Franz is aggressively non-ANSI compatible with their
"modern images". They achieve this by interning the built in symbols in
lower case and then using a readtable case of :preserve.

Regards,
Adam
From: M. K.
Subject: Re: Converting a string to a symbol
Date: 
Message-ID: <3EF90A24.62AE45BA@ozemail.com.au>
Thanks Bruce. Intern works well if I convert my string to caps first.

Best Regards, M.K.

--------------------


Bruce Hoult wrote:

> In article <·················@ozemail.com.au>,
>  "M. K." <····@ozemail.com.au> wrote:
>
> > Hi,
> >
> > Is there a way to covert a string ("abcd") into a symbol ('ABCD) ???
>
> (intern "ABCD")
>
> Note that (intern "abcd") returns a different object to (intern "ABCD"),
> but 'abcd and 'ABCD are the same object.
>
> -- Bruce
From: Adam Warner
Subject: Re: Converting a string to a symbol
Date: 
Message-ID: <pan.2003.06.24.06.34.50.418066@consulting.net.nz>
Hi M. K.,

> Is there a way to covert a string ("abcd") into a symbol ('ABCD) ???

(intern "abcd") => ABCD
(read-from-string "abcd") => abcd
(eq (intern "abcd") (read-from-string "abcd")) => nil
(eq (intern "ABCD") (read-from-string "abcd")) => t

Results depend upon readtable case. I use the ANSI defined invert mode:
http://www.lispworks.com/reference/HyperSpec/Body/23_ab.htm

This invert mode allows one to preserve case information while still being
able to refer to all built in symbols using lower case.

Regards,
Adam
From: Kumade Khawi
Subject: Re: Converting a string to a symbol
Date: 
Message-ID: <9cfb0cea.0306242119.2fd3928a@posting.google.com>
"M. K." <····@ozemail.com.au> wrote in message news:<·················@ozemail.com.au>...
> Hi,
> 
> Is there a way to covert a string ("abcd") into a symbol ('ABCD) ???
> 
> Thanks, M.K.

I see you have gotten an answer now, but next time you have a quick technical
question, try the FreeNode network on IRC and join #lisp chanel. You will get
an answer within minutes (if not seconds).

Here are the servers: http://freenode.net/irc_servers.shtml
From: Christophe Rhodes
Subject: Re: Converting a string to a symbol
Date: 
Message-ID: <sqbrwmo9yy.fsf@lambda.jcn.srcf.net>
······@pobox.com (Kumade Khawi) writes:

> "M. K." <····@ozemail.com.au> wrote in message news:<·················@ozemail.com.au>...
>> Hi,
>> 
>> Is there a way to covert a string ("abcd") into a symbol ('ABCD) ???
>
> I see you have gotten an answer now, but next time you have a quick technical
> question, try the FreeNode network on IRC and join #lisp chanel. You will get
> an answer within minutes (if not seconds).

Note though that the participants generally reserve the ancient Usenet
right to say both "yay" and "nay" and "go not unto IRC for advice, for
they shall say both 'yay' and 'nay' and 'go not unto ...' ..." :-)

Christophe
-- 
http://www-jcsu.jesus.cam.ac.uk/~csr21/       +44 1223 510 299/+44 7729 383 757
(set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b)))
(defvar b "~&Just another Lisp hacker~%")    (pprint #36rJesusCollegeCambridge)