On 16 August 2010 05:37, Donald Winston satchwins...@yahoo.com wrote:
I guess you got to use toArray and as-list all the time for any kind of
array.
Not quite. And the remaining todo's can be nicely abstracted into a couple
of deffunctions for doing the puts and gets:
(deffunction putIntoMap (?map ?key $?val)
(if (= 1 (length$ $?val))
then (call ?map put ?key (nth$ 1 $?val))
else (call ?map put ?key $?val)))
(deffunction getFromMap (?map ?key)
(bind ?val (call ?map get ?key))
(bind ?strep (call String valueOf ?val))
(if (and (eq ?strep null) (= ?val nil))
then (return nil)
else (bind ?clname ((call ?val getClass) getName))
(if (= [ (call ?clname substring 0 1))
then (return (as-list ?val))
else (return ?val
(bind ?myMap (new java.util.HashMap))
(bind ?string string-of-char)
(bind ?strings (list un deux trois))
(bind ?number 42)
(bind ?numbers (list 1001 64 3.14159))
(putIntoMap ?myMap string ?string)
(putIntoMap ?myMap strings ?strings)
(putIntoMap ?myMap nephews Huey Dewey Louie)
(putIntoMap ?myMap number ?number)
(putIntoMap ?myMap numbers ?numbers)
(putIntoMap ?myMap primes 2 3 5 7 11 13)
(foreach ?key (?myMap keySet)
;(list string strings nephews number numbers primes foo)
(bind ?val (getFromMap ?myMap ?key))
(if (listp ?val)
then (printout t ?key (list): ?val crlf)
else (printout t ?key (scalar): ?val crlf)))
This is the output:
numbers (list): (1001 64 3.14159)
string (scalar): string-of-char
number (scalar): 42
strings (list): (un deux trois)
primes (list): (2 3 5 7 11 13)
nephews (list): (Huey Dewey Louie)
(IMHO, Java Arrays aren't first choice in an application such as the one
you've described. YMMV.)
-W