From: gtasso
Subject: hask key
Date: 
Message-ID: <ce0a0b86-8fd4-464f-8062-d70a345a52e7@w8g2000prd.googlegroups.com>
hello all
I am collecting hash keys via http  request as string.

How do i convert into 'key symbol so that i could gethash my record

I tried this:

(gethash (read-from-string (concatenate 'string "'' my-key)) *my-hash-
table*)

many thanks

George
ps. I am using sbcl sbcl-1.0.11 debian

From: Joshua Taylor
Subject: Re: hask key
Date: 
Message-ID: <aabefe59-c2c7-4234-9767-79dd20003c8d@m44g2000hsc.googlegroups.com>
On Jun 9, 9:31 pm, gtasso <·······@gmail.com> wrote:
> hello all
> I am collecting hash keys via http  request as string.
>
> How do i convert into 'key symbol so that i could gethash my record
>
> I tried this:
>
> (gethash (read-from-string (concatenate 'string "'' my-key)) *my-hash-
> table*)
>
> many thanks
>
> George
> ps. I am using sbcl sbcl-1.0.11 debian

"intern enters a symbol named string into package. If a symbol whose
name is the same as string is already accessible in package, it is
returned. If no such symbol is accessible in package, a new symbol
with the given name is created and entered into package as an internal
symbol, or as an external symbol if the package is the KEYWORD
package; package becomes the home package of the created symbol. "

http://www.lisp.org/HyperSpec/Body/fun_intern.html

You could also use a hash table that compares keys using equal (which
will treat strings as with string=) or equalp (which will treat
strings as with string-equal). You can make such hash tables with

(make-hash-table :test 'equal)

and

(make-hash-table :test 'equalp)

(For more about hash tables, see http://www.lisp.org/HyperSpec/Body/fun_make-hash-table.html
.)
From: Rainer Joswig
Subject: Re: hask key
Date: 
Message-ID: <joswig-9568C6.10210010062008@news-europe.giganews.com>
In article 
<····································@w8g2000prd.googlegroups.com>,
 gtasso <·······@gmail.com> wrote:

> hello all
> I am collecting hash keys via http  request as string.
> 
> How do i convert into 'key symbol so that i could gethash my record

This 'key symbol makes no sense. See below:

> 
> I tried this:
> 
> (gethash (read-from-string (concatenate 'string "'' my-key)) *my-hash-
> table*)
> 
> many thanks
> 
> George
> ps. I am using sbcl sbcl-1.0.11 debian

Why 'key?


'symbol is another form to write (quote symbol)

Why would one use 'foo ?

If a symbol gets evaluated, the value is the value
of the variable foo. If you want under evaluation to
get the symbol, you have to indicate that the symbol
should not be evaluated as a variable. Then one
writes 'foo.

READ-FROM-STRING would return this:

a)


CL-USER 9 > (read-from-string "FOO")
FOO
3

just the symbol!


b)

CL-USER 7 > (concatenate 'string "'" "FOO")
"'FOO"

CL-USER 8 > (read-from-string *)
(QUOTE FOO)
4

A list of two symbols!


This means that when you want to read something and get a
symbol, a) is sufficient. It is this symbol that you
can use later.

If you want to get a symbol from a string you can also
use INTERN. Intern takes a string and returns a symbol.

-- 
http://lispm.dyndns.org/
From: Thomas A. Russ
Subject: Re: hask key
Date: 
Message-ID: <ymimylsq2tz.fsf@blackcat.isi.edu>
gtasso <·······@gmail.com> writes:

> hello all
> I am collecting hash keys via http  request as string.
> 
> How do i convert into 'key symbol so that i could gethash my record
> 
> I tried this:
> 
> (gethash (read-from-string (concatenate 'string "'' my-key)) *my-hash-
> table*)

Well, you could just use the string itself as the hash key.
Depending on whether you wanted the comparison to be case-sensitive or
not, you would have to use either an EQUAL or EQUALP hash table.

   (make-hash-table :test 'equal)

should give you a hash table that you can use to map strings directly to
your records.

But as to your original question, you should just use

   (intern my-key)

 to get a symbol.  But I don't think it is necessary to do that, since
 you would, in effect, be using two hash-table lookups each time.  One
 that is internal to the INTERN process* and then your explicit one.

-- 
Thomas A. Russ,  USC/Information Sciences Institute

* OK, there isn't any requirement that intern use a hash table, but most
  implementations must do something similar.  I guess I could imagine a
  discrimination net being used instead, but I don't think any
  implementations actually do that.

  On the other hand, it is a bit odd that the standard didn't consider
  adding STRING= or STRING-EQUAL as additional tests for hash tables.  I
  guess they were considered too specialized.  I suppose the rise of the
  internet and the scourge of Perl and string processing were not
  foreseeable.