swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Compare function followup


From: Paul Johnson
Subject: Compare function followup
Date: Fri, 17 Sep 1999 11:39:54 -0500

I've gotten some good Map feedback and I think I've got most of that
straightened out.  There is one niggling thing, which I think I read in
the Swarmdocs, but can't find it again.

If a program uses a Map without specifying the comparison function, then
does swarm assume the comparison is the internal function compareID?  In
the grid3.m, this seems to be what happens.  ALthough it is described as
a comparison of strings, I believe it is putting C strings into String
objects, and then the keys are treated as equal only when the "id's" of
the objects are the same.  This amounts to checking if the memory
address of 2 objects is the same.  Otherwise,it would be necessary to 
declare a compare function.

There is a built in function compareCStrings, which I believe can be
used if the strings used as keys are cast as (id), but from what I can
tell it does not work if the strings are wrapped inside String objects. 
The example grid3.m uses String wrappers.  

At one level it is nice to know that objects can be inserted in any
number of ways, but what I strive for is the simple bottom-line of what
is "best" and what ought to be taught.

The lesson I've taken away from this is that the casting of ints or
strings to create keys or objects probably is a bad practice because it
is not portable.  Hence, when they need keys that are not objects
themselves, people ought to use wrapper objects around strings or
integers and then, if necessary, comparison functions can be written to
compare the values wrapped in the objects.

Marcus's example of a Map using integer wrapper keys is now available
here:

http://lark.cc.ukans.edu/~pauljohn/SwarmFaq/WorkingExampleCode/MapIntegerIndex.txt


-- 
Paul E. Johnson                       email: address@hidden
Dept. of Political Science            http://lark.cc.ukans.edu/~pauljohn
University of Kansas                  Office: (785) 864-9086
Lawrence, Kansas 66045                FAX: (785) 864-5700

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]