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 ;-). Their names are used everywhere: * stand-alone pattern output * super-pattern output (subpatterns are replaced by their name, else output explodes) eg operand: symbol|number * inside nodes they generate (eg allow discrimination between choices) * error output ("expected operand at position...") * result output for testing > Regarding your generic question, I'd like DMD to have more static > introspection, for for now ... Dynamic introspection would do the job for me, I guess. In python, would be like (untested): def namePatterns (scope = var()): for (name,obj) in scope: if isinstance(obj, Pattern): obj.name = name Don't know how static would help better. Any idea how else to write somethink analog to format()? denis -- -- -- -- -- -- -- vit esse estrany ☣ spir.wikidot.com