Re: JESS: Lisp is maddening

"Wolfgang Laun" <[email protected]>
Newsgroups gmane.comp.java.jess
Message-ID <26503_1284834423_o8IIQC1w028000_AANLkTi=j2X_zo-pjN8yUMsLD9F4x68orBUbiVyFatr-E@mail.gmail.com>
On 18 September 2010 15:38, Ernest Friedman-Hill <[email protected]> wrote:

> That's extremely close; the only problem is on the last line of the
> defglobal: (?hash-set) is an attempt to call the function whose name is in
> ?hash-set. That's not a function name, it's a map, so it doesn't work (the
> error is "method name expected, as Jess tries to call a method on that
> object). You want the progn to return "?hash-set", not "(?hash-set)" -- just
> drop those parentheses and you're good to go.
>
> Another way to do this that would involve less typing: Jess lists turn into
> arrays when passed to Java functions. So you could do this:
>
> (import java.util.*)
> (defglobal ?*usps-state-code* =
>    (new HashSet (call Arrays asList (list "AL" "AK" "AS" ...))))


Better golfing: You can omit the quotes ;-)

Actually, the difference between a Java HashSet and a Jess list isn't hefty,
I've clocked this, and the list is slower by 15% only. This test was based
on testing all list/set elements with equal frequency.

Since this won't be true in reality, I have used a list ordered by
decreasing population, and used a set of test cases where lookups were
proportional to the distribution of the population. Then, there is no
difference between a Jess list and HashSet.

I compared these lookup functions:
   (deffunction testList (?sc) (member$ ?sc ?*sclist*))
   (deffunction testSet (?sc) (?*scset* contains ?sc))

@Donald: Why is New York (NY) omitted from the list?

-W

>
>
>
>
> On Sep 18, 2010, at 9:24 AM, Donald Winston wrote:
>
>  Why doesn't this work?
>>
>> (defglobal ?*usps-state-codes* = (progn
>>    (bind ?hash-set (new java.util.HashSet 59))
>>    (call ?hash-set add "AL") (call ?hash-set add "AK") (call ?hash-set add
>> "AS") (call ?hash-set add "AZ")
>>    (call ?hash-set add "CA") (call ?hash-set add "CO") (call ?hash-set add
>> "CT") (call ?hash-set add "DE")
>>    (call ?hash-set add "DC") (call ?hash-set add "FM") (call ?hash-set add
>> "FL") (call ?hash-set add "GA")
>>    (call ?hash-set add "GU") (call ?hash-set add "HI") (call ?hash-set add
>> "ID") (call ?hash-set add "IL")
>>    (call ?hash-set add "IN") (call ?hash-set add "IA") (call ?hash-set add
>> "KS") (call ?hash-set add "KY")
>>    (call ?hash-set add "LA") (call ?hash-set add "ME") (call ?hash-set add
>> "MH") (call ?hash-set add "MD")
>>    (call ?hash-set add "MA") (call ?hash-set add "MI") (call ?hash-set add
>> "MN") (call ?hash-set add "MS")
>>    (call ?hash-set add "MO") (call ?hash-set add "MT") (call ?hash-set add
>> "NE") (call ?hash-set add "NV")
>>    (call ?hash-set add "NH") (call ?hash-set add "NJ") (call ?hash-set add
>> "NM") (call ?hash-set add "NC")
>>    (call ?hash-set add "ND") (call ?hash-set add "MP") (call ?hash-set add
>> "OH") (call ?hash-set add "OK")
>>    (call ?hash-set add "OR") (call ?hash-set add "PW") (call ?hash-set add
>> "PA") (call ?hash-set add "PR")
>>    (call ?hash-set add "RI") (call ?hash-set add "SC") (call ?hash-set add
>> "SD") (call ?hash-set add "TN")
>>    (call ?hash-set add "TX") (call ?hash-set add "UT") (call ?hash-set add
>> "VT") (call ?hash-set add "VI")
>>    (call ?hash-set add "VA") (call ?hash-set add "WA") (call ?hash-set add
>> "WV") (call ?hash-set add "WI")
>>    (call ?hash-set add "WY")
>>    (?hash-set)))
>>
>> (printout t (call ?*usps-state-codes* contains "VA") crlf)
>>
>> I need to have a global variable that will contain state code values after
>> a (reset). list "AL" "AK" ... works but a HashSet would be more efficient. A
>> jess list is not a collection so I can't use the HashSet(Collection)
>> constructor.
>>
>>
> ---------------------------------------------------------
> Ernest Friedman-Hill
> Informatics & Decision Sciences, Sandia National Laboratories
> PO Box 969, MS 9012, Livermore, CA 94550
> http://www.jessrules.com
>
>
>
>
>
>
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users [email protected]'
> in the BODY of a message to [email protected], NOT to the list
> (use your own address!) List problems? Notify [email protected].
> --------------------------------------------------------------------
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.