Re: Curl, how to recieve data.

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

On Sunday, 18 October 2015 at 20:12:42 UTC, sigod wrote:

On Sunday, 18 October 2015 at 20:05:24 UTC, holo wrote:

@sigod

Actually im working on ec2 requests. Thank you  for help, it 
is working right now. I don't know why i was trying "+=" 
before instead of "~=". Is it good solution to make it such 
way?


Not really as it will trigger allocation on every call. Better 
use [`Appender`][0].


[0]: http://dlang.org/phobos/std_array.html#.Appender


I changed it to such code:

...
auto client = HTTP(endpoint ~ "?" ~ 
canonicalQueryString);

client.method = HTTP.Method.get;
client.addRequestHeader("x-amz-date", xamztime);
client.addRequestHeader("Authorization", 
authorizationHeader);
client.onReceive = (ubyte[] 
data){receivedData.put(data); return data.length;};

client.perform();

return new Result(receivedData.data);
...
 auto receivedData = appender!string();
...

and it is really much more faster than it was - hope it is what 
you had on your mind.


Re: kxml and dub package manager.

2015-10-18 Thread drug via Digitalmars-d-learn

19.10.2015 02:57, holo пишет:

How to make dub to work for me?

Try
```
import kxml.xml; // instead of import kxml;
```



Re: Curl, how to recieve data.

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

@sigod

Actually im working on ec2 requests. Thank you  for help, it is 
working right now. I don't know why i was trying "+=" before 
instead of "~=". Is it good solution to make it such way?


@Suliaman

I need to collect information about my instances and put it to 
DB. I want to present those datas with with vibe.d, but collector 
want to make without too many dependencies (i was thinking to 
make it as separate thread but simplest solution will be just to 
use cron to run collector i think)


Re: OT: why do people use python when it is slow?

2015-10-18 Thread Mengu via Digitalmars-d-learn
On Sunday, 18 October 2015 at 13:29:50 UTC, Ola Fosheim Grøstad 
wrote:

On Sunday, 18 October 2015 at 12:50:43 UTC, Namespace wrote:
On Tuesday, 13 October 2015 at 23:26:14 UTC, Laeeth Isharc 
wrote:

https://www.quora.com/Why-is-Python-so-popular-despite-being-so-slow
Andrei suggested posting more widely.


Maybe also interesting: 
https://docs.google.com/presentation/d/1LO_WI3N-3p2Wp9PDWyv5B6EGFZ8XTOTNJ7Hd40WOUHo/mobilepresent?pli=1=id.g70b0035b2_1_168


What I got out of that is that someone at Mozilla were writing 
a push service (stateful connections, which more demanding than 
regular http) and found that jitted Python was more suitable 
than Go for productivity reasons. Then they speculate that 
their own Rust will be better suited than Go for such services 
in the future, apparently not yet.



To the poster further up in the thread: turns out that 
reddit.com is implemented in Python and a little bit of C: 
https://github.com/reddit/reddit


So there we have it. Python gives higher productive at the cost 
of efficiency, but does not have a significant impact on 
effectiveness, for regular web services that are built to scale.


that's the pylons guy. he also has many python libraries for web 
development. reddit is built with pylons btw and pylons is now 
pyramid.


i've seen the presentation and i can't stop thinking how it'd be 
if they had chosen D instead of Go.


Re: kxml and dub package manager.

2015-10-18 Thread holo via Digitalmars-d-learn
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


Re: OT: why do people use python when it is slow?

2015-10-18 Thread Ola Fosheim Grøstad via Digitalmars-d-learn

On Sunday, 18 October 2015 at 20:44:44 UTC, Mengu wrote:
i've seen the presentation and i can't stop thinking how it'd 
be if they had chosen D instead of Go.


Not much better, probably worse, given that Go has stack 
protection for fibers and D doesn't. So in Go you can get away 
with 2K growable stacks, in D you would need a lot more to stay 
on the safe side.


IIRC he claims that CPython would  fast enough for their 
application and that the application was memory limited and not 
computation limited.





Re: Curl, how to recieve data.

2015-10-18 Thread sigod via Digitalmars-d-learn

On Sunday, 18 October 2015 at 21:01:05 UTC, holo wrote:

On Sunday, 18 October 2015 at 20:12:42 UTC, sigod wrote:

[...]


I changed it to such code:

...
auto client = HTTP(endpoint ~ "?" ~ 
canonicalQueryString);

client.method = HTTP.Method.get;
client.addRequestHeader("x-amz-date", xamztime);
client.addRequestHeader("Authorization", 
authorizationHeader);
client.onReceive = (ubyte[] 
data){receivedData.put(data); return data.length;};

client.perform();

return new Result(receivedData.data);
...
 auto receivedData = appender!string();
...

and it is really much more faster than it was - hope it is what 
you had on your mind.


Yes, this is exactly what I meant.


Re: Curl, how to recieve data.

2015-10-18 Thread sigod via Digitalmars-d-learn

On Sunday, 18 October 2015 at 20:05:24 UTC, holo wrote:

@sigod

Actually im working on ec2 requests. Thank you  for help, it is 
working right now. I don't know why i was trying "+=" before 
instead of "~=". Is it good solution to make it such way?


Not really as it will trigger allocation on every call. Better 
use [`Appender`][0].


[0]: http://dlang.org/phobos/std_array.html#.Appender



Re: Curl, how to recieve data.

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

On Sunday, 18 October 2015 at 21:11:58 UTC, sigod wrote:

On Sunday, 18 October 2015 at 21:01:05 UTC, holo wrote:

On Sunday, 18 October 2015 at 20:12:42 UTC, sigod wrote:

[...]


I changed it to such code:

...
auto client = HTTP(endpoint ~ "?" ~ 
canonicalQueryString);

client.method = HTTP.Method.get;
client.addRequestHeader("x-amz-date", xamztime);
client.addRequestHeader("Authorization", 
authorizationHeader);
client.onReceive = (ubyte[] 
data){receivedData.put(data); return data.length;};

client.perform();

return new Result(receivedData.data);
...
 auto receivedData = appender!string();
...

and it is really much more faster than it was - hope it is 
what you had on your mind.


Yes, this is exactly what I meant.


Thank you for help.


Re: std.algorithm.startsWith only predicate

2015-10-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 18, 2015 17:48:18 Freddy via Digitalmars-d-learn wrote:
> How do you call startsWith with only a predicate
> ---
> import std.algorithm;
> import std.ascii;
>
> bool iden(string str)
> {
>  return str.startsWith!(a => a.isAlpha || a == '_');
> }
> ---

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



kxml and dub package manager.

2015-10-18 Thread holo via Digitalmars-d-learn
I want to add xml support to my application so i fetched kxml 
library with dub but it don't want to work for me. Steps and test 
code:


[holo@ultraxps kxml]$ cat dub.sdl
name "kxml"
description "A minimal D application."
copyright "Copyright © 2015, holo"
authors "holo"
dependencies "kxml" version="1.0.0"
[holo@ultraxps kxml]$ dub run
Performing "debug" build using dmd for x86_64.
kxml ~master: building configuration "application"...
source/app.d(1,8): Error: module kxml is in file 'kxml.d' which 
cannot be read

import path[0] = source/
import path[1] = /usr/include/dlang/dmd
dmd failed with exit code 1.
[holo@ultraxps kxml]$ cat source/app.d
import kxml;
import std.stdio;
import std.file;


struct instance
{
   string id;
   string name;
   string type;
   string state;
}


void main()
{

}

[holo@ultraxps kxml]$

How to make dub to work for me?


Re: kxml and dub package manager.

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

On Monday, 19 October 2015 at 03:04:28 UTC, drug wrote:

19.10.2015 02:57, holo пишет:

How to make dub to work for me?

Try
```
import kxml.xml; // instead of import kxml;
```


Same:

[holo@ultraxps kxml]$ dub run
Performing "debug" build using dmd for x86_64.
kxml ~master: building configuration "application"...
source/app.d(1,8): Error: module xml is in file 'kxml/xml.d' 
which cannot be read

import path[0] = source/
import path[1] = /usr/include/dlang/dmd
dmd failed with exit code 1.
[holo@ultraxps kxml]$


kxml - parsing AWS API xml respond

2015-10-18 Thread holo via Digitalmars-d-learn
I'm trying to take out from AWS respond needed information. Here 
is cut off part of example respond:


...
i-x
ami-x

16
running


ip-xxx.ec2.internal

ec2-xx.compute-1.amazonaws.com


ec2key
0





marketplace


c3.large

2015-08-18T16:51:11.000Z

...

With such code im getting only information about all instance ids:

string xmlstring = cast(string)read("test.xml");
XmlNode newdoc = xmlstring.readDocument();
XmlNode[]  searchlist = newdoc.parseXPath("//instanceId");
writeln(searchlist);

What i need is that to take out from there instance id and eg 
LaunchTime for that instance. How can i do it using kxml?


Why there is needed that "//" before tag? In other way im not 
getting any respond. What is interesting when i do that same with 
first tag appearing in respond it is not needed. From other hand 
with "///" i'm getting much more information but not separated by 
coma.


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?


Re: std.algorithm.startsWith only predicate

2015-10-18 Thread Freddy via Digitalmars-d-learn

On Sunday, 18 October 2015 at 17:58:30 UTC, Meta wrote:
Is this a simplified use case of some actual code you have? 
Otherwise, you can just do:



bool iden(string str)
{
auto f = str.front;
return f.isAlpha || f == '_';
}


It's simplified, i wanted to check for empty


Re: Curl, how to recieve data.

2015-10-18 Thread sigod via Digitalmars-d-learn

On Sunday, 18 October 2015 at 18:04:53 UTC, holo wrote:
I'm trying to receive data from curl request my sample code 
looks like that:


...
auto client = HTTP(endpoint ~ "?" ~ 
canonicalQueryString);

client.method = HTTP.Method.get;
client.addRequestHeader("x-amz-date", xamztime);
client.addRequestHeader("Authorization", 
authorizationHeader);

client.onReceive = (ubyte[] data)
{
recievedData = data;
return data.length;
};
client.perform();

return new Result(recievedData);
...

ubyte[] receivedData;

...

but im getting only last (like from "tail" command in unix 
systems) part of data which im expecting.


How to receive and save whole data which came as feedback for 
request? Or is there some other way to access it after usage of 
client.perform method?


I believe `onReceive` called multiple times with chunks of 
received data. So, you need to use `Appender` or `~`.


A bit off-topic:
Are you trying to download file from S3? It seems I should really 
start working on my S3 library...


Re: Curl, how to recieve data.

2015-10-18 Thread Suliman via Digitalmars-d-learn

On Sunday, 18 October 2015 at 18:04:53 UTC, holo wrote:
I'm trying to receive data from curl request my sample code 
looks like that:


...
auto client = HTTP(endpoint ~ "?" ~ 
canonicalQueryString);

client.method = HTTP.Method.get;
client.addRequestHeader("x-amz-date", xamztime);
client.addRequestHeader("Authorization", 
authorizationHeader);

client.onReceive = (ubyte[] data)
{
recievedData = data;
return data.length;
};
client.perform();

return new Result(recievedData);
...

ubyte[] receivedData;

...

but im getting only last (like from "tail" command in unix 
systems) part of data which im expecting.


How to receive and save whole data which came as feedback for 
request? Or is there some other way to access it after usage of 
client.perform method?


You also may try to look at 
http://vibed.org/api/vibe.http.client/requestHTTP

curl maybe a little bit hard in use.


[sdc] linker problems when building programs with sdc

2015-10-18 Thread Joseph Rushton Wakeling via Digitalmars-d-learn

Hello all,

I recently decided to have another play with sdc to see how it's doing.  Since 
my dmd is installed in /opt/dmd/ I had to do a couple of tricks to get sdc 
itself to build:


(i) put a dlang.conf in /etc/ld.so.conf.d/ containing the /opt/dmd/lib64 path;

(ii) call 'make LD_PATH=/opt/dmd/lib64' when building sdc

sdc itself then builds successfully, and I wind up with a bin/ directory 
containing sdc and sdc.conf (which contains includePath and libPath options) and 
a lib/ directory containing libd.a, libd-llvm.a, libphobos.a and libsdrt.a.


However, when I try to build any program, even a simple hello-world, I get a 
linker error:


$ ./sdc hello.d
hello.o: In function `_D5hello4mainFMZv':
hello.d:(.text+0x1c): undefined reference to `_D3std5stdio7writelnFMAyaZv'
collect2: error: ld returned 1 exit status

To solve this, I tried adding in a library-path flag, but this simply resulted 
in an exception being thrown by sdc's options parsing:


$ ./sdc -L$MYHOMEDIR/code/D/sdc/lib hello.d
std.getopt.GetOptException@/opt/dmd/bin/../import/std/getopt.d(604): 
Unrecognized option -L$MYHOMEDIR/code/D/sdc/lib


[cut great big backtrace]

Can anyone advise what's missing in my setup?  I did also try adding 
$MYHOMEDIR/code/D/sdc/lib to the /etc/ld.so.conf.d/dlang.conf file, and 
re-running ldconfig, but that didn't seem to make any difference.


Thanks & best wishes,

-- Joe


Re: OT: why do people use python when it is slow?

2015-10-18 Thread Namespace via Digitalmars-d-learn

On Tuesday, 13 October 2015 at 23:26:14 UTC, Laeeth Isharc wrote:

https://www.quora.com/Why-is-Python-so-popular-despite-being-so-slow
Andrei suggested posting more widely.


Maybe also interesting: 
https://docs.google.com/presentation/d/1LO_WI3N-3p2Wp9PDWyv5B6EGFZ8XTOTNJ7Hd40WOUHo/mobilepresent?pli=1=id.g70b0035b2_1_168


Re: OT: why do people use python when it is slow?

2015-10-18 Thread data pulverizer via Digitalmars-d-learn

On Thursday, 15 October 2015 at 21:16:18 UTC, Laeeth Isharc wrote:
On Wednesday, 14 October 2015 at 22:11:56 UTC, data pulverizer 
wrote:
On Tuesday, 13 October 2015 at 23:26:14 UTC, Laeeth Isharc 
wrote:

https://www.quora.com/Why-is-Python-so-popular-despite-being-so-slow
Andrei suggested posting more widely.


I am coming at D by way of R, C++, Python etc. so I speak as a 
statistician who is interested in data science applications.


Welcome...  Looks like we have similar interests.


That's good to know

To sit on the deployment side, D needs to grow it's big 
data/noSQL infrastructure for a start, then hook into a whole 
ecosystem of analytic tools in an easy and straightforward 
manner. This will take a lot of work!


Indeed.  The dlangscience project managed by John Colvin is 
very interesting.  It is not a pure stats project, but there 
will be many shared areas of need.  He has some v interesting 
ideas, and being able to mix Python and D in a Jupyter notebook 
is rather nice (you can do this already).


Thanks for bringing my attention to this, this looks interesting.

Sounds interesting.  Take a look at Colvin's dlang science 
draft white paper, and see what you would add.  It's a chance 
to shape things whilst they are still fluid.


Good suggestion.

3. Solid interface to a big data database, that allows a D 
data table <-> database easily


Which ones do you have in mind for stats?  The different 
choices seem to serve quite different needs.  And when you say 
big data, how big do you typically mean ?


What I mean is to start by tapping into current big data 
technologies. HDFS and Cassandra have C APIs which we can wrap 
for D.


4. Functional programming: especially around data table and 
array structures. R's apply(), lapply(), tapply(), plyr and 
now data.table(,, by = list()) provides powerful tools for 
data manipulation.


Any thoughts on what the design should look like?


Yes, I think this is easy to implement but still important. The 
real devil is my point #1 the dynamic data table object.




To an extent there is a balance between wanting to explore data 
iteratively (when you don't know where you will end up), and 
wanting to build a robust process for production.  I have been 
wondering myself about using LuaJIT to strap together D 
building blocks for the exploration (and calling it based on a 
custom console built around Adam Ruppe's terminal).


Sounds interesting

6. Nullable types makes talking about missing data more 
straightforward and gives you the opportunity to code them 
into a set value in your analysis. D is streaks ahead of 
Python here, but this is built into R at a basic level.


So matrices with nullable types within?  Is nan enough for you 
?  If not then could be quite expensive if back end is C.


I am not suggesting that we pass nullable matrices to C 
algorithms, yes nan is how this is done in practice but you 
wouldn't have nans in your matrix at the point of modeling - 
they'll just propagate and trash your answer. Nullable types are 
useful in data acquisition and exploration - the more practical 
side of data handling. I was quite shocked to see them in D, when 
they are essentially absent from "high level" programming 
languages like Python. Real data is messy and having nullable 
types is useful in processing, storing and summarizing raw data. 
I put in as #6 because I think it is possible to do practical 
statistics working around them by using notional hacks. Nullables 
are something that C#, and R have and Python's pandas has 
struggled with. The great news is that they are available in D so 
we can use them.




If D can get points 1, 2, 3 many people would be all over D 
because it is a fantastic programming language and is wicked 
fast.
What do you like best about it ?  And in your own domain, what 
have the biggest payoffs been in practice?


I am playing with D at the moment. To become useful to me the 
data table structure is a must. I previously said points 1, 2, 
and 3 would get data scientists sucked into D. But the data table 
structure is the seed. A dynamic structure like that in D would 
catalyze the rest. Everything else is either wrappers, routine 
and maybe a lot of work but straightforward to implement. The 
data table structure for me is the real enigma.


The way that R's data types are structured around SEXPs is the 
key to all of this. I am currently reading through R's internal 
documentation to get my head around this.


https://cran.r-project.org/doc/manuals/r-release/R-ints.html



Re: OT: why do people use python when it is slow?

2015-10-18 Thread Ola Fosheim Grøstad via Digitalmars-d-learn

On Sunday, 18 October 2015 at 12:50:43 UTC, Namespace wrote:
On Tuesday, 13 October 2015 at 23:26:14 UTC, Laeeth Isharc 
wrote:

https://www.quora.com/Why-is-Python-so-popular-despite-being-so-slow
Andrei suggested posting more widely.


Maybe also interesting: 
https://docs.google.com/presentation/d/1LO_WI3N-3p2Wp9PDWyv5B6EGFZ8XTOTNJ7Hd40WOUHo/mobilepresent?pli=1=id.g70b0035b2_1_168


What I got out of that is that someone at Mozilla were writing a 
push service (stateful connections, which more demanding than 
regular http) and found that jitted Python was more suitable than 
Go for productivity reasons. Then they speculate that their own 
Rust will be better suited than Go for such services in the 
future, apparently not yet.



To the poster further up in the thread: turns out that reddit.com 
is implemented in Python and a little bit of C: 
https://github.com/reddit/reddit


So there we have it. Python gives higher productive at the cost 
of efficiency, but does not have a significant impact on 
effectiveness, for regular web services that are built to scale.




Re: OT: why do people use python when it is slow?

2015-10-18 Thread Namespace via Digitalmars-d-learn
On Sunday, 18 October 2015 at 13:29:50 UTC, Ola Fosheim Grøstad 
wrote:

On Sunday, 18 October 2015 at 12:50:43 UTC, Namespace wrote:
On Tuesday, 13 October 2015 at 23:26:14 UTC, Laeeth Isharc 
wrote:

https://www.quora.com/Why-is-Python-so-popular-despite-being-so-slow
Andrei suggested posting more widely.


Maybe also interesting: 
https://docs.google.com/presentation/d/1LO_WI3N-3p2Wp9PDWyv5B6EGFZ8XTOTNJ7Hd40WOUHo/mobilepresent?pli=1=id.g70b0035b2_1_168


What I got out of that is that someone at Mozilla were writing 
a push service (stateful connections, which more demanding than 
regular http) and found that jitted Python was more suitable 
than Go for productivity reasons. Then they speculate that 
their own Rust will be better suited than Go for such services 
in the future, apparently not yet.
I liked the fact that Python with PyPy is more performant than Go 
(in contrast to the title "Python is slow") and that Go-Routines 
leak.




To the poster further up in the thread: turns out that 
reddit.com is implemented in Python and a little bit of C: 
https://github.com/reddit/reddit


So there we have it. Python gives higher productive at the cost 
of efficiency, but does not have a significant impact on 
effectiveness, for regular web services that are built to scale.





Re: Why does File.byLine() return char[] and not string

2015-10-18 Thread Suliman via Digitalmars-d-learn

On Friday, 16 October 2015 at 12:43:59 UTC, Meta wrote:
On Friday, 16 October 2015 at 10:38:52 UTC, Shriramana Sharma 
wrote:
Is there a particular reason that File.byLine() returns char[] 
and not string i.e. immutable(char)[]? Is it just to avoid 
being overly restrictive? It seems that having to .idup it is 
inefficient...


byLine reuses an internal buffer for each line which gets 
overwritten each iteration. The fact that it returns char 
instead of string is meant to signal this to the user, to tell 
them that the value they're getting back is mutable and subject 
to change.


Sorry, but could you explain more simply? I reread all 
information, bit can't understand about what buffer you are 
talking. And what is "signal"? How it's working?


Re: Why does File.byLine() return char[] and not string

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

what buffer you are talking.


internal buffer. where result line resides.



And what is "signal"? How it's working?


just the fact for programmer, that result line can be changed by 
other code (by phobos library code in this case).


no any special programming "signal".



Re: [sdc] linker problems when building programs with sdc

2015-10-18 Thread Marco Leise via Digitalmars-d-learn
Am Sun, 18 Oct 2015 11:35:16 +0200
schrieb Joseph Rushton Wakeling via Digitalmars-d-learn
:

> Hello all,
> 
> I recently decided to have another play with sdc to see how it's doing.  
> Since 
> my dmd is installed in /opt/dmd/ I had to do a couple of tricks to get sdc 
> itself to build:
> 
> (i) put a dlang.conf in /etc/ld.so.conf.d/ containing the /opt/dmd/lib64 path;
> 
> (ii) call 'make LD_PATH=/opt/dmd/lib64' when building sdc
> 
> sdc itself then builds successfully, and I wind up with a bin/ directory 
> containing sdc and sdc.conf (which contains includePath and libPath options) 
> and 
> a lib/ directory containing libd.a, libd-llvm.a, libphobos.a and libsdrt.a.
> 
> However, when I try to build any program, even a simple hello-world, I get a 
> linker error:
> 
> $ ./sdc hello.d
> hello.o: In function `_D5hello4mainFMZv':
> hello.d:(.text+0x1c): undefined reference to `_D3std5stdio7writelnFMAyaZv'
> collect2: error: ld returned 1 exit status
> 
> To solve this, I tried adding in a library-path flag, but this simply 
> resulted 
> in an exception being thrown by sdc's options parsing:
> 
> $ ./sdc -L$MYHOMEDIR/code/D/sdc/lib hello.d
> std.getopt.GetOptException@/opt/dmd/bin/../import/std/getopt.d(604): 
> Unrecognized option -L$MYHOMEDIR/code/D/sdc/lib
> 
> [cut great big backtrace]
> 
> Can anyone advise what's missing in my setup?  I did also try adding 
> $MYHOMEDIR/code/D/sdc/lib to the /etc/ld.so.conf.d/dlang.conf file, and 
> re-running ldconfig, but that didn't seem to make any difference.
> 
> Thanks & best wishes,
> 
>  -- Joe

Maybe you should have started with `return 42;`? :D
writeln is not a light-weight in terms of exercised compiler
features. I didn't even know that it compiles yet. Last time I
heard it was not usable.

-- 
Marco



Re: Why does File.byLine() return char[] and not string

2015-10-18 Thread Daniel Kozak via Digitalmars-d-learn
V Sun, 18 Oct 2015 15:51:13 +
Suliman via Digitalmars-d-learn 
napsáno:

> On Sunday, 18 October 2015 at 15:40:09 UTC, novice2 wrote:
> >> what buffer you are talking.  
> >
> > internal buffer. where result line resides.
> >
> >  
> >> And what is "signal"? How it's working?  
> >
> > just the fact for programmer, that result line can be changed 
> > by other code (by phobos library code in this case).
> >
> > no any special programming "signal".  
> 
> Am I right understand that byLine work like:
> read string, put it's to internal buffer, then read new line, 
> overwrite existent buffer etc...

Yes

> 
> byLineCopy is create range that storage all strings in format of 
> string, not char?
> 

byLineCopy is same as byLine, but do dup for each line

> What is size of this buffer, how it's calculate?

it is dynamic it depends on line length







Re: Why does File.byLine() return char[] and not string

2015-10-18 Thread Suliman via Digitalmars-d-learn

On Sunday, 18 October 2015 at 15:40:09 UTC, novice2 wrote:

what buffer you are talking.


internal buffer. where result line resides.



And what is "signal"? How it's working?


just the fact for programmer, that result line can be changed 
by other code (by phobos library code in this case).


no any special programming "signal".


Am I right understand that byLine work like:
read string, put it's to internal buffer, then read new line, 
overwrite existent buffer etc...


byLineCopy is create range that storage all strings in format of 
string, not char?


What is size of this buffer, how it's calculate?


Re: OT: why do people use python when it is slow?

2015-10-18 Thread Ola Fosheim Grøstad via Digitalmars-d-learn

On Sunday, 18 October 2015 at 13:57:40 UTC, Namespace wrote:
I liked the fact that Python with PyPy is more performant than 
Go (in contrast to the title "Python is slow") and that 
Go-Routines leak.


Yes, Python apparently used less memory, which is rather 
important when you write a service with persistent websocket 
connections, like a webchat or game. Old school stackless 
coroutines probably would be better than fibers like D and Go 
uses.


An alternative to writing such code for the application is to get 
persistent connections by "ready made" server-infrastructure 
(which probably is more reliable anyway). On AppEngine you have 
something called channels which basically allows you to send 
messages to a connected client push-style:


https://cloud.google.com/appengine/docs/python/channel/

As far as I can tell that means that the application server can 
die without loosing the connection.




Re: Why does File.byLine() return char[] and not string

2015-10-18 Thread Meta via Digitalmars-d-learn

On Sunday, 18 October 2015 at 15:03:22 UTC, Suliman wrote:
Sorry, but could you explain more simply? I reread all 
information, bit can't understand about what buffer you are 
talking.


This is more or less how byLine works, simplified:

struct ByLine
{
File file;
char[] line;
char[] buffer;
char terminator;

bool empty() { return line is null; }
char[] front() { return line; }

void popFront()
{
line = buffer;
file.readLine(line, terminator); //This overwrites the 
current contents of line

if (line.length > buffer.length)
{
buffer = line;
}

if (line.empty) line = null;
}
}

auto byLine(string fileName, char terminator = '\n')
{
return ByLine(File(fileName), terminator);
}



And what is "signal"? How it's working?


It's just an expression that means "to convey information". So 
when ByLine.front returns char[], a mutable array of char, it's 
meant to convey to the programmer that since the return value is 
mutable, it could change and they should make a copy.


std.algorithm.startsWith only predicate

2015-10-18 Thread Freddy via Digitalmars-d-learn

How do you call startsWith with only a predicate
---
import std.algorithm;
import std.ascii;

bool iden(string str)
{
return str.startsWith!(a => a.isAlpha || a == '_');
}
---


Re: std.algorithm.startsWith only predicate

2015-10-18 Thread Meta via Digitalmars-d-learn

On Sunday, 18 October 2015 at 17:48:20 UTC, Freddy wrote:

How do you call startsWith with only a predicate
---
import std.algorithm;
import std.ascii;

bool iden(string str)
{
return str.startsWith!(a => a.isAlpha || a == '_');
}
---


Is this a simplified use case of some actual code you have? 
Otherwise, you can just do:



bool iden(string str)
{
auto f = str.front;
return f.isAlpha || f == '_';
}


Curl, how to recieve data.

2015-10-18 Thread holo via Digitalmars-d-learn
I'm trying to receive data from curl request my sample code looks 
like that:


...
auto client = HTTP(endpoint ~ "?" ~ 
canonicalQueryString);

client.method = HTTP.Method.get;
client.addRequestHeader("x-amz-date", xamztime);
client.addRequestHeader("Authorization", 
authorizationHeader);

client.onReceive = (ubyte[] data)
{
recievedData = data;
return data.length;
};
client.perform();

return new Result(recievedData);
...

ubyte[] receivedData;

...

but im getting only last (like from "tail" command in unix 
systems) part of data which im expecting.


How to receive and save whole data which came as feedback for 
request? Or is there some other way to access it after usage of 
client.perform method?


Re: [sdc] linker problems when building programs with sdc

2015-10-18 Thread Joseph Rushton Wakeling via Digitalmars-d-learn

On 18/10/15 19:43, Marco Leise via Digitalmars-d-learn wrote:

Maybe you should have started with `return 42;`? :D
writeln is not a light-weight in terms of exercised compiler
features. I didn't even know that it compiles yet. Last time I
heard it was not usable.


Hahahahahahahaha :-D

Turns out even `return 42;` is a bit heavy-duty.  I do really like the way that 
sdc is obviously hooking into llvm's error reporting mechanism, though:


$ ./sdc nohello.d
; ModuleID = 'nohello.d'

define i32 @_Dmain() {
  br label %body

body: ; preds = %0
  call void @_D7nohello4mainFMZv()
  ret i32 0
}

define void @_D7nohello4mainFMZv() {

body: ; No predecessors!
}
nohello.d:3:4: error: d.ir.error.ErrorExpression is not supported
return 42;
^~
d.exception.CompileException@libd/src/d/exception.d(15): 
d.ir.error.ErrorExpression is not supported


./sdc(llvm.c.core.__LLVMOpaqueValue* 
util.visitor.dispatchImpl!(_D1d4llvm10expression13ExpressionGen5visitMFC1d2ir10expression10ExpressionZ14__funcliteral2FC1d2ir10expression10ExpressionZPS4llvm1c4core17__LLVMOpaqueValue, 
d.llvm.expression.ExpressionGen, d.ir.expression.Expression).dispatchImpl(ref 
d.llvm.expression.ExpressionGen, d.ir.expression.Expression)+0x538) [0x138fae0]
./sdc(llvm.c.core.__LLVMOpaqueValue* 
util.visitor.dispatch!(_D1d4llvm10expression13ExpressionGen5visitMFC1d2ir10expression10ExpressionZ14__funcliteral2FC1d2ir10expression10ExpressionZPS4llvm1c4core17__LLVMOpaqueValue, 
d.llvm.expression.ExpressionGen, d.ir.expression.Expression).dispatch(ref 
d.llvm.expression.ExpressionGen, d.ir.expression.Expression)+0x1d) [0x138f5a5]
./sdc(llvm.c.core.__LLVMOpaqueValue* 
d.llvm.expression.ExpressionGen.visit(d.ir.expression.Expression)+0x55) [0x137ec55]
./sdc(llvm.c.core.__LLVMOpaqueValue* 
d.llvm.statement.StatementGen.genExpression(d.ir.expression.Expression)+0x3f) 
[0x138a627]
./sdc(void 
d.llvm.statement.StatementGen.visit(d.ast.statement.ReturnStatement!(d.ir.expression.Expression, 
d.ir.statement.Statement).ReturnStatement)+0x75) [0x138b1bd]
./sdc(void 
util.visitor.__T12dispatchImplS294util7visitor14__funcliteral6TS1d4llvm9statement12StatementGenTC1d2ir9statement9StatementZ.dispatchImpl(ref 
d.llvm.statement.StatementGen, d.ir.statement.Statement)+0x274) [0x13907ac]
./sdc(void 
util.visitor.__T8dispatchS294util7visitor14__funcliteral6TS1d4llvm9statement12StatementGenTC1d2ir9statement9StatementZ.dispatch(ref 
d.llvm.statement.StatementGen, d.ir.statement.Statement)+0x1d) [0x1390535]
./sdc(void d.llvm.statement.StatementGen.visit(d.ir.statement.Statement)+0x55) 
[0x138a4ad]
./sdc(void 
d.llvm.statement.StatementGen.visit(d.ast.statement.BlockStatement!(d.ir.statement.Statement).BlockStatement)+0xc2) 
[0x138ad3a]
./sdc(void d.llvm.local.LocalGen.genBody(d.ir.symbol.Function, 
llvm.c.core.__LLVMOpaqueValue*)+0xbb8) [0x1388730]
./sdc(bool d.llvm.local.LocalGen.maybeDefine(d.ir.symbol.Function, 
llvm.c.core.__LLVMOpaqueValue*)+0x10e) [0x1387b56]
./sdc(llvm.c.core.__LLVMOpaqueValue* 
d.llvm.local.LocalGen.define(d.ir.symbol.Function)+0x8e) [0x138798e]
./sdc(llvm.c.core.__LLVMOpaqueValue* 
d.llvm.global.GlobalGen.define(d.ir.symbol.Function)+0x15b) [0x13860cb]

./sdc(void d.llvm.global.GlobalGen.define(d.ir.symbol.Symbol)+0xd0) [0x1385db8]
./sdc(d.ir.symbol.Module 
d.llvm.codegen.CodeGenPass.visit(d.ir.symbol.Module)+0xe2) [0x132c0f2]
./sdc(void d.llvm.backend.LLVMBackend.emitObject(d.ir.symbol.Module[], 
immutable(char)[])+0xd1) [0x1328c79]

./sdc(void sdc.sdc.SDC.codeGen(immutable(char)[])+0x87) [0x12c7d17]
./sdc(void sdc.sdc.SDC.codeGen(immutable(char)[], immutable(char)[])+0x74) 
[0x12c7d94]

./sdc(_Dmain+0x59a) [0x12be462]
/opt/dmd/lib64/libphobos2.so.0.68(_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv+0x28) 
[0x7f7c02d54ee8]
/opt/dmd/lib64/libphobos2.so.0.68(void rt.dmain2._d_run_main(int, char**, extern 
(C) int function(char[][])*).tryExec(scope void delegate())+0x2d) [0x7f7c02d54e2d]
/opt/dmd/lib64/libphobos2.so.0.68(void rt.dmain2._d_run_main(int, char**, extern 
(C) int function(char[][])*).runAll()+0x2d) [0x7f7c02d54e8d]
/opt/dmd/lib64/libphobos2.so.0.68(void rt.dmain2._d_run_main(int, char**, extern 
(C) int function(char[][])*).tryExec(scope void delegate())+0x2d) [0x7f7c02d54e2d]

/opt/dmd/lib64/libphobos2.so.0.68(_d_run_main+0x1e7) [0x7f7c02d54da7]
./sdc(main+0x20) [0x12c7708]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7f7c0173fa40]