www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Introspection/Reflection/etc on Linux

reply J Arrizza <cppgent0 gmail.com> writes:
--bcaec521572b53552704af957f4d
Content-Type: text/plain; charset=ISO-8859-1

I'm trying to write some sample code to:
  1 create an object via it's name
  2 search an object for it's functions
  3 call a static function in a class
  4 call a non-static function in an object

#1, #2 and #3 were straightforward. But  #4 looks like it's not possible in
DMD 2.0.

I found this:

http://www.digitalmars.com/d/archives/digitalmars/D/announce/Runtime_reflection_9949.html

which implies #4 is doable in Windows but not Linux. I'm using Linux 64-bit
Ubuntu.

Any other avenues I can chase?

TIA,
John

--bcaec521572b53552704af957f4d
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<meta http-equiv=3D"content-type" content=3D"text/html; charset=3Dutf-8"><d=
iv>I&#39;m trying to write some sample code to:</div><div>=A0 1 create an o=
bject via it&#39;s name</div><div>=A0 2 search an object for it&#39;s funct=
ions</div>
<div>=A0 3 call a static function in a class</div><div>=A0 4 call a non-sta=
tic function in an object</div><div><br></div><div>#1, #2 and #3 were strai=
ghtforward. But =A0#4 looks like it&#39;s not possible in DMD 2.0.</div><di=
v>
<br></div><div>I found this:</div><div><br></div><span class=3D"Apple-style=
-span" style=3D"border-collapse: collapse; font-family: arial, sans-serif; =
font-size: 13px; "><a href=3D"http://www.digitalmars.com/d/archives/digital=
mars/D/announce/Runtime_reflection_9949.html" target=3D"_blank" style=3D"co=
lor: rgb(0, 0, 204); ">http://www.digitalmars.com/d/archives/digitalmars/D/=
announce/Runtime_reflection_9949.html</a></span><br>
<br>
<div>which implies #4 is doable in Windows but not Linux. I&#39;m using Lin=
ux 64-bit Ubuntu.</div><div><br></div><div>Any other avenues I can chase?</=
div><div><br></div><div>TIA,</div><div>John</div>

--bcaec521572b53552704af957f4d--
Oct 18 2011
next sibling parent "Robert Jacques" <sandford jhu.edu> writes:
On Tue, 18 Oct 2011 12:48:47 -0400, J Arrizza <cppgent0 gmail.com> wrote:

 I'm trying to write some sample code to:
   1 create an object via it's name
   2 search an object for it's functions
   3 call a static function in a class
   4 call a non-static function in an object

 #1, #2 and #3 were straightforward. But  #4 looks like it's not possible in
 DMD 2.0.

 I found this:

 http://www.digitalmars.com/d/archives/digitalmars/D/announce/Runtime_reflection_9949.html

 which implies #4 is doable in Windows but not Linux. I'm using Linux 64-bit
 Ubuntu.

 Any other avenues I can chase?

 TIA,
 John

You could try out my improved variant implementation: https://jshare.johnshopkins.edu/rjacque2/public_html/variant.mht https://jshare.johnshopkins.edu/rjacque2/public_html/variant.d Example: import variant; class Foo { int x; } void main(string[] args) { Variant.__register!Foo; Variant var = Object.factory( typeid(Foo).toString ); var.__reflect("x",Variant(10)); // or explicitly assert(var.__reflect("x") == 10); return; }
Oct 18 2011
prev sibling next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2011-10-18 18:48, J Arrizza wrote:
 I'm trying to write some sample code to:
    1 create an object via it's name
    2 search an object for it's functions
    3 call a static function in a class
    4 call a non-static function in an object

 #1, #2 and #3 were straightforward. But  #4 looks like it's not possible
 in DMD 2.0.

 I found this:

 http://www.digitalmars.com/d/archives/digitalmars/D/announce/Runtime_reflection_9949.html

 which implies #4 is doable in Windows but not Linux. I'm using Linux
 64-bit Ubuntu.

 Any other avenues I can chase?

 TIA,
 John

How about doing something like this: class Foo { void bar () { writeln("bar"); } } void main () { auto foo = new Foo; auto members = __traits(derivedMembers, Foo); void delegate () dg; foreach (i, m ; members) if (m == "bar") dg.funcptr = cast(void function()) foo.classinfo.vtbl[i + 6]; dg.ptr = cast(void*) foo; dg(); } -- /Jacob Carlborg
Oct 19 2011
parent reply Jacob Carlborg <doob me.com> writes:
On 2011-10-19 11:24, J Arrizza wrote:
 Just noticed an odd thing when I was trying Jacob's code.

 This works great:
      auto x = new someClass();
      Object o = x;
      void delegate() dg;
      foreach(i, m; __traits(derivedMembers, someClass))
        {
          writeln("i=", i, "  m=", m);

          if(m != "__ctor")
            {
              dg.funcptr = cast(void function()) o.classinfo.vtbl[i + 6];
              dg.ptr = cast(void*) o;
              dg();
            }
        }

 but this doesn't (it segfaults):
      Object o = Object.factory("someClass");
      void delegate() dg;
      foreach(i, m; __traits(derivedMembers, someClass))
        {
          writeln("i=", i, "  m=", m);

          if(m != "__ctor")
            {
              dg.funcptr = cast(void function()) o.classinfo.vtbl[i + 6];
              dg.ptr = cast(void*) o;
              dg();
            }
        }


 Is the object returned by Object.factory() not the same somehow as the
 one returned by new()?

 John

For Object.factory you need the fully qualified name, i.e. SomeClass.classinfo.name. If Object.factory can't find a class name it will just return null. -- /Jacob Carlborg
Oct 19 2011
parent Jacob Carlborg <doob me.com> writes:
On 2011-10-20 07:44, J Arrizza wrote:
 Yup, didn't check for null, damn it. Can I blame it on working on it at
 2:30AM? Forget the excuse, I just didn't check for null.

 For future reference, the fully qualified name for SomeClass is
 "SomeClass.SomeClass".   If I create class Bob in the SomeClass file
 "SomeClass.Bob". The first node is the file name, the second the actual
 name of the class. I imagine there is additional complications for
 nested classes.

The fully qualified class name includes the module the class is defined in, if you're unsure you can get it by running: writeln(SomeClass.classinfo.name);
 Thanks Jacob,
 John


     For Object.factory you need the fully qualified name, i.e.
     SomeClass.classinfo.name <http://SomeClass.classinfo.name>. If
     Object.factory can't find a class name it will just return null.

     --
     /Jacob Carlborg

-- /Jacob Carlborg
Oct 19 2011
prev sibling next sibling parent Jacob Carlborg <doob me.com> writes:
On 2011-10-18 18:48, J Arrizza wrote:
 I'm trying to write some sample code to:
    1 create an object via it's name
    2 search an object for it's functions
    3 call a static function in a class
    4 call a non-static function in an object

 #1, #2 and #3 were straightforward. But  #4 looks like it's not possible
 in DMD 2.0.

 I found this:

 http://www.digitalmars.com/d/archives/digitalmars/D/announce/Runtime_reflection_9949.html

 which implies #4 is doable in Windows but not Linux. I'm using Linux
 64-bit Ubuntu.

 Any other avenues I can chase?

 TIA,
 John

Runtime reflection by inspecting the symbol table of the currently executing application: http://flectioned.kuehne.cn/ -- /Jacob Carlborg
Oct 19 2011
prev sibling next sibling parent J Arrizza <cppgent0 gmail.com> writes:
--bcaec52161cff0415704afa366d8
Content-Type: text/plain; charset=ISO-8859-1

Just noticed an odd thing when I was trying Jacob's code.

This works great:
    auto x = new someClass();
    Object o = x;
    void delegate() dg;
    foreach(i, m; __traits(derivedMembers, someClass))
      {
        writeln("i=", i, "  m=", m);

        if(m != "__ctor")
          {
            dg.funcptr = cast(void function()) o.classinfo.vtbl[i + 6];
            dg.ptr = cast(void*) o;
            dg();
          }
      }

but this doesn't (it segfaults):
    Object o = Object.factory("someClass");
    void delegate() dg;
    foreach(i, m; __traits(derivedMembers, someClass))
      {
        writeln("i=", i, "  m=", m);

        if(m != "__ctor")
          {
            dg.funcptr = cast(void function()) o.classinfo.vtbl[i + 6];
            dg.ptr = cast(void*) o;
            dg();
          }
      }


Is the object returned by Object.factory() not the same somehow as the one
returned by new()?

John

--bcaec52161cff0415704afa366d8
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div>Just noticed an odd thing when I was trying Jacob&#39;s code.</div><di=
v><br></div><div>This works great:</div><div>=A0 =A0 auto x =3D new someCla=
ss();</div><div>=A0 =A0 Object o =3D x;</div><div><div>=A0 =A0 void delegat=
e() dg;</div>
<div>=A0 =A0 foreach(i, m; __traits(derivedMembers,=A0someClass))</div><div=
=A0 =A0 =A0 {</div><div>=A0 =A0 =A0 =A0 writeln(&quot;i=3D&quot;, i, &quot=

ot;__ctor&quot;)</div><div>=A0 =A0 =A0 =A0 =A0 {</div> <div>=A0 =A0 =A0 =A0 =A0 =A0 dg.funcptr =3D cast(void function()) o.classin= fo.vtbl[i + 6];</div><div>=A0 =A0 =A0 =A0 =A0 =A0 dg.ptr =3D cast(void*) o;= </div><div>=A0 =A0 =A0 =A0 =A0 =A0 dg();</div><div>=A0 =A0 =A0 =A0 =A0 }</d= iv><div>=A0 =A0 =A0 }</div></div><div><br></div><div> but this doesn&#39;t (it segfaults):</div><div><div>=A0 =A0 Object o =3D Ob= ject.factory(&quot;someClass&quot;);</div></div><div><div><div>=A0 =A0 void= delegate() dg;</div><div>=A0 =A0 foreach(i, m; __traits(derivedMembers,=A0= someClass))</div> <div>=A0 =A0 =A0 {</div><div>=A0 =A0 =A0 =A0 writeln(&quot;i=3D&quot;, i, &= quot; =A0m=3D&quot;, m);</div><div><br></div><div>=A0 =A0 =A0 =A0 if(m !=3D= &quot;__ctor&quot;)</div><div>=A0 =A0 =A0 =A0 =A0 {</div><div>=A0 =A0 =A0 = =A0 =A0 =A0 dg.funcptr =3D cast(void function()) o.classinfo.vtbl[i + 6];</= div> <div>=A0 =A0 =A0 =A0 =A0 =A0 dg.ptr =3D cast(void*) o;</div><div>=A0 =A0 = =A0 =A0 =A0 =A0 dg();</div><div>=A0 =A0 =A0 =A0 =A0 }</div><div>=A0 =A0 =A0= }</div></div></div><div><br></div><div><br></div><div>Is the object return= ed by Object.factory() not the same somehow as the one returned by new()?</= div> <div><br></div><div>John</div><div><br></div> --bcaec52161cff0415704afa366d8--
Oct 19 2011
prev sibling next sibling parent J Arrizza <cppgent0 gmail.com> writes:
--000e0cd4b29856bcff04afb4742d
Content-Type: text/plain; charset=ISO-8859-1

Yup, didn't check for null, damn it. Can I blame it on working on it at
2:30AM? Forget the excuse, I just didn't check for null.

For future reference, the fully qualified name for SomeClass is
"SomeClass.SomeClass".   If I create class Bob in the SomeClass file
"SomeClass.Bob". The first node is the file name, the second the actual name
of the class. I imagine there is additional complications for nested
classes.

Thanks Jacob,
John


For Object.factory you need the fully qualified name, i.e.
 SomeClass.classinfo.name. If Object.factory can't find a class name it
 will just return null.

 --
 /Jacob Carlborg

--000e0cd4b29856bcff04afb4742d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Yup, didn&#39;t check for null, damn it. Can I blame it on working on it at= 2:30AM? Forget the excuse, I just didn&#39;t check for null.<div><br></div=
<div>For future reference, the fully qualified name for SomeClass is &quot=

le &quot;SomeClass.Bob&quot;.=A0The first node is the file name, the second= the actual name of the class. I imagine there is additional complications = for nested classes.</div> <div><br></div><div>Thanks Jacob,</div><div>John</div><div><br><br><div cla= ss=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 = .8ex;border-left:1px #ccc solid;padding-left:1ex;"> For Object.factory you need the fully qualified name, i.e. <a href=3D"http:= //SomeClass.classinfo.name" target=3D"_blank">SomeClass.classinfo.name</a>.= If Object.factory can&#39;t find a class name it will just return null.<br=

<br> -- <br> /Jacob Carlborg<br> </font></blockquote></div><br> </div> --000e0cd4b29856bcff04afb4742d--
Oct 19 2011
prev sibling next sibling parent J Arrizza <cppgent0 gmail.com> writes:
--f46d041037990f64f904b0033c06
Content-Type: text/plain; charset=ISO-8859-1

Jacob, by the way, I did try flectioned and unfortunately it failed to
compile.

   http://flectioned.kuehne.cn/

According to the comments it should work in windows or linux and it should
work with D1 and D2. However I got quite a few compiler errors using:

    $ dmd -v
    DMD64 D Compiler v2.055

I tried fixing as many as I could, but at this point in my D skills, it was
beyond me.

It looked promising though. I did something similar by parsing the PE format
of Windows DLLs http://www.arrizza.com/unittesters/utx/utx.html . Kind of
kludgy though. I had to de-mangle the names in the internal PE dictionary,
making it wholly reliant on the microsoft compiler. But it worked...

John


On Wed, Oct 19, 2011 at 1:22 AM, Jacob Carlborg <doob me.com> wrote:

 Runtime reflection by inspecting the symbol table of the currently
 executing application: http://flectioned.kuehne.cn/

 --
 /Jacob Carlborg

-- John blog: http://arrizza.blogspot.com/ web: http://www.arrizza.com/ --f46d041037990f64f904b0033c06 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div>Jacob, by the way, I did try flectioned and unfortunately it failed to= compile.</div><div><br></div>=A0 =A0<a href=3D"http://flectioned.kuehne.cn= /" target=3D"_blank">http://flectioned.kuehne.cn/</a><div><br></div><div>Ac= cording to the comments it should work in windows or linux and it should wo= rk with D1 and D2. However I got quite a few compiler errors using:</div> <div><br></div><div><div>=A0 =A0 $ dmd -v</div><div>=A0 =A0 DMD64 D Compile= r v2.055</div></div><div><br></div><div>I tried fixing as many as I could, = but at this point in my D skills, it was beyond me.=A0</div><div><br></div>= <div>It looked promising though. I did something similar by parsing the PE = format of Windows DLLs=A0<a href=3D"http://www.arrizza.com/unittesters/utx/= utx.html">http://www.arrizza.com/unittesters/utx/utx.html</a>=A0. Kind of k= ludgy though. I had to de-mangle the names in the internal PE dictionary, m= aking it wholly reliant on the microsoft compiler. But it worked...</div> <div><br></div><div>John</div><div><br><br><div class=3D"gmail_quote">On We= d, Oct 19, 2011 at 1:22 AM, Jacob Carlborg <span dir=3D"ltr">&lt;<a href=3D= "mailto:doob me.com">doob me.com</a>&gt;</span> wrote:<br><blockquote class= =3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd= ing-left:1ex;"> <div class=3D"im"><br></div> Runtime reflection by inspecting the symbol table of the currently executin= g application: <a href=3D"http://flectioned.kuehne.cn/" target=3D"_blank">h= ttp://flectioned.kuehne.cn/</a><br><font color=3D"#888888"> <br> -- <br> /Jacob Carlborg<br> </font></blockquote></div><br><br clear=3D"all"><div><br></div>-- <br>John<= br>blog: <a href=3D"http://arrizza.blogspot.com/">http://arrizza.blogspot.c= om/</a><br>web: <a href=3D"http://www.arrizza.com/">http://www.arrizza.com/= </a><br> </div> --f46d041037990f64f904b0033c06--
Oct 23 2011
prev sibling next sibling parent J Arrizza <cppgent0 gmail.com> writes:
--0015177408a27ef23b04b0b0b88b
Content-Type: text/plain; charset=ISO-8859-1

Robert,

I tried using variant.d using your exact test program below and I got
compiler errors:

$ dmd  variant.d dtest.d
variant.d(273): Error: no property 'length' for type 'Result'
variant.d(273): Error: no property 'length' for type 'Result'
variant.d(274): Error: no property 'length' for type 'Result'
variant.d(274): Error: no property 'length' for type 'Result'
variant.d(274): Error: no property 'length' for type 'Result'
variant.d(275): Error: no property 'length' for type 'Result'
variant.d(277): Error: no property 'length' for type 'Result'
variant.d(277): Error: no property 'length' for type 'Result'
variant.d(277): Error: no property 'length' for type 'Result'
variant.d(277): Error: no property 'length' for type 'Result'
variant.d(280): Error: no property 'length' for type 'Result'
$ dmd -v
DMD64 D Compiler v2.055

Am I missing a switch or something?

John

On Tue, Oct 18, 2011 at 8:13 PM, Robert Jacques <sandford jhu.edu> wrote:

 You could try out my improved variant implementation:

 https://jshare.johnshopkins.**edu/rjacque2/public_html/**variant.mht<https://jshare.johnshopkins.edu/rjacque2/public_html/variant.mht>

 https://jshare.johnshopkins.**edu/rjacque2/public_html/**variant.d<https://jshare.johnshopkins.edu/rjacque2/public_html/variant.d>

 Example:

 import variant;

 class Foo { int x; }
 void main(string[] args) {
    Variant.__register!Foo;
    Variant var = Object.factory( typeid(Foo).toString );
    var.__reflect("x",Variant(10))**; // or explicitly
    assert(var.__reflect("x") == 10);
    return;
 }

-- John blog: http://arrizza.blogspot.com/ web: http://www.arrizza.com/ --0015177408a27ef23b04b0b0b88b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Robert,<div><br></div><div>I tried using variant.d using your exact test pr= ogram below and I got compiler errors:</div><div><br></div><div>$ dmd =A0va= riant.d dtest.d</div><div>variant.d(273): Error: no property &#39;length&#3= 9; for type &#39;Result&#39;</div> <div><div>variant.d(273): Error: no property &#39;length&#39; for type &#39= ;Result&#39;</div><div>variant.d(274): Error: no property &#39;length&#39; = for type &#39;Result&#39;</div><div>variant.d(274): Error: no property &#39= ;length&#39; for type &#39;Result&#39;</div> <div>variant.d(274): Error: no property &#39;length&#39; for type &#39;Resu= lt&#39;</div><div>variant.d(275): Error: no property &#39;length&#39; for t= ype &#39;Result&#39;</div><div>variant.d(277): Error: no property &#39;leng= th&#39; for type &#39;Result&#39;</div> <div>variant.d(277): Error: no property &#39;length&#39; for type &#39;Resu= lt&#39;</div><div>variant.d(277): Error: no property &#39;length&#39; for t= ype &#39;Result&#39;</div><div>variant.d(277): Error: no property &#39;leng= th&#39; for type &#39;Result&#39;</div> <div>variant.d(280): Error: no property &#39;length&#39; for type &#39;Resu= lt&#39;</div><div><div>$ dmd -v</div><div>DMD64 D Compiler v2.055</div></di= v><div><br></div>Am I missing a switch or something?</div><div><br></div> <div>John<br><div class=3D"gmail_quote"><br></div><div class=3D"gmail_quote= ">On Tue, Oct 18, 2011 at 8:13 PM, Robert Jacques <span dir=3D"ltr">&lt;<a = href=3D"mailto:sandford jhu.edu">sandford jhu.edu</a>&gt;</span> wrote:<br>= <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex;"> <div class=3D"im">You could try out my improved variant implementation:</di= v> <br> <a href=3D"https://jshare.johnshopkins.edu/rjacque2/public_html/variant.mht= " target=3D"_blank">https://jshare.johnshopkins.<u></u>edu/rjacque2/public_= html/<u></u>variant.mht</a><br> <br> <a href=3D"https://jshare.johnshopkins.edu/rjacque2/public_html/variant.d" = target=3D"_blank">https://jshare.johnshopkins.<u></u>edu/rjacque2/public_ht= ml/<u></u>variant.d</a><br> <br> Example:<br> <br> import variant;<br> <br> class Foo { int x; }<br> void main(string[] args) {<br> =A0 =A0Variant.__register!Foo;<br> =A0 =A0Variant var =3D Object.factory( typeid(Foo).toString );<br> =A0 =A0var.__reflect(&quot;x&quot;,Variant(10))<u></u>; // or explicitly<b= r> =A0 =A0assert(var.__reflect(&quot;x&quot;) =3D=3D 10);<br> =A0 =A0return;<br> }<br> </blockquote></div><br><br clear=3D"all"><div><br></div>-- <br>John<br>blog= : <a href=3D"http://arrizza.blogspot.com/">http://arrizza.blogspot.com/</a>= <br>web: <a href=3D"http://www.arrizza.com/">http://www.arrizza.com/</a><br=

</div> --0015177408a27ef23b04b0b0b88b--
Nov 01 2011
prev sibling next sibling parent "Robert Jacques" <sandford jhu.edu> writes:
On Tue, 01 Nov 2011 14:42:42 -0400, J Arrizza <cppgent0 gmail.com> wrote:

 Robert,

 I tried using variant.d using your exact test program below and I got
 compiler errors:

 $ dmd  variant.d dtest.d
 variant.d(273): Error: no property 'length' for type 'Result'
 variant.d(273): Error: no property 'length' for type 'Result'
 variant.d(274): Error: no property 'length' for type 'Result'
 variant.d(274): Error: no property 'length' for type 'Result'
 variant.d(274): Error: no property 'length' for type 'Result'
 variant.d(275): Error: no property 'length' for type 'Result'
 variant.d(277): Error: no property 'length' for type 'Result'
 variant.d(277): Error: no property 'length' for type 'Result'
 variant.d(277): Error: no property 'length' for type 'Result'
 variant.d(277): Error: no property 'length' for type 'Result'
 variant.d(280): Error: no property 'length' for type 'Result'
 $ dmd -v
 DMD64 D Compiler v2.055

 Am I missing a switch or something?

 John

(I apologize if this gets sent twice, my newsreader is acting up) Nope, (hopefully) just patches. I maintain a list of the bugzilla patches (i.e. http://d.puremagic.com/issues/show_bug.cgi?id=5155) I've applied at the top of the file. But, mostly those are so DMD doesn't ICE; I've never seen this particular error before and am not sure how to interpret it. Hmm.. I don't use a Result type, but std.algoroithm does and one of the patches I always use is 6256 (http://d.puremagic.com/issues/show_bug.cgi?id=6256), which addresses length for Map.
Nov 02 2011
prev sibling next sibling parent J Arrizza <cppgent0 gmail.com> writes:
--14dae93409b78138b904b0d20610
Content-Type: text/plain; charset=ISO-8859-1

Robert,

This stub shows the issue:

import std.stdio;
import std.range;

void main(string[] args)
  {
    string id = "somestring";
    auto rid = retro(id);
    writeln(rid.length);
  }

$: dmd  dtest.d
dtest.d(8): Error: no property 'length' for type 'Result'


I haven't applied either patch you mentioned below. Neither patch seems to
address retro() or Result...

John



On Wed, Nov 2, 2011 at 6:43 AM, Robert Jacques <sandford jhu.edu> wrote:

 On Tue, 01 Nov 2011 14:42:42 -0400, J Arrizza <cppgent0 gmail.com> wrote:

  Robert,
 I tried using variant.d using your exact test program below and I got
 compiler errors:

 $ dmd  variant.d dtest.d
 variant.d(273): Error: no property 'length' for type 'Result'
 variant.d(273): Error: no property 'length' for type 'Result'
 variant.d(274): Error: no property 'length' for type 'Result'
 variant.d(274): Error: no property 'length' for type 'Result'
 variant.d(274): Error: no property 'length' for type 'Result'
 variant.d(275): Error: no property 'length' for type 'Result'
 variant.d(277): Error: no property 'length' for type 'Result'
 variant.d(277): Error: no property 'length' for type 'Result'
 variant.d(277): Error: no property 'length' for type 'Result'
 variant.d(277): Error: no property 'length' for type 'Result'
 variant.d(280): Error: no property 'length' for type 'Result'
 $ dmd -v
 DMD64 D Compiler v2.055

 Am I missing a switch or something?

 John

(I apologize if this gets sent twice, my newsreader is acting up) Nope, (hopefully) just patches. I maintain a list of the bugzilla patches (i.e. http://d.puremagic.com/issues/**show_bug.cgi?id=5155<http://d.puremagic.com/issues/show_bug.cgi?id=5155>) I've applied at the top of the file. But, mostly those are so DMD doesn't ICE; I've never seen this particular error before and am not sure how to interpret it. Hmm.. I don't use a Result type, but std.algoroithm does and one of the patches I always use is 6256 (http://d.puremagic.com/** issues/show_bug.cgi?id=6256<http://d.puremagic.com/issues/show_bug.cgi?id=6256>), which addresses length for Map.

-- John blog: http://arrizza.blogspot.com/ web: http://www.arrizza.com/ --14dae93409b78138b904b0d20610 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div>Robert,=A0</div><div><br></div><div>This stub shows the issue:</div><b= lockquote class=3D"webkit-indent-blockquote" style=3D"margin: 0 0 0 40px; b= order: none; padding: 0px;"><div><font class=3D"Apple-style-span" face=3D"&= #39;courier new&#39;, monospace">import std.stdio;</font></div> <div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp= ace">import std.range;</font></div><div><font class=3D"Apple-style-span" fa= ce=3D"&#39;courier new&#39;, monospace"><br></font></div><div><font class= =3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">void main(s= tring[] args)</font></div> <div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp= ace">=A0 {</font></div><div><font class=3D"Apple-style-span" face=3D"&#39;c= ourier new&#39;, monospace">=A0 =A0 string id =3D &quot;somestring&quot;;</= font></div><div> <font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">= =A0 =A0 auto rid =3D retro(id);</font></div><div><font class=3D"Apple-style= -span" face=3D"&#39;courier new&#39;, monospace">=A0 =A0 writeln(rid.length= );</font></div> <div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp= ace">=A0 }</font></div><div><font class=3D"Apple-style-span" face=3D"&#39;c= ourier new&#39;, monospace"><br></font></div><div><div><font class=3D"Apple= -style-span" face=3D"&#39;courier new&#39;, monospace">$: dmd =A0dtest.d=A0= </font></div> </div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#= 39;, monospace">dtest.d(8): Error: no property &#39;length&#39; for type &#= 39;Result&#39;</font></div></div></blockquote><div><br></div><div>I haven&#= 39;t applied either patch you mentioned below. Neither patch seems to addre= ss retro() or Result...=A0</div> <div><br></div><div>John</div><div><br></div><div><br></div><br><div class= =3D"gmail_quote">On Wed, Nov 2, 2011 at 6:43 AM, Robert Jacques <span dir= =3D"ltr">&lt;<a href=3D"mailto:sandford jhu.edu">sandford jhu.edu</a>&gt;</= span> wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex;"><div class=3D"im">On Tue, 01 Nov 2011 14:42= :42 -0400, J Arrizza &lt;<a href=3D"mailto:cppgent0 gmail.com" target=3D"_b= lank">cppgent0 gmail.com</a>&gt; wrote:<br> <br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> Robert,<br> <br> I tried using variant.d using your exact test program below and I got<br> compiler errors:<br> <br> $ dmd =A0variant.d dtest.d<br> variant.d(273): Error: no property &#39;length&#39; for type &#39;Result&#3= 9;<br> variant.d(273): Error: no property &#39;length&#39; for type &#39;Result&#3= 9;<br> variant.d(274): Error: no property &#39;length&#39; for type &#39;Result&#3= 9;<br> variant.d(274): Error: no property &#39;length&#39; for type &#39;Result&#3= 9;<br> variant.d(274): Error: no property &#39;length&#39; for type &#39;Result&#3= 9;<br> variant.d(275): Error: no property &#39;length&#39; for type &#39;Result&#3= 9;<br> variant.d(277): Error: no property &#39;length&#39; for type &#39;Result&#3= 9;<br> variant.d(277): Error: no property &#39;length&#39; for type &#39;Result&#3= 9;<br> variant.d(277): Error: no property &#39;length&#39; for type &#39;Result&#3= 9;<br> variant.d(277): Error: no property &#39;length&#39; for type &#39;Result&#3= 9;<br> variant.d(280): Error: no property &#39;length&#39; for type &#39;Result&#3= 9;<br> $ dmd -v<br> DMD64 D Compiler v2.055<br> <br> Am I missing a switch or something?<br> <br> John<br> </blockquote> <br></div> (I apologize if this gets sent twice, my newsreader is acting up)<br> <br> Nope, (hopefully) just patches. I maintain a list of the bugzilla patches (= i.e. <a href=3D"http://d.puremagic.com/issues/show_bug.cgi?id=3D5155" targe= t=3D"_blank">http://d.puremagic.com/issues/<u></u>show_bug.cgi?id=3D5155</a=
) I&#39;ve applied at the top of the file. But, mostly those are so DMD do=

sure how to interpret it. Hmm.. I don&#39;t use a Result type, but std.algo= roithm does and one of the patches I always use is 6256 (<a href=3D"http://= d.puremagic.com/issues/show_bug.cgi?id=3D6256" target=3D"_blank">http://d.p= uremagic.com/<u></u>issues/show_bug.cgi?id=3D6256</a>), which addresses len= gth for Map.<br> </blockquote></div><br><br clear=3D"all"><div><br></div>-- <br>John<br>blog= : <a href=3D"http://arrizza.blogspot.com/">http://arrizza.blogspot.com/</a>= <br>web: <a href=3D"http://www.arrizza.com/">http://www.arrizza.com/</a><br=

--14dae93409b78138b904b0d20610--
Nov 03 2011
prev sibling next sibling parent J Arrizza <cppgent0 gmail.com> writes:
--001517741520c1acc804b0d20cd7
Content-Type: text/plain; charset=ISO-8859-1

PS, this version works and prints "10" for the length:

    string id = "somestring";
    auto rid = retro(id);
    //writeln(rid.length);
    writeln(rid.source.length);


On Thu, Nov 3, 2011 at 3:26 AM, J Arrizza <cppgent0 gmail.com> wrote:

 Robert,

 This stub shows the issue:

 import std.stdio;
 import std.range;

 void main(string[] args)
   {
     string id = "somestring";
     auto rid = retro(id);
     writeln(rid.length);
   }

 $: dmd  dtest.d
 dtest.d(8): Error: no property 'length' for type 'Result'


 I haven't applied either patch you mentioned below. Neither patch seems to
 address retro() or Result...

 John

--001517741520c1acc804b0d20cd7 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div>PS, this version works and prints &quot;10&quot; for the length:</div>= <div><br></div><div>=A0 =A0 string id =3D &quot;somestring&quot;;</div><div=
=A0 =A0 auto rid =3D retro(id);</div><div>=A0 =A0 //writeln(rid.length);</=

<div><br></div><br><div class=3D"gmail_quote">On Thu, Nov 3, 2011 at 3:26 A= M, J Arrizza <span dir=3D"ltr">&lt;<a href=3D"mailto:cppgent0 gmail.com">cp= pgent0 gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote"= style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> <div>Robert,=A0</div><div><br></div><div>This stub shows the issue:</div><b= lockquote style=3D"margin:0 0 0 40px;border:none;padding:0px"><div><font fa= ce=3D"&#39;courier new&#39;, monospace">import std.stdio;</font></div> <div><font face=3D"&#39;courier new&#39;, monospace">import std.range;</fon= t></div><div><font face=3D"&#39;courier new&#39;, monospace"><br></font></d= iv><div><font face=3D"&#39;courier new&#39;, monospace">void main(string[] = args)</font></div> <div><font face=3D"&#39;courier new&#39;, monospace">=A0 {</font></div><div=
<font face=3D"&#39;courier new&#39;, monospace">=A0 =A0 string id =3D &quo=

<font face=3D"&#39;courier new&#39;, monospace">=A0 =A0 auto rid =3D retro(= id);</font></div><div><font face=3D"&#39;courier new&#39;, monospace">=A0 = =A0 writeln(rid.length);</font></div> <div><font face=3D"&#39;courier new&#39;, monospace">=A0 }</font></div><div=
<font face=3D"&#39;courier new&#39;, monospace"><br></font></div><div><div=
<font face=3D"&#39;courier new&#39;, monospace">$: dmd =A0dtest.d=A0</font=
</div>

</div><div><div><font face=3D"&#39;courier new&#39;, monospace">dtest.d(8):= Error: no property &#39;length&#39; for type &#39;Result&#39;</font></div>= </div></blockquote><div><br></div><div>I haven&#39;t applied either patch y= ou mentioned below. Neither patch seems to address retro() or Result...=A0<= /div> <div><br></div><div>John</div><div><div></div><div class=3D"h5"><div><br></= div><div><br></div></div></div></blockquote></div> --001517741520c1acc804b0d20cd7--
Nov 03 2011
prev sibling next sibling parent "Robert Jacques" <sandford jhu.edu> writes:
On Thu, 03 Nov 2011 06:28:30 -0400, J Arrizza <cppgent0 gmail.com> wrote:
 PS, this version works and prints "10" for the length:

     string id = "somestring";
     auto rid = retro(id);
     //writeln(rid.length);
     writeln(rid.source.length);


 On Thu, Nov 3, 2011 at 3:26 AM, J Arrizza <cppgent0 gmail.com> wrote:

 Robert,

 This stub shows the issue:

 import std.stdio;
 import std.range;

 void main(string[] args)
   {
     string id = "somestring";
     auto rid = retro(id);
     writeln(rid.length);
   }

 $: dmd  dtest.d
 dtest.d(8): Error: no property 'length' for type 'Result'


 I haven't applied either patch you mentioned below. Neither patch seems to
 address retro() or Result...

 John


Thanks John for tracking this down and finding a work around. It seems that the behavior of retro changed between 2.053 and 2.055. As you've probably already found, the errors are in the typeinfo2stringof function on line 245 of the currently uploaded variant.
Nov 03 2011
prev sibling next sibling parent J Arrizza <cppgent0 gmail.com> writes:
--0015177415207a725204b0e24f4b
Content-Type: text/plain; charset=ISO-8859-1

Here's my changes to it:

   //Convert a string representation of a type, produced by typeinfo into a
.stringof representation
    string typeinfo2stringof(string id){
        auto rid = retro(id);
        auto r1  = find(rid, '.');
        auto rb  = find(rid, '!');
        auto r1len = r1.source.length;

        if(!rb.empty) {
            auto r1a = r1;
                 r1a.popFront;
                  rb.popFront;
            auto r2  = find(r1a,'.');
            auto r1alen = r1a.source.length;
            auto r2len = r2.source.length;
            auto rblen = rb.source.length;
            assert(id[r2len..rblen]==id[r1len..r1len+ (rblen-r2len)],
"Internal error in std.Variant regarding converting toString to stringof.");
            if(r1len+(rblen-r2len) >= id.length ) {
                id = id[r2len..r1alen];
            } else {
                id = id[r2len..r1alen]~id[r1len +(rblen-r2len)..$];
            }
        } else {
            id = id[r1len..$];
        }
        return id;
    }

--0015177415207a725204b0e24f4b
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div>Here&#39;s my changes to it:</div><div><font class=3D"Apple-style-span=
" face=3D"&#39;courier new&#39;, monospace"><br></font></div><div><font cla=
ss=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 =A0//=
Convert a string representation of a type, produced by typeinfo into a .str=
ingof representation</font></div>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">=A0 =A0 string typeinfo2stringof(string id){</font></div><div><font cl=
ass=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 =A0 =
=A0 =A0 auto rid =3D retro(id);</font></div>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">=A0 =A0 =A0 =A0 auto r1 =A0=3D find(rid, &#39;.&#39;);</font></div><di=
v><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace=
">=A0 =A0 =A0 =A0 auto rb =A0=3D find(rid, &#39;!&#39;);</font></div>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">=A0 =A0 =A0 =A0 auto r1len =3D r1.source.length;</font></div><div><fon=
t class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace"><br>=
</font></div><div>
<font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">=
=A0 =A0 =A0 =A0 if(!rb.empty) {</font></div><div><font class=3D"Apple-style=
-span" face=3D"&#39;courier new&#39;, monospace">=A0 =A0 =A0 =A0 =A0 =A0 au=
to r1a =3D r1;</font></div>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0r1a.popFront;</font></div><div><fon=
t class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 rb.popFront;</font></div>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">=A0 =A0 =A0 =A0 =A0 =A0 auto r2 =A0=3D find(r1a,&#39;.&#39;);</font></=
div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, mo=
nospace">=A0 =A0 =A0 =A0 =A0 =A0 auto r1alen =3D r1a.source.length;</font><=
/div>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">=A0 =A0 =A0 =A0 =A0 =A0 auto r2len =3D r2.source.length;</font></div><=
div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospa=
ce">=A0 =A0 =A0 =A0 =A0 =A0 auto rblen =3D rb.source.length;</font></div>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">=A0 =A0 =A0 =A0 =A0 =A0 assert(id[r2len..rblen]=3D=3Did[r1len..r1len+ =
(rblen-r2len)], &quot;Internal error in std.Variant regarding converting to=
String to stringof.&quot;);</font></div>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">=A0 =A0 =A0 =A0 =A0 =A0 if(r1len+(rblen-r2len) &gt;=3D id.length ) {</=
font></div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#=
39;, monospace">=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 id =3D id[r2len..r1alen];</=
font></div>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">=A0 =A0 =A0 =A0 =A0 =A0 } else {</font></div><div><font class=3D"Apple=
-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 id =3D id[r2len..r1alen]~id[r1len +(rblen-r2len)..$];</font></d=
iv>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">=A0 =A0 =A0 =A0 =A0 =A0 }</font></div><div><font class=3D"Apple-style-=
span" face=3D"&#39;courier new&#39;, monospace">=A0 =A0 =A0 =A0 } else {</f=
ont></div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#3=
9;, monospace">=A0 =A0 =A0 =A0 =A0 =A0 id =3D id[r1len..$];</font></div>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">=A0 =A0 =A0 =A0 }</font></div><div><font class=3D"Apple-style-span" fa=
ce=3D"&#39;courier new&#39;, monospace">=A0 =A0 =A0 =A0 return id;</font></=
div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, mo=
nospace">=A0 =A0 }</font></div>
<div><br></div><div><br></div>

--0015177415207a725204b0e24f4b--
Nov 03 2011
prev sibling next sibling parent J Arrizza <cppgent0 gmail.com> writes:
--90e6ba6e89d6131b5704b0e2d354
Content-Type: text/plain; charset=ISO-8859-1

And here's a working example:

import std.stdio;
import variant;
import std.string;
import std.conv;

//----
class Base
  {
    private int y;  //check if a variable causes any problems

    //run all member functions that start with "in"
    public void RunAllIn(alias T) ()
    {
      writeln("RunAllIn: ", typeid(T));
      Variant.__register!T;
      Variant var = this;
      foreach (i, m; __traits(derivedMembers, T))
        {
        if (!startsWith(m, "in"))
          {
            continue;
          }

        writeln("== i=", i, "  m=", m);
        var.__reflect(m);
        }
    }
  }

//----
class Bob : Base
  {
    private int x;  //check if a variable causes any problems
    //private int inx;  //causes an exception

    this()
      {
        RunAllIn!Bob;
      }

    public void inBob1()
      {
        writeln("   in bob : inBob1()");
      }

    public void inBob2()
      {
        writeln("   in bob : inBob2()");
      }
  }

//----
class Jane: Base
  {
    this()
      {
        RunAllIn!Jane;
      }

    public void inJane1()
      {
        writeln("   in jane : inJane1()");
      }

    public void inJane2()
      {
        writeln("   in jane : inJane2()");
      }
  }

void main(string[] args)
  {
    new Bob();
    new Jane();
  }


The output is:

$ rm -f dtest; dmd   dtest.d variant.d  -ofdtest; ./dtest
RunAllIn: dtest.Bob
== i=2  m=inBob1
   in bob : inBob1()
== i=3  m=inBob2
   in bob : inBob2()
RunAllIn: dtest.Jane
== i=1  m=inJane1
   in jane : inJane1()
== i=2  m=inJane2
   in jane : inJane2()


Perfect, thanks Robert! Works like a charm.

--90e6ba6e89d6131b5704b0e2d354
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

And here&#39;s a working example:
<div><br></div><blockquote class=3D"webkit-indent-blockquote" style=3D"marg=
in: 0 0 0 40px; border: none; padding: 0px;"><div><div><font class=3D"Apple=
-style-span" face=3D"&#39;courier new&#39;, monospace">import std.stdio;</f=
ont></div>
</div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#=
39;, monospace">import variant;</font></div></div><div><div><font class=3D"=
Apple-style-span" face=3D"&#39;courier new&#39;, monospace">import std.stri=
ng;</font></div>
</div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#=
39;, monospace">import std.conv;</font></div></div><div><div><font class=3D=
"Apple-style-span" face=3D"&#39;courier new&#39;, monospace"><br></font></d=
iv></div>
<div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, m=
onospace">//----</font></div></div><div><div><font class=3D"Apple-style-spa=
n" face=3D"&#39;courier new&#39;, monospace">class Base</font></div></div><=
div>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">=A0 {</font></div></div><div><div><font class=3D"Apple-style-span" fac=
e=3D"&#39;courier new&#39;, monospace">=A0 =A0 private int y; =A0//check if=
 a variable causes any problems</font></div>
</div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#=
39;, monospace">=A0 =A0=A0</font></div></div><div><div><font class=3D"Apple=
-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 =A0 //run all me=
mber functions that start with &quot;in&quot;</font></div>
</div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#=
39;, monospace">=A0 =A0 public void RunAllIn(alias T) ()</font></div></div>=
<div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, m=
onospace">=A0 =A0 {</font></div>
</div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#=
39;, monospace">=A0 =A0 =A0 writeln(&quot;RunAllIn: &quot;, typeid(T));</fo=
nt></div></div><div><div><font class=3D"Apple-style-span" face=3D"&#39;cour=
ier new&#39;, monospace">=A0 =A0 =A0 Variant.__register!T;</font></div>
</div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#=
39;, monospace">=A0 =A0 =A0 Variant var =3D this;</font></div></div><div><d=
iv><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospac=
e">=A0 =A0 =A0 foreach (i, m; __traits(derivedMembers, T))</font></div>
</div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#=
39;, monospace">=A0 =A0 =A0 =A0 {</font></div></div><div><div><font class=
=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 =A0 =A0=
 =A0 if (!startsWith(m, &quot;in&quot;))</font></div>
</div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#=
39;, monospace">=A0 =A0 =A0 =A0 =A0 {</font></div></div><div><div><font cla=
ss=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 =A0 =
=A0 =A0 =A0 =A0 continue;</font></div>
</div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#=
39;, monospace">=A0 =A0 =A0 =A0 =A0 }</font></div></div><div><div><font cla=
ss=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 =A0=
=A0</font></div></div>
<div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, m=
onospace">=A0 =A0 =A0 =A0 writeln(&quot;=3D=3D i=3D&quot;, i, &quot; =A0m=
=3D&quot;, m);</font></div></div><div><div><font class=3D"Apple-style-span"=
 face=3D"&#39;courier new&#39;, monospace">=A0 =A0 =A0 =A0 var.__reflect(m)=
;</font></div>
</div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#=
39;, monospace">=A0 =A0 =A0 =A0 }</font></div></div><div><div><font class=
=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 =A0 }</=
font></div></div><div>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">=A0 }</font></div></div><div><div><font class=3D"Apple-style-span" fac=
e=3D"&#39;courier new&#39;, monospace"><br></font></div></div><div><div><fo=
nt class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">//-=
---</font></div>
</div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#=
39;, monospace">class Bob : Base</font></div></div><div><div><font class=3D=
"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 {</font></=
div></div>
<div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, m=
onospace">=A0 =A0 private int x; =A0//check if a variable causes any proble=
ms</font></div></div><div><div><font class=3D"Apple-style-span" face=3D"&#3=
9;courier new&#39;, monospace">=A0 =A0 //private int inx; =A0//causes an ex=
ception</font></div>
</div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#=
39;, monospace">=A0 =A0=A0</font></div></div><div><div><font class=3D"Apple=
-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 =A0 this()</font=
</div></div><div>

ace">=A0 =A0 =A0 {</font></div></div><div><div><font class=3D"Apple-style-s= pan" face=3D"&#39;courier new&#39;, monospace">=A0 =A0 =A0 =A0 RunAllIn!Bob= ;</font></div></div> <div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, m= onospace">=A0 =A0 =A0 }</font></div></div><div><div><font class=3D"Apple-st= yle-span" face=3D"&#39;courier new&#39;, monospace"><br></font></div></div>= <div><div> <font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">= =A0 =A0 public void inBob1()</font></div></div><div><div><font class=3D"App= le-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 =A0 =A0 {</fon= t></div></div> <div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, m= onospace">=A0 =A0 =A0 =A0 writeln(&quot; =A0 in bob : inBob1()&quot;);</fon= t></div></div><div><div><font class=3D"Apple-style-span" face=3D"&#39;couri= er new&#39;, monospace">=A0 =A0 =A0 }</font></div> </div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#= 39;, monospace"><br></font></div></div><div><div><font class=3D"Apple-style= -span" face=3D"&#39;courier new&#39;, monospace">=A0 =A0 public void inBob2= ()</font></div> </div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#= 39;, monospace">=A0 =A0 =A0 {</font></div></div><div><div><font class=3D"Ap= ple-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 =A0 =A0 =A0 w= riteln(&quot; =A0 in bob : inBob2()&quot;);</font></div> </div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#= 39;, monospace">=A0 =A0 =A0 }</font></div></div><div><div><font class=3D"Ap= ple-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 }</font></div=
</div><div>

ace"><br></font></div></div><div><div><font class=3D"Apple-style-span" face= =3D"&#39;courier new&#39;, monospace">//----</font></div></div><div><div><f= ont class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">cl= ass Jane: Base</font></div> </div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#= 39;, monospace">=A0 {</font></div></div><div><div><font class=3D"Apple-styl= e-span" face=3D"&#39;courier new&#39;, monospace">=A0 =A0 this()</font></di= v></div><div> <div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp= ace">=A0 =A0 =A0 {</font></div></div><div><div><font class=3D"Apple-style-s= pan" face=3D"&#39;courier new&#39;, monospace">=A0 =A0 =A0 =A0 RunAllIn!Jan= e;</font></div></div> <div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, m= onospace">=A0 =A0 =A0 }</font></div></div><div><div><font class=3D"Apple-st= yle-span" face=3D"&#39;courier new&#39;, monospace">=A0=A0</font></div></di= v><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;,= monospace">=A0 =A0 public void inJane1()</font></div> </div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#= 39;, monospace">=A0 =A0 =A0 {</font></div></div><div><div><font class=3D"Ap= ple-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 =A0 =A0 =A0 w= riteln(&quot; =A0 in jane : inJane1()&quot;);</font></div> </div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#= 39;, monospace">=A0 =A0 =A0 }</font></div></div><div><div><font class=3D"Ap= ple-style-span" face=3D"&#39;courier new&#39;, monospace">=A0=A0</font></di= v></div><div><div> <font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">= =A0 =A0 public void inJane2()</font></div></div><div><div><font class=3D"Ap= ple-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 =A0 =A0 {</fo= nt></div></div> <div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, m= onospace">=A0 =A0 =A0 =A0 writeln(&quot; =A0 in jane : inJane2()&quot;);</f= ont></div></div><div><div><font class=3D"Apple-style-span" face=3D"&#39;cou= rier new&#39;, monospace">=A0 =A0 =A0 }</font></div> </div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#= 39;, monospace">=A0 }</font></div></div><div><div><font class=3D"Apple-styl= e-span" face=3D"&#39;courier new&#39;, monospace"><br></font></div></div><d= iv><div> <font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">= void main(string[] args)</font></div></div><div><div><font class=3D"Apple-s= tyle-span" face=3D"&#39;courier new&#39;, monospace">=A0 {</font></div></di= v><div> <div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp= ace">=A0 =A0 new Bob();</font></div></div><div><div><font class=3D"Apple-st= yle-span" face=3D"&#39;courier new&#39;, monospace">=A0 =A0 new Jane();</fo= nt></div></div> <div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, m= onospace">=A0 }</font></div></div></blockquote><div><br></div><div>The outp= ut is:</div><blockquote class=3D"webkit-indent-blockquote" style=3D"margin:= 0 0 0 40px; border: none; padding: 0px;"> <div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, m= onospace">$ rm -f dtest; dmd =A0 dtest.d variant.d =A0-ofdtest; ./dtest</fo= nt></div></div><div><div><font class=3D"Apple-style-span" face=3D"&#39;cour= ier new&#39;, monospace">RunAllIn: dtest.Bob</font></div> </div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#= 39;, monospace">=3D=3D i=3D2 =A0m=3DinBob1</font></div></div><div><div><fon= t class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 = =A0in bob : inBob1()</font></div> </div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#= 39;, monospace">=3D=3D i=3D3 =A0m=3DinBob2</font></div></div><div><div><fon= t class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 = =A0in bob : inBob2()</font></div> </div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#= 39;, monospace">RunAllIn: dtest.Jane</font></div></div><div><div><font clas= s=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">=3D=3D i= =3D1 =A0m=3DinJane1</font></div> </div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#= 39;, monospace">=A0 =A0in jane : inJane1()</font></div></div><div><div><fon= t class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">=3D= =3D i=3D2 =A0m=3DinJane2</font></div> </div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#= 39;, monospace">=A0 =A0in jane : inJane2()</font></div></div></blockquote><= div><br></div><div>Perfect, thanks Robert! Works like a charm.</div><div><b= r></div> --90e6ba6e89d6131b5704b0e2d354--
Nov 03 2011
prev sibling parent "Robert Jacques" <sandford jhu.edu> writes:
On Tue, 01 Nov 2011 14:42:42 -0400, J Arrizza <cppgent0 gmail.com> wrote:
 Robert,

 I tried using variant.d using your exact test program below and I got
 compiler errors:

 $ dmd  variant.d dtest.d
 variant.d(273): Error: no property 'length' for type 'Result'
 variant.d(273): Error: no property 'length' for type 'Result'
 variant.d(274): Error: no property 'length' for type 'Result'
 variant.d(274): Error: no property 'length' for type 'Result'
 variant.d(274): Error: no property 'length' for type 'Result'
 variant.d(275): Error: no property 'length' for type 'Result'
 variant.d(277): Error: no property 'length' for type 'Result'
 variant.d(277): Error: no property 'length' for type 'Result'
 variant.d(277): Error: no property 'length' for type 'Result'
 variant.d(277): Error: no property 'length' for type 'Result'
 variant.d(280): Error: no property 'length' for type 'Result'
 $ dmd -v
 DMD64 D Compiler v2.055

 Am I missing a switch or something?

 John

Nope, (hopefully) just patches. I maintain a list of the bugzilla patches (i.e. http://d.puremagic.com/issues/show_bug.cgi?id=5155) I've applied at the top of the file. But, mostly those are so DMD doesn't ICE; I've never seen this particular error before and am not sure how to interpret it. Hmm.. I don't use a Result type, but std.algoroithm does and one of the patches I always use is 6256 (http://d.puremagic.com/issues/show_bug.cgi?id=6256), which addresses length for Map.
Nov 07 2011