Re: kxml and dub package manager.

2015-10-19 Thread Mike Parker via Digitalmars-d-learn

On Monday, 19 October 2015 at 03:33:18 UTC, holo wrote:
ok i fugure out it. When i do initiation i need to add 
dependencies (thought it is enough to add them to sdl file). 
Proper initiation should look like that:


dub init projectname kxml


No, you should never need to do that. I think your problem might 
be related to the fact that in your dub.sdl you named your 
project "kxml". You shouldn't name a project the same as one of 
your dependencies.


Re: kxml - parsing AWS API xml respond

2015-10-19 Thread Kagamin via Digitalmars-d-learn
Select parent tags and get data from their child tags like 
instanceId.


Re: kxml - parsing AWS API xml respond

2015-10-19 Thread holo via Digitalmars-d-learn

On Monday, 19 October 2015 at 11:53:08 UTC, Kagamin wrote:

On Monday, 19 October 2015 at 04:49:25 UTC, holo wrote:

Why there is needed that "//" before tag?


That's an XPath expression.



Need, to read about that XPaths.


How to drop tags from respond? I have such result of parsing 
by id tag:


i-xx

I need only value. Is there some equivalent to ".text" from 
std.xml?


Try getCData 
https://github.com/opticron/kxml/blob/master/source/kxml/xml.d#L309



getCData is working like expected.

Thank you for tips.


Re: kxml - parsing AWS API xml respond

2015-10-19 Thread holo via Digitalmars-d-learn
Sorry i was trying to use that XPaths to take out instanceId and 
laounchTime but i always get an empty respond.


//instanceId/launchTime" - empty
//instanceId/*   - empty too
//instanceId.launchTime  - empty too

How to take instance id and variable which im interest in or 
few/all for instanceId?


Re: kxml - parsing AWS API xml respond

2015-10-19 Thread Kagamin via Digitalmars-d-learn

On Monday, 19 October 2015 at 04:49:25 UTC, holo wrote:

Why there is needed that "//" before tag?


That's an XPath expression.

How to drop tags from respond? I have such result of parsing by 
id tag:


i-xx

I need only value. Is there some equivalent to ".text" from 
std.xml?


Try getCData 
https://github.com/opticron/kxml/blob/master/source/kxml/xml.d#L309


Re: kxml and dub package manager.

2015-10-19 Thread holo via Digitalmars-d-learn

On Monday, 19 October 2015 at 06:20:19 UTC, Mike Parker wrote:

On Monday, 19 October 2015 at 03:33:18 UTC, holo wrote:
ok i fugure out it. When i do initiation i need to add 
dependencies (thought it is enough to add them to sdl file). 
Proper initiation should look like that:


dub init projectname kxml


No, you should never need to do that. I think your problem 
might be related to the fact that in your dub.sdl you named 
your project "kxml". You shouldn't name a project the same as 
one of your dependencies.


Tried too with different name as i came to same idea and created 
new one with other name. It was behaving that same, so it is not 
cause of problem.


Re: kxml - parsing AWS API xml respond

2015-10-19 Thread holo via Digitalmars-d-learn

On Monday, 19 October 2015 at 12:54:52 UTC, Kagamin wrote:
Select parent tags and get data from their child tags like 
instanceId.


void main()
{
string xmlstring = cast(string)read("test.xml");
XmlNode newdoc = xmlstring.readDocument();
XmlNode[]  searchlist = newdoc.parseXPath("//instanceId");
XmlNode[] searchlist2 = searchlist.parseXPath("//launchTime");
writeln(searchlist2);
}

Not working but probably its not what you thought, how to select 
it do you have some example?


Enough introspection to report variable name of calling argument

2015-10-19 Thread Handyman via Digitalmars-d-learn
Is the following possible in D?  To call a (unary) function f 
with variable a, and let f print:



Called with argument named 'a'.


I am of course asking for a generic solution, independent of the 
actual variable name (in this case, 'a').  I am aware that I am 
likely asking the impossible because of how the function call 
mechanism is implemented in most programming languages, hence in 
D.  Still, it might be possible given D's stong introspection 
capabilities / traits / pragma's / whathaveyou's.


Re: foreach loop

2015-10-19 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn

On Monday, 19 October 2015 at 14:28:06 UTC, Namal wrote:

Is it possible to create a foreach loop with a breakstetemen?

I mean something like that for the second loop where i want to 
break if element from:


int []  g = [9,15,21];
int [] v = [2,3,5,7,8,9,11,13,17,19];

foreach(j;1..10)
for(int i = 0; v[i]

Re: foreach loop

2015-10-19 Thread Rikki Cattermole via Digitalmars-d-learn

On 20/10/15 3:28 AM, Namal wrote:

Is it possible to create a foreach loop with a breakstetemen?

I mean something like that for the second loop where i want to break if
element from:

int []  g = [9,15,21];
int [] v = [2,3,5,7,8,9,11,13,17,19];

foreach(j;1..10)
for(int i = 0; v[i]

Check Instance of Template for Parameter Type/Value

2015-10-19 Thread Stewart Moth via Digitalmars-d-learn
I'm working with a library that has template structs of 
mathematical vectors that can sometimes be the type of an array 
I'm passing to a function.


The definition of the struct is like this:

struct Vector(type, int dimension_){ ... }

Where type is going to be an int/float/etc and dimension_ is 
2/3/4.


I could write a bunch of functions for each case, but I'd rather 
not... I'd like to use something like the following:


void foo(T)(Array!T array){
if(isInstanceOf!(Vector, T)){
//get type of T or check it
//test if dimension_ is 2 or 3 or 4
...
} else {
//Non-vector stuff
...
}
}

But to do that I need to check that parameters of T as if it were 
an instantiated instance of Vector and I'm not sure how to 
accomplish that... Can anyone help me out with what I need to do?


Re: Enough introspection to report variable name of calling argument

2015-10-19 Thread anonymous via Digitalmars-d-learn
On Monday, October 19, 2015 04:14 PM, Handyman wrote:

> Is the following possible in D?  To call a (unary) function f
> with variable a, and let f print:
> 
>> Called with argument named 'a'.
> 
> I am of course asking for a generic solution, independent of the
> actual variable name (in this case, 'a').  I am aware that I am
> likely asking the impossible because of how the function call
> mechanism is implemented in most programming languages, hence in
> D.  Still, it might be possible given D's stong introspection
> capabilities / traits / pragma's / whathaveyou's.

I think the exact thing you're asking for is not possible.

With slightly different syntax you can do this:

module test;
void f(alias v)()
{
import std.stdio: writeln;
import std.traits: fullyQualifiedName;
writeln(v.stringof, " ", fullyQualifiedName!v);
}

void main()
{
int a;
f!a(); /* prints "a test.main.a" */
}



Re: Check Instance of Template for Parameter Type/Value

2015-10-19 Thread anonymous via Digitalmars-d-learn
On Monday, October 19, 2015 04:51 PM, Stewart Moth wrote:

> struct Vector(type, int dimension_){ ... }
> 
> Where type is going to be an int/float/etc and dimension_ is
> 2/3/4.
> 
> I could write a bunch of functions for each case, but I'd rather
> not... I'd like to use something like the following:
> 
> void foo(T)(Array!T array){
>  if(isInstanceOf!(Vector, T)){
>  //get type of T or check it
>  //test if dimension_ is 2 or 3 or 4
>  ...
>  } else {
>  //Non-vector stuff
>  ...
>  }
> }
> 
> But to do that I need to check that parameters of T as if it were
> an instantiated instance of Vector and I'm not sure how to
> accomplish that... Can anyone help me out with what I need to do?

You can use std.traits.TemplateArgsOf:

static if(isInstanceOf!(Vector, T)){ /* note: must be a static if */
enum dimensions = TemplateArgsOf!T[1];
static if(dimensions == 2) {...}
}



foreach loop

2015-10-19 Thread Namal via Digitalmars-d-learn

Is it possible to create a foreach loop with a breakstetemen?

I mean something like that for the second loop where i want to 
break if element from:


int []  g = [9,15,21];
int [] v = [2,3,5,7,8,9,11,13,17,19];

foreach(j;1..10)
for(int i = 0; v[i]

Re: foreach loop

2015-10-19 Thread Daniel Kozak via Digitalmars-d-learn
V Mon, 19 Oct 2015 14:28:03 +
Namal via Digitalmars-d-learn 
napsáno:

> Is it possible to create a foreach loop with a breakstetemen?
> 
> I mean something like that for the second loop where i want to 
> break if element from:
> 
> int []  g = [9,15,21];
> int [] v = [2,3,5,7,8,9,11,13,17,19];
> 
> foreach(j;1..10)
> for(int i = 0; v[i]   do something;
> }

I am not sure what you exactly want, but you can break foreach
statement:

int []  g = [9,15,21];
int [] v = [2,3,5,7,8,9,11,13,17,19];

outerfor: foreach(j;1..10)
for(int i = 0; v[i]

Re: Check Instance of Template for Parameter Type/Value

2015-10-19 Thread Justin Whear via Digitalmars-d-learn
On Mon, 19 Oct 2015 14:51:28 +, Stewart Moth wrote:

> I'm working with a library that has template structs of mathematical
> vectors that can sometimes be the type of an array I'm passing to a
> function.
> 
> The definition of the struct is like this:
> 
> struct Vector(type, int dimension_){ ... }
> 
> Where type is going to be an int/float/etc and dimension_ is 2/3/4.
> 
> I could write a bunch of functions for each case, but I'd rather not...
> I'd like to use something like the following:
> 
> void foo(T)(Array!T array){
>  if(isInstanceOf!(Vector, T)){
>  //get type of T or check it //test if dimension_ is 2 or 3 or 4
>  ...
>  } else {
>  //Non-vector stuff ...
>  }
> }
> 
> But to do that I need to check that parameters of T as if it were an
> instantiated instance of Vector and I'm not sure how to accomplish
> that... Can anyone help me out with what I need to do?

Pattern matching!

void foo(ArrayT : Array!VectorT, VectorT : Vector!(T, dimension), T, int 
dimension)(ArrayT arr)
{
static if (dimension >= 2 && dimension <= 4)
{

} else {

}
}


Re: kxml - parsing AWS API xml respond

2015-10-19 Thread Kagamin via Digitalmars-d-learn

If you don't want parent tag, then:
XmlNode[] searchlist2 = newdoc.parseXPath("//launchTime");


Re: foreach loop

2015-10-19 Thread Namal via Digitalmars-d-learn
On Monday, 19 October 2015 at 14:43:04 UTC, Rikki Cattermole 
wrote:

On 20/10/15 3:28 AM, Namal wrote:

Is it possible to create a foreach loop with a breakstetemen?

I mean something like that for the second loop where i want to 
break if

element from:

int []  g = [9,15,21];
int [] v = [2,3,5,7,8,9,11,13,17,19];

foreach(j;1..10)
for(int i = 0; v[i]

Re: foreach loop

2015-10-19 Thread Namal via Digitalmars-d-learn

Is it possible to use foreach backwards?

foreach(int i;20..1)
 writeln(i);

compiles but I get nothing.



Re: std.algorithm.startsWith only predicate

2015-10-19 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 18 October 2015 at 21:44:57 UTC, Jonathan M Davis 
wrote:
startsWith doesn't have an overload that takes only a 
predicate. The existing overloads all require at least one 
"needle" to search for in the "haystack." An overload that 
doesn't require a needle could certainly be added, but there 
isn't one right now.


- Jonathan M Davis


https://github.com/D-Programming-Language/phobos/pull/3752


Re: kxml - parsing AWS API xml respond

2015-10-19 Thread holo via Digitalmars-d-learn

On Monday, 19 October 2015 at 16:12:56 UTC, Kagamin wrote:

If you don't want parent tag, then:
XmlNode[] searchlist2 = newdoc.parseXPath("//launchTime");


I wanted parent tag, i think. I almost figure out what i needed, 
but getCData stops working :/


void main()
{
string xmlstring = cast(string)read("test.xml");
XmlNode newdoc = xmlstring.readDocument();
XmlNode[]  searchlist = 
newdoc.parseXPath("//instancesSet/item");


foreach(list, searchlist)
{
string test = list.parseXPath("instanceId").getCData();
writeln(test);
}
}

[holo@ultraxps test]$ dub
Performing "debug" build using dmd for x86_64.
kxml 1.0.0: target for configuration "library" is up to date.
test ~master: building configuration "application"...
source/app.d(20,57): Error: no property 'getCData' for type 
'XmlNode[]'

dmd failed with exit code 1.
[holo@ultraxps test]$



Re: kxml - parsing AWS API xml respond

2015-10-19 Thread holo via Digitalmars-d-learn
I have no idea what i'm doing, but i did it (i just choose 1 
element of array):


void main()
{
string xmlstring = cast(string)read("test.xml");
XmlNode newdoc = xmlstring.readDocument();

XmlNode[]  searchlist = 
newdoc.parseXPath(`//instancesSet/item`);

foreach(list; searchlist)
{
string test1 = 
list.parseXPath(`//instanceId`)[0].getCData;


writeln(test1);
}

}

Is it really how it should looks like? Is there any better/more 
beautiful solution?


Re: foreach loop

2015-10-19 Thread novice2 via Digitalmars-d-learn

On Monday, 19 October 2015 at 15:56:00 UTC, Namal wrote:

Is it possible to use foreach backwards?



yes
http://dlang.org/statement.html#ForeachStatement
http://dpaste.dzfl.pl/cf847a9e1595


Re: foreach loop

2015-10-19 Thread Mike Parker via Digitalmars-d-learn

On Monday, 19 October 2015 at 15:56:00 UTC, Namal wrote:

Is it possible to use foreach backwards?

foreach(int i;20..1)
 writeln(i);

compiles but I get nothing.


foreach_reverse(i; 1 .. 20)
writeln(i);

Or:

import std.range : iota, retro;
foreach(i; iota(1, 20).retro)
writeln(i);

But if you really want the numbers 1 to 20, you should use 21 as 
the end value in both cases, as it's exclusive.