Just as in perl, There is More Than One Way To Do It (R). One way
might be to use the (bag) function:
(defglobal ?*numbers* = (bag create NUMBERS))
(bag set ?*numbers* aString 1)
(bag set ?*numbers* anotherString 2)
(bag set ?*numbers* yetAnotherString 3)
; ...
(bag get ?*numbers* anotherString) ; returns 2
If the indexes are always contiguous, you could of course use a
multifield and use member$ to find the strings, but it wouldn't be as
efficient; (bag) uses a hashed lookup which would be faster than a
linear search, for 60 items, certianly.
I think Duane Morin wrote:
>
> I've got about 60 facts of the form (integer string). I would like to write
> a function that says getIndex(string x), given the string, returns the int.
>
> How best to implement this? A big multifield? I'm not sure if I can do it
> as facts -- can I write a function (since it needs to be called on demand,
> not as a rule) that accesses facts?
>
> Duane
>
>
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9214 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list. List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------