Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!bu.edu!m2c!risky.ecs.umass.edu!dime!kevin From: kevin@dime.cs.umass.edu (kevin gallagher) Newsgroups: comp.lang.lisp Subject: Re: string to symbol conversion Summary: Speak softly and carry a small stick Message-ID: <32421@dime.cs.umass.edu> Date: 21 Jun 91 19:32:10 GMT References: <80761@eerie.acsu.Buffalo.EDU> Reply-To: kevin@dime.cs.umass.edu (Kevin Gallagher) Organization: University of Massachusetts, Amherst Lines: 37 An excellent programming principle is to use the least powerful method for acheiving your objective. This is especially important in lisp because there are always several ways to do something, each with widely different costs. Using a big stick when a small one will do will make your program run slower, probably lead to unexpected bugs, and contribute to the misperception that `lisp is slow.' In the case of converting a string to a symbol use INTERN. INTERN looks for an existing symbol with the specified name and creates one if no such symbol exists. It returns the symbol that was found or created. (If you expect the symbol to already exist you should use FIND-SYMBOL which returns nil no symbol with the specified name is found.) As was pointed out in other messages, intern doesn't do case conversion or anything else. (intern "Foo") => |Foo| (intern "FOO") => FOO The function READ-FROM-STRING is too big a stick. It invokes the reader which is a large program by itself. (On my Explorer (intern string) is 6-7 times faster than (read-from-string string) and it doesn't cons at all.) Perhaps even worse, INTERN will *always* return a string. READ-FROM-STRING can return (and in fact *do*) anything. (intern "(cons 1 2)") => |(cons 1 2)| (read-from-string "(cons 1 2)" => (CONS 1 2) (catch 'exit (read-from-string "#.(throw 'exit 'dumb)")) => DUMB EVAL, READ, and READ-xxx are the functions that are most overused when a smaller stick will do. Also, FORMAT and the other printing functions can often be replaced with less powerful (and less costly) functions. Kevin Gallagher