Programming Question 
Author Message
 Programming Question

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();
end class;

...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:

Quote:
>number(id: 4123)

42

Is this possible?  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()).

Thanks,
Neil



Thu, 17 Jun 1999 03:00:00 GMT  
 Programming Question


Quote:
>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();
>end class;

>...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:

>>number(id: 4123)
>42

>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.

Quote:
>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



Thu, 17 Jun 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. tkinspect/tk program question - how to name a program

2. 31-bit Programming Question

3. J program question.

4. CDROM Programming Question

5. J programming question

6. Language newbie programming question

7. J programming question

8. a VisualAge visual programming question

9. One more big program question with classes

10. Help: VW2.5.2 programming question...

11. E-Mail Program Question

12. CW - general programming question - ideas??

 

 
Powered by phpBB® Forum Software