>Let's say I have an object...
>define class <example-object> (<object>)
> slot id, init-keyword: id:, init-function: unique-id-maker();
> slot number, init-keyword: number:, init-function: number-maker();
>...and I want to make a getter and setter method which uses the unique
>id of the <example-object>.
>I want the result to look like this:
>Is this possible?
Not as you've described it. All the methods on the number generic
function have to have congruent parameter lists (see DRM, pp 93-94).
Your choices would be to:
1. rename the number slot
2. rename the number function which takes the keyword argument
3. put these two functions into different modules
4. change the number function which takes a keyword argument so
that it no longer takes a keyword argument, and can somehow figure
out by the type or value of its arguments whether it is getting
an <example-object> or an object which is the value of a slot
of an <example-object>.
3 would only work if the two versions of 'number' are never both imported
into the same module.
>I ask because I'm trying to write a simulation which
>allows the user to create an indefinate number of objects of various
>kinds, but each object has to be able to react with the others in a
>specific way. I can't use getter and setter methods which use variable
>names (unless I can find a random-variable-name-maker()).
It's hard to respond to this without knowing more about your program.
However, offhand I'd say that you should probably be able to use
different function for accessing a slot directly (by passing the
example-object) and indirectly (by passing the value of a slot of an
example-object). Or, if you want to use the same function for both
types of access, that function doesn't need to be the same as the
the raw slot accessor function; it can just redirect to the raw slot
accessor when appropropriate.
Andrew Shalit Time is a meadow, not a highway.
http://www.shore.net/~alms -Tom Robbins