Re: JESS: Lisp is maddening
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.
Re: JESS: Lisp is maddening
Hello Donald. You were very close. Since you were erroneously treating the ?hash-set variable in the last statement in your (progn) as a function, to get the result you want, remove the parentheses surround it, as in the following very slightly modified form of you (defglobal): (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)) Getting the string value of the global java.util.HashSet variable shows that this has worked: (string ?*usps-state-codes*) [VT, RI, HI, VI, MH, ME, VA, MI, DE, ID, IA, MD, MA, AS, UT, IL, IN, MN, AZ, MP, MO, MT, MS, NH, PW, NJ, PR, NM, AK, AL, TX, NC, ND, NE, GA, NV, TN, CA, OK, OH, WY, FM, FL, SD, SC, CT, WV, DC, WI, KY, KS, OR, LA, GU, WA, CO, PA] Regards, Win Carus On 09/18/2010 09: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. begin:vcard fn:Win Carus n:Carus;Win org:Information Extraction Systems, Inc. (tm) adr:;;20 East Quinobequin Road;Waban;MA;02468;USA email;internet:win.ca...@infoextract.com title:President tel;work:(617) 244-5068 tel;fax:(617) 244-5068 note;quoted-printable:=E2=80=9CInformation Extraction Systems=E2=80=9D, =E2=80=9CInfoExtract=E2= =80=9D, and =E2=80=9CIEBuilder=E2=80=9D are trademarks or registered trad= emarks owned by Information Extraction Systems, Inc. x-mozilla-html:FALSE url:http://www.InfoExtract.com version:2.1 end:vcard
Re: JESS: Lisp is maddening
On 18 September 2010 15:38, Ernest Friedman-Hill ejfr...@sandia.gov 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 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.