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" ...))))
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 y...@address.com'
in the BODY of a message to majord...@sandia.gov, NOT to the list
(use your own address!) List problems? Notify owner-jess-us...@sandia.gov.
--------------------------------------------------------------------