Re: explore current scope, or other hack

2010-11-16 Thread spir
On Mon, 15 Nov 2010 21:35:19 +0100
Simen kjaeraas simen.kja...@gmail.com wrote:

 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.

Oh, yes! I see the point, now, thank you. But in the present case (and a few 
others where I had to name objects), only the birth name is relevant. Here is 
an example from written using the library I'm writing, I'm sure it's 
self-explaining. I overloaded opCall in the top Pattern class so that it names 
the object:

== test code 
auto digits = new String(new Klass(0-9));
digits.name = digits;
auto DOT = new Literal(.);
DOT.name = DOT;
auto integer = new Compose(digits,DOT,digits);
integer.name = integer;
// output
writeln(digits.view());
writeln(integer.view());
writeln-);
integer.test(123.45);
writeln-);
integer.test(123.);
=== output ==
digits=[0-9]+
integer=(digits DOT digits)

-
pattern   : integer=(digits DOT digits)
text  : 123.45
outcome   : (123 . 45)
-

Test Error: see outcome below.
-
pattern   : integer=(digits DOT digits)
text  : 123.
outcome   : *failure*
-
*
End Of Text Error: end of text reached while matching
   pattern digits=[0-9]+ at index 4
*


 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 ~ \));
 }

Thank you again, I'll explore this path.


Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com



Re: effect of a label on following block

2010-11-16 Thread Nick Voronin
On Mon, 15 Nov 2010 19:34:46 +0300, Ellery Newcomer  
ellery-newco...@utulsa.edu wrote:


My gut feeling is that the if statement's behavior is wrong and the  
while statement's is correct, but it could go either way.


I agree, I think case with 'when' works as specs say.

No need for a rationale for what can be adequately explained as a  
compiler bug


There is still correct but unexpected behaviour. I found this on bugtracker
http://d.puremagic.com/issues/show_bug.cgi?id=199
The rationale was I don't want to change this because it could break  
existing code,

and there doesn't seem to be a compelling reason to do so. Well. :(


Please to report to bugzilla


I'll report about if/while inconsistency.

--
Using Opera's revolutionary email client: http://www.opera.com/mail/