www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Variants array and IDK

reply g g <g g.com> writes:
IDK where to put this.

first thing:
Could it be a way to collapse Variants in std.variant?, like
Variant x = Variant(1)
Variant y = Variant([x,x,x,x])
//y could be simplified to Variant(int[]) instead of Variant(Variant(int)[])
//now it is not implemented (as far i know)

Also if want to know if using Variant  internally for a scripting language is
recommendable ( or acceptable)
I am facing the problem? writing my weird language (
https://github.com/zkp0s/Dw fell free to comment on it __not finished__)

Excuse me if I wrote in the wrong newsgroup. I didn't know where to put it,
.learn .D or .annouce ( Dw)

Thanks for reading
.
Jan 30 2011
next sibling parent "Nick Sabalausky" <a a.a> writes:
"g g" <g g.com> wrote in message news:ii5mtb$12qv$1 digitalmars.com...
 IDK where to put this.

 first thing:
 Could it be a way to collapse Variants in std.variant?, like
 Variant x = Variant(1)
 Variant y = Variant([x,x,x,x])
 //y could be simplified to Variant(int[]) instead of 
 Variant(Variant(int)[])
 //now it is not implemented (as far i know)

The problem with that is that x is only an int at runtime. It's the same problem as this: Variant x = Variant(1); int z = x; // ERROR: x might not be an int. You have to do it like this: Variant x = Variant(1); if(x.convertsTo!int()) { int z = x.coerce!int(); } else // Do something else Or you skip the "if(x.convertsTo!int())" part if you expect that x should always be an int. If it ever isn't an int then coerce will throw an exception. So if you want y to be Variant(int[]), you need to do: Variant x = Variant(1); if(x.convertsTo!int()) { auto xInt = x.coerce!int(); Variant y = Variant([xInt,xInt,xInt,xInt]); } else // Do something else
Jan 31 2011
prev sibling next sibling parent "Robert Jacques" <sandford jhu.edu> writes:
On Mon, 31 Jan 2011 02:04:11 -0500, g g <g g.com> wrote:

 IDK where to put this.

 first thing:
 Could it be a way to collapse Variants in std.variant?, like
 Variant x = Variant(1)
 Variant y = Variant([x,x,x,x])
 //y could be simplified to Variant(int[]) instead of  
 Variant(Variant(int)[])
 //now it is not implemented (as far i know)

 Also if want to know if using Variant  internally for a scripting  
 language is recommendable ( or acceptable)
 I am facing the problem? writing my weird language (  
 https://github.com/zkp0s/Dw fell free to comment on it __not finished__)

 Excuse me if I wrote in the wrong newsgroup. I didn't know where to put  
 it, .learn .D or .annouce ( Dw)

 Thanks for reading
 .

One of Variant's design goals is to be used for interfacing/implementing scripting languages. So, yes, I'd say it's both recommended and acceptable. In fact, I'd encourage you to post to the newsgroup or bugzilla any rough edges you run into with variant. I've been working on an update to it which fixes all current bugzilla issues and implements a runtime-reflection system. (https://jshare.johnshopkins.edu/rjacque2/public_html/variant.mht, https://jshare.johnshopkins.edu/rjacque2/public_html/variant.d)
Jan 31 2011
prev sibling parent "Robert Jacques" <sandford jhu.edu> writes:
On Mon, 31 Jan 2011 02:04:11 -0500, g g <g g.com> wrote:

 IDK where to put this.

 first thing:
 Could it be a way to collapse Variants in std.variant?, like
 Variant x = Variant(1)
 Variant y = Variant([x,x,x,x])
 //y could be simplified to Variant(int[]) instead of  
 Variant(Variant(int)[])
 //now it is not implemented (as far i know)

// Although this has to be true assert( y.type == typeid(Variant[]) ); // Should coerce support such lowering/conversions/collapses? i.e. int[] z = y.coerce!(int[])();
Jan 31 2011