Strict aliasing in D

2012-01-20 Thread Denis Shelomovskij
Is there a strict aliasing rule in D? I just saw https://bitbucket.org/goshawk/gdc/changeset/b44331053062

sameness

2012-01-20 Thread sclytrack
--- letters are different yet the same immutable(char) [] letter1; const(char) [] letter2; char [] letter3; void proc1( const(char) [] letter) {} --- letters

Re: sameness

2012-01-20 Thread bearophile
sclytrack: letters are different yet the same ... letters are different It's a Zen thing. Templates are very strict in the type you give them, while function arguments perform some silent type conversions. I think this will not change, because it's hard to design C++/D-style

Re: Reading web pages

2012-01-20 Thread Xan xan
Thanks for that. The standard library would include it. It will easy the things high level, please. For the other hand, how to specify the protocol? It's not the same http://foo than ftp://foo Thanks, Xan. 2012/1/20 Bystroushaak bystrou...@kitakitsune.org: You can always use my module:  

tdlp: higher-order functions

2012-01-20 Thread Jerome BENOIT
Hello List: In tDlp book in section 5.6 entitled `Higher-Order Functions. Function Literals, the first code example is: - T[] find(alias pred, T)(T[] input) if (is(typeof(pred(input[0])) == bool)) { for(;

Re: Reading web pages

2012-01-20 Thread Xan xan
I get errors: xan@gerret:~/yottium/@codi/aranya-d2.0$ gdmd-4.6 spider.d spider.o: In function `_Dmain': spider.d:(.text+0x4d): undefined reference to `_D11dhttpclient10HTTPClient7__ClassZ' spider.d:(.text+0x5a): undefined reference to

Re: Reading web pages

2012-01-20 Thread Bystroushaak
With dmd 2.057 on my linux machine: bystrousak:DHTTPClient,0$ dmd spider.d dhttpclient.d bystrousak:DHTTPClient,0$ ./spider http://kitakitsune.org [Contingut: !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd; HTML . On 20.1.2012 15:37, Xan

Re: Reading web pages

2012-01-20 Thread Xan xan
Yes. I ddi not know that I have to compile the two d files, although it has sense ;-) Perfect. On the other hand, I see dhttpclient identifies as Mozilla/5.0 (Windows; U; Windows NT 5.1; cs; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.13 How can I change that? 2012/1/20 Bystroushaak

Re: tdlp: higher-order functions

2012-01-20 Thread Alex Rønne Petersen
On 20-01-2012 15:32, Jerome BENOIT wrote: Hello List: In tDlp book in section 5.6 entitled `Higher-Order Functions. Function Literals, the first code example is: - T[] find(alias pred, T)(T[] input) if (is(typeof(pred(input[0]))

Re: Reading web pages

2012-01-20 Thread Bystroushaak
This module is very simple, only for HTTP protocol, but there is way how to add HTTPS: public void setTcpSocketCreator(TcpSocket function(string domain, ushort port) fn) You can add lambda function which return SSL socket, which will be called for every connection. FTP is not supported -

Re: tdlp: higher-order functions

2012-01-20 Thread Jerome BENOIT
Thanks. Let go further. On 20/01/12 15:58, Alex Rønne Petersen wrote: On 20-01-2012 15:32, Jerome BENOIT wrote: Hello List: In tDlp book in section 5.6 entitled `Higher-Order Functions. Function Literals, the first code example is:

Re: Passing arguments to a new thread

2012-01-20 Thread Timon Gehr
On 01/20/2012 03:12 PM, Mars wrote: Hello everybody. As the title states, I want to run a function in a new thread, and pass it some arguments. How would I do that? I guess I could make a class, deriving from Thread, and work with it, but out of curiosity, I'd like to know if it's possible with

Re: Reading web pages

2012-01-20 Thread Bystroushaak
First version was buggy. I've updated code at github, so if you want to try it, pull new version (git pull). I've also added new example into examples/user_agent_change.d On 20.1.2012 16:08, Bystroushaak wrote: There are two ways: Change global variable for module:

Re: tdlp: higher-order functions

2012-01-20 Thread Jerome BENOIT
Hello Again: On 20/01/12 15:58, Alex Rønne Petersen wrote: On 20-01-2012 15:32, Jerome BENOIT wrote: Hello List: In tDlp book in section 5.6 entitled `Higher-Order Functions. Function Literals, the first code example is: - T[]

Re: tdlp: higher-order functions

2012-01-20 Thread Alex Rønne Petersen
On 20-01-2012 17:14, Jerome BENOIT wrote: Hello Again: On 20/01/12 15:58, Alex Rønne Petersen wrote: On 20-01-2012 15:32, Jerome BENOIT wrote: Hello List: In tDlp book in section 5.6 entitled `Higher-Order Functions. Function Literals, the first code example is:

Re: Passing arguments to a new thread

2012-01-20 Thread Mars
On Friday, 20 January 2012 at 15:33:34 UTC, Timon Gehr wrote: On 01/20/2012 03:12 PM, Mars wrote: Hello everybody. As the title states, I want to run a function in a new thread, and pass it some arguments. How would I do that? I guess I could make a class, deriving from Thread, and work with

Re: tdlp: higher-order functions

2012-01-20 Thread Jerome BENOIT
On 20/01/12 17:23, Alex Rønne Petersen wrote: On 20-01-2012 17:14, Jerome BENOIT wrote: Hello Again: On 20/01/12 15:58, Alex Rønne Petersen wrote: On 20-01-2012 15:32, Jerome BENOIT wrote: Hello List: In tDlp book in section 5.6 entitled `Higher-Order Functions. Function Literals, the

Re: Reading web pages

2012-01-20 Thread Xan xan
Thank you very much, Bystroushaak. I see you limite httpclient to xml/html documents. Is there possibility of download any files (and not only html or xml). Just like: HTTPClient navegador = new HTTPClient(); auto file = navegador.download(http://www.google.com/myfile.pdf;) ? Thanks a lot,

Re: Reading web pages

2012-01-20 Thread Bystroushaak
It is unlimited, you just have to cast output to ubyte[]: std.file.write(logo3w.png, cast(ubyte[]) cl.get(http://www.google.cz/images/srpr/logo3w.png;)); On 20.1.2012 17:53, Xan xan wrote: Thank you very much, Bystroushaak. I see you limite httpclient to xml/html documents. Is there

Re: Reading web pages

2012-01-20 Thread Bystroushaak
If you want to know what type of file you just downloaded, look at .getResponseHeaders(): std.file.write(logo3w.png, cast(ubyte[]) cl.get(http://www.google.cz/images/srpr/logo3w.png;)); writeln(cl.getResponseHeaders()[Content-Type]); Which will print in this case: image/png Here is full

Re: Reading web pages

2012-01-20 Thread Xan xan
Thanks, but what fails that, because I downloaded as collection of bytes. No matter if a file is a pdf, png or whatever if I downloaded as bytes, isn't? Thanks, 2012/1/20 Bystroushaak bystrou...@kitakitsune.org: If you want to know what type of file you just downloaded, look at

Re: Reading web pages

2012-01-20 Thread Bystroushaak
Thats because you are trying writeln binary data, and that is impossible, because writeln IMHO checks UTF8 validity. On 20.1.2012 18:08, Xan xan wrote: Before and now, I get this error: $ ./spider http://static.arxiv.org/pdf/1109.4897.pdf [Excepció:

Re: Reading web pages

2012-01-20 Thread Bystroushaak
rawWrite(): stdout.rawWrite(cast(ubyte[]) navegador.get(a)); On 20.1.2012 18:18, Xan xan wrote: Mmmm... I understand it. But is there any way of circumvent it? Perhaps I could write to one file, isn't? 2012/1/20 Bystroushaakbystrou...@kitakitsune.org: Thats because you are trying writeln

Re: Reading web pages

2012-01-20 Thread Xan xan
Thank you very much. I should invite you to a beer ;-) For the other hand, I get this error: [Excepció: std.conv.ConvException@/usr/include/d2/4.6/std/conv.d(1640): Can't convert value `HTT' of type string to type uint] if I only want the length: //D 2.0 //gdmd-4.6 fitxer dhttpclient = surt

Merging two hashes

2012-01-20 Thread Andrej Mitrovic
Is there a way to merge the keys from one hash to another (overwriting any duplicates) without using a foreach loop? E.g.: void main() { int[int] a, b; a[0] = 0; b[1] = 1; b += a; // ? } It's not too hard to write this of course: foreach (key, val; a) b[key] = val;

Re: Reading web pages

2012-01-20 Thread Xan xan
The same error with: [...] foreach (a; args[1..$]) { |___|___|___|___write([Longitud: ); |___|___|___|___stdout.rawWrite(cast(ubyte[]) navegador.get(a)); |___|___|___|___writeln(]); |___|___|___} [...] 2012/1/20 Bystroushaak bystrou...@kitakitsune.org: rawWrite(): stdout.rawWrite(cast(ubyte[])

Re: Reading web pages

2012-01-20 Thread Bystroushaak
On 20.1.2012 18:42, Xan xan wrote: Thank you very much. I should invite you to a beer ;-) Write me if you will be in prag/czech republic :) For the other hand, I get this error: [Excepció: std.conv.ConvException@/usr/include/d2/4.6/std/conv.d(1640): Can't convert value `HTT' of type string

Re: Merging two hashes

2012-01-20 Thread Steven Schveighoffer
On Fri, 20 Jan 2012 12:46:40 -0500, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: Is there a way to merge the keys from one hash to another (overwriting any duplicates) without using a foreach loop? E.g.: void main() { int[int] a, b; a[0] = 0; b[1] = 1; b += a; // ? }

Re: tdlp: higher-order functions

2012-01-20 Thread Ali Çehreli
On 01/20/2012 08:43 AM, Jerome BENOIT wrote: - T[] find(alias pred, T)(T[] input) if (is(typeof(pred(input[0])) == bool)) { for(; input.length 0; input = input[1 .. $]) { if (pred(input[0])) break; } return input; }

Re: Changes for newer version...

2012-01-20 Thread Jesse Phillips
On Thursday, 19 January 2012 at 20:44:04 UTC, Era Scarecrow wrote: Been a bit out of it for a while, but finding enough tools at my disposal I feel I can work on/convert a project now. I happen to have one of the first printing books (without the name on the cover), and although it may be

Re: Merging two hashes

2012-01-20 Thread Andrej Mitrovic
Nice! On 1/20/12, Steven Schveighoffer schvei...@yahoo.com wrote: On Fri, 20 Jan 2012 12:46:40 -0500, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: Is there a way to merge the keys from one hash to another (overwriting any duplicates) without using a foreach loop? E.g.: void main() {

Re: Changes for newer version...

2012-01-20 Thread Timon Gehr
On 01/19/2012 09:30 PM, Era Scarecrow wrote: Been a bit out of it for a while, but finding enough tools at my disposal I feel I can work on/convert a project now. I happen to have one of the first printing books (without the name on the cover), and although it may be worth millions in a

Re: tdlp: higher-order functions

2012-01-20 Thread Tobias Pankrath
Philippe Sigaud's template document covers everything about templates: https://github.com/PhilippeSigaud/D-templates-tutorial (Just download the pdf there.) This should be on the website.

foreach with classes like associative array?

2012-01-20 Thread Matt Soucy
So I was messing around with some code I've been writing today, and I wanted to use a foreach for something, as if it were an associative array. The problem is, I can't find any information on how to do that. I can't use something like alias this, because the class I'm writing acts as a wrapper

Re: foreach with classes like associative array?

2012-01-20 Thread bearophile
Matt Soucy: I don't see any sort of opApply or similar to do this, and the foreach section of dlang.org doesn't help. Is there a way to do it? opApply sounds like the solution for your problem, if you don't need to define a Range. You are allowed to define two or more opApply with different

Re: foreach with classes like associative array?

2012-01-20 Thread Ali Çehreli
On 01/20/2012 04:53 PM, Matt Soucy wrote: So I was messing around with some code I've been writing today, and I wanted to use a foreach for something, as if it were an associative array. The problem is, I can't find any information on how to do that. I can't use something like alias this,