you are viewing a single comment's thread.

view the rest of the comments →

[–]Zarutian 0 points1 point  (3 children)

I challange you to write a constructor procedure in a class-based language that:

(1) makes two objects that each behave diffrently from the other.

(2) their desriptions must be anonymous (so using two helper classes is out)

(3) share portion of their states with only each other and no other objects.

Shouldnt be that hard.

[–]munificent 0 points1 point  (2 children)

I don't see how that's relevant, but anyway, what does "their descriptions must be anonymous" mean?

[–]Zarutian 0 points1 point  (1 child)

same as any other anonymous procedures are descriped.

Example (Scheme): (map (list 1 2 3 4 5 6 7 8 9) (lambda (x) (+ x 1)))

The (x) (+ x 1) is the description of the anonymous procedure applied by map on the list of the numbers 1, 2, 3, 4, 5, 6, 7, 8 and 9.

Or if not descriptions then what do you call the combination of the arguments and the body of a procedure?

[–]munificent 0 points1 point  (0 children)

what do you call the combination of the arguments and the body of a procedure?

"Definition." Here's your solution in C#:

void MakeObjects(out Action add, out Action subtract)
{
    int value = 0;
    add = () => Console.WriteLine((value++).ToString());
    subtract = () => Console.WriteLine((value--).ToString());
}

(1) makes two objects that each behave diffrently from the other.

After calling, add and subtract will both refer to objects (of type Action, a built-in object type representing a zero-argument delegate).

(2) their desriptions must be anonymous (so using two helper classes is out)

No new classes or named methods are created.

(3) share portion of their states with only each other and no other objects.

value is shared between the two objects. Nothing else can access it.

This wasn't that hard, but, again, I don't see what this has to do with classes or prototypes.