From: Kim Russell
Subject: hash
Date: 
Message-ID: <1149662460.753149.72240@c74g2000cwc.googlegroups.com>
hi,

is there a way to store properties associated with an entry in an hash
table. I'm storing  a series of entries (records) in the hash and each
one needs to have a count for example and other properties (genre,rate,
etc). I will then need to be able to retrieve those properties. Sorry,
but it's the first time i work with hashing in lisp.

Best Regards,
k

From: Barry Margolin
Subject: Re: hash
Date: 
Message-ID: <barmar-702806.08370307062006@comcast.dca.giganews.com>
In article <·······················@c74g2000cwc.googlegroups.com>,
 "Kim Russell" <······@gmail.com> wrote:

> hi,
> 
> is there a way to store properties associated with an entry in an hash
> table. I'm storing  a series of entries (records) in the hash and each
> one needs to have a count for example and other properties (genre,rate,
> etc). I will then need to be able to retrieve those properties. Sorry,
> but it's the first time i work with hashing in lisp.

Make the values of the hash table entries structures or CLOS instances, 
with the appropriate properties as slots of the structure or instance.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Pascal Bourguignon
Subject: Re: hash
Date: 
Message-ID: <87u06xl9kj.fsf@thalassa.informatimago.com>
"Kim Russell" <······@gmail.com> writes:
> is there a way to store properties associated with an entry in an hash
> table. I'm storing  a series of entries (records) in the hash and each
> one needs to have a count for example and other properties (genre,rate,
> etc). I will then need to be able to retrieve those properties. Sorry,
> but it's the first time i work with hashing in lisp.

(setf (getf (gethash key table nil) property) value)
(getf (gethash key table nil) property)



[60]> (defparameter *t* (make-hash-table))
*T*
[61]> (setf (getf (gethash :pjb *t* nil) :name) "Pascal")
"Pascal"
[62]> (setf (getf (gethash :pjb *t* nil) :age) 42)
42
[63]>  (getf (gethash :pjb *t* nil) :age)
42
[64]>  (getf (gethash :pjb *t* nil) :name)
"Pascal"
[65]> 


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

In a World without Walls and Fences, 
who needs Windows and Gates?
From: Kim Russell
Subject: Re: hash
Date: 
Message-ID: <1149666655.432731.12290@u72g2000cwu.googlegroups.com>
Thanks very much Pascal.
also what about if i want to increase the age or change any property
for a prticular entry. I would like to be able to do it from anywhere
in the program.

Best Regards,
k

Pascal Bourguignon wrote:
> "Kim Russell" <······@gmail.com> writes:
> > is there a way to store properties associated with an entry in an hash
> > table. I'm storing  a series of entries (records) in the hash and each
> > one needs to have a count for example and other properties (genre,rate,
> > etc). I will then need to be able to retrieve those properties. Sorry,
> > but it's the first time i work with hashing in lisp.
>
> (setf (getf (gethash key table nil) property) value)
> (getf (gethash key table nil) property)
>
>
>
> [60]> (defparameter *t* (make-hash-table))
> *T*
> [61]> (setf (getf (gethash :pjb *t* nil) :name) "Pascal")
> "Pascal"
> [62]> (setf (getf (gethash :pjb *t* nil) :age) 42)
> 42
> [63]>  (getf (gethash :pjb *t* nil) :age)
> 42
> [64]>  (getf (gethash :pjb *t* nil) :name)
> "Pascal"
> [65]>
>
>
> --
> __Pascal Bourguignon__                     http://www.informatimago.com/
>
> In a World without Walls and Fences, 
> who needs Windows and Gates?
From: Pascal Bourguignon
Subject: Re: hash
Date: 
Message-ID: <87pshll7hk.fsf@thalassa.informatimago.com>
"Kim Russell" <······@gmail.com> writes:
> Pascal Bourguignon wrote:
>> "Kim Russell" <······@gmail.com> writes:
>> > is there a way to store properties associated with an entry in an hash
>> > table. I'm storing  a series of entries (records) in the hash and each
>> > one needs to have a count for example and other properties (genre,rate,
>> > etc). I will then need to be able to retrieve those properties. Sorry,
>> > but it's the first time i work with hashing in lisp.
>>
>> (setf (getf (gethash key table nil) property) value)
>> (getf (gethash key table nil) property)
>>
>>
>>
>> [60]> (defparameter *t* (make-hash-table))
>> *T*
>> [61]> (setf (getf (gethash :pjb *t* nil) :name) "Pascal")
>> "Pascal"
>> [62]> (setf (getf (gethash :pjb *t* nil) :age) 42)
>> 42
>> [63]>  (getf (gethash :pjb *t* nil) :age)
>> 42
>> [64]>  (getf (gethash :pjb *t* nil) :name)
>> "Pascal"
>> [65]>
>>
> Thanks very much Pascal.
> also what about if i want to increase the age or change any property
> for a prticular entry. I would like to be able to do it from anywhere
> in the program.

Why don't you just send in the requirements? ;-)
Have a look at: http://www.cliki.net/Education
                http://www.cliki.net/Online%20Tutorial
And of course:
    http://www.lispworks.com/documentation/HyperSpec/Front/Contents.htm

Changing or adding a property is the same thing:

   (setf (getf (gethash :pjb *t* nil) :name) "Philip")

You could increment the age property with:

    (incf (getf (gethash :pjb *t* 0) :age 0))

(if there's no :PJB in the hash-table, or if it has no :AGE property,
then we start from 0 and increment it).


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

ADVISORY: There is an extremely small but nonzero chance that,
through a process known as "tunneling," this product may
spontaneously disappear from its present location and reappear at
any random place in the universe, including your neighbor's
domicile. The manufacturer will not be responsible for any damages
or inconveniences that may result.