spir <denis.s...@gmail.com> wrote:

On Mon, 15 Nov 2010 12:44:24 -0500
bearophile <bearophileh...@lycos.com> wrote:

spir:

> 1. name objects automatically
> I need some objects to know their name (as field on themselves). the only solution I can else imagine is for the user write:
>    x = ...;
>    x.name = "x";

What if you have two or more references to the same object?

I'm not sure what you mean. The said objects are patterns (instances of a Pattern class hierachy). And indeed, they are multiply referenced (that's precisely the point of writing a grammar ;-).

The two (or more) references could not be referred to by the same name.
Sure, they would point to the same object, but how could the object know
whether its functions were called from x or from y? While you may use the
same name everywhere for the same object, the x in function foo is a
different one from that in function bar, not to mention across modules.

If I may come with a solution, it would be something like this:

mixin template New!( T, string name ) {
        mixin( "auto " ~ name ~ " = new T(\"" ~ name ~ "\")");
}

--
Simen

Reply via email to