how to access a ftp sever with socket
Hello Anyone: i am trying make a ftp client with socket,i have tried std.net.curl,but i cont stand with so many try-catch structure in my code,i am not familiar with socket,i write a pecie of code but it cont give me the welcome message which i want,and then i use wireshark to trace the comunication,i found that ftp server:21 send the message to my client:1024,but why there is nothing in str buf?thanks for your help. import std.socket,std.stdio; void main(){ string ip = **;//i hide the address int msecs = 1000; auto ftp = getAddressInfo(ip,ftp); Socket listener = new TcpSocket; listener.bind(new InternetAddress(1024)); listener.connect(ftp[0].address); auto pair = socketPair(); auto sock = pair[0]; sock.setOption(SocketOptionLevel.SOCKET,SocketOption.RCVTIMEO, dur!msecs(msecs)); char[1024] buf; sock.receive(buf); writeln(buf); }
Re: how to access a ftp sever with socket
On Mon, 8 Dec 2014 17:16:23 +0800 (CST) michael via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Hello Anyone: i am trying make a ftp client with socket,i have tried std.net.curl,but i cont stand with so many try-catch structure in my code,i am not familiar with socket,i write a pecie of code but it cont give me the welcome message which i want,and then i use wireshark to trace the comunication,i found that ftp server:21 send the message to my client:1024,but why there is nothing in str buf?thanks for your help. import std.socket,std.stdio; void main(){ string ip = **;//i hide the address int msecs = 1000; auto ftp = getAddressInfo(ip,ftp); Socket listener = new TcpSocket; listener.bind(new InternetAddress(1024)); listener.connect(ftp[0].address); auto pair = socketPair(); auto sock = pair[0]; sock.setOption(SocketOptionLevel.SOCKET,SocketOption.RCVTIMEO, dur!msecs(msecs)); char[1024] buf; sock.receive(buf); writeln(buf); } that is not how it all works. you need to learn network programming with sockets first, it is not D-specific. for now it looks like you are trying random things in a hope that it will magically works. signature.asc Description: PGP signature
Derelict / SDL error
Sorry this is a bit off topic but as there doesn't seem to be an active forum for Derelict atm This simple test code is giving me an error 'Error executing command run: Program exited with code -11' (or a seg fault if executed from a terminal). The problem line is: SDL_RenderCopy(renderer, texture, sourceRect, destRect); I've tried this call with the 'null' options as well as passing the address of the rects but neither works (I've also tried manually assigning the various struct components rather than using the c style initialisation in case that was the problem). Any ideas please? import derelict.sdl2.sdl; import std.stdio; void main() { scope(exit) SDL_Quit(); DerelictSDL2.load(); writeln( SDL loaded ok); //init sdl if (SDL_Init(SDL_INIT_EVERYTHING) != 0){ writeln(SDL_Init Error: , SDL_GetError() ); return; } //open a window SDL_Window *window = SDL_CreateWindow(Window Title!, 100, 100, 640, 480, SDL_WINDOW_SHOWN); if (window == null){ writeln(SDL_CreateWindow Error: , SDL_GetError() ); return; } //get a renderer (ie buffer), use software renderer for now SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE); if (renderer == null){ writeln( SDL_CreateRenderer Error: , SDL_GetError() ); return; } //load a bitmap SDL_Surface *image = SDL_LoadBMP(./test.bmp); if (image == null){ writeln( SDL_LoadBMP error: , SDL_GetError() ); return; } //create texture for bitmap SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, image); if (texture == null){ writeln( CreateTextureFromSurface error: , SDL_GetError() ); return; } //copy to renderer at correct position scale SDL_Rect sourceRect = { 0, 0, 64, 64 }; SDL_Rect destRect = { 100, 100, 64, 64 }; SDL_RenderCopy(renderer, texture, sourceRect, destRect); //display and pause SDL_RenderPresent(renderer); SDL_Delay(2000); }
Re: Derelict / SDL error
On Mon, 08 Dec 2014 12:53:10 + Paul via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Sorry this is a bit off topic but as there doesn't seem to be an active forum for Derelict atm This simple test code is giving me an error 'Error executing command run: Program exited with code -11' (or a seg fault if executed from a terminal). The problem line is: SDL_RenderCopy(renderer, texture, sourceRect, destRect); I've tried this call with the 'null' options as well as passing the address of the rects but neither works (I've also tried manually assigning the various struct components rather than using the c style initialisation in case that was the problem). Any ideas please? import derelict.sdl2.sdl; import std.stdio; void main() { scope(exit) SDL_Quit(); DerelictSDL2.load(); writeln( SDL loaded ok); //init sdl if (SDL_Init(SDL_INIT_EVERYTHING) != 0){ writeln(SDL_Init Error: , SDL_GetError() ); return; } //open a window SDL_Window *window = SDL_CreateWindow(Window Title!, 100, 100, 640, 480, SDL_WINDOW_SHOWN); if (window == null){ writeln(SDL_CreateWindow Error: , SDL_GetError() ); return; } //get a renderer (ie buffer), use software renderer for now SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE); if (renderer == null){ writeln( SDL_CreateRenderer Error: , SDL_GetError() ); return; } //load a bitmap SDL_Surface *image = SDL_LoadBMP(./test.bmp); if (image == null){ writeln( SDL_LoadBMP error: , SDL_GetError() ); return; } //create texture for bitmap SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, image); if (texture == null){ writeln( CreateTextureFromSurface error: , SDL_GetError() ); return; } //copy to renderer at correct position scale SDL_Rect sourceRect = { 0, 0, 64, 64 }; SDL_Rect destRect = { 100, 100, 64, 64 }; SDL_RenderCopy(renderer, texture, sourceRect, destRect); //display and pause SDL_RenderPresent(renderer); SDL_Delay(2000); } this exact code is working for me. i just copypasted it and gave it test.bmp to work with. signature.asc Description: PGP signature
Re: Derelict / SDL error
On Monday, 8 December 2014 at 13:08:58 UTC, ketmar via Digitalmars-d-learn wrote: On Mon, 08 Dec 2014 12:53:10 + Paul via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Sorry this is a bit off topic but as there doesn't seem to be an active forum for Derelict atm This simple test code is giving me an error 'Error executing command run: Program exited with code -11' (or a seg fault if executed from a terminal). The problem line is: SDL_RenderCopy(renderer, texture, sourceRect, destRect); I've tried this call with the 'null' options as well as passing the address of the rects but neither works (I've also tried manually assigning the various struct components rather than using the c style initialisation in case that was the problem). Any ideas please? this exact code is working for me. i just copypasted it and gave it test.bmp to work with. Thanks for testing, must be something on my system then... I've no idea where to start looking for the problem though :(
Re: Derelict / SDL error
On Mon, 08 Dec 2014 13:16:37 + Paul via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Monday, 8 December 2014 at 13:08:58 UTC, ketmar via Digitalmars-d-learn wrote: On Mon, 08 Dec 2014 12:53:10 + Paul via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Sorry this is a bit off topic but as there doesn't seem to be an active forum for Derelict atm This simple test code is giving me an error 'Error executing command run: Program exited with code -11' (or a seg fault if executed from a terminal). The problem line is: SDL_RenderCopy(renderer, texture, sourceRect, destRect); I've tried this call with the 'null' options as well as passing the address of the rects but neither works (I've also tried manually assigning the various struct components rather than using the c style initialisation in case that was the problem). Any ideas please? this exact code is working for me. i just copypasted it and gave it test.bmp to work with. Thanks for testing, must be something on my system then... I've no idea where to start looking for the problem though :( i must admit that i'm on 32-bit GNU/Linux, so i can't say anything about 64-bit and/or non-GNU/Linux OSes. signature.asc Description: PGP signature
Re: Sorted Array Wrapper Range
On Sunday, 7 December 2014 at 13:12:06 UTC, Tobias Pankrath wrote: Something like this https://github.com/Panke/phobos/blob/std_container_sorted/std/container/sorted.d It should additionally support c.remove(r), c.removeKey(k), opIn and insertFront/removeFront if the underlying store supports them. But that's pretty much it, I'd say. Sadly, the unittest using an Array!int as store does not compile because of of linker errors. I'm using rdmd -unittest -main std/container/sorted.d but that does not work with std/container/array.d as well. So, my setup seems to be broken. Thanks! I don't get any linker errors using dmd git master. I'll try 2.066 later on. I'll do some polishing :)
Re: Derelict / SDL error
On Monday, 8 December 2014 at 13:23:12 UTC, ketmar via Digitalmars-d-learn wrote: On Mon, 08 Dec 2014 13:16:37 + Paul via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Monday, 8 December 2014 at 13:08:58 UTC, ketmar via Digitalmars-d-learn wrote: On Mon, 08 Dec 2014 12:53:10 + Paul via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Sorry this is a bit off topic but as there doesn't seem to be an active forum for Derelict atm This simple test code is giving me an error 'Error executing command run: Program exited with code -11' (or a seg fault if executed from a terminal). The problem line is: SDL_RenderCopy(renderer, texture, sourceRect, destRect); I've tried this call with the 'null' options as well as passing the address of the rects but neither works (I've also tried manually assigning the various struct components rather than using the c style initialisation in case that was the problem). Any ideas please? this exact code is working for me. i just copypasted it and gave it test.bmp to work with. Thanks for testing, must be something on my system then... I've no idea where to start looking for the problem though :( i must admit that i'm on 32-bit GNU/Linux, so i can't say anything about 64-bit and/or non-GNU/Linux OSes. I added this around the problem line to catch the problem: try{ SDL_RenderCopy(renderer, texture, sourceRect, destRect); } catch{} finally { writeln( Error: , SDL_GetError() ); } The program now works from a terminal as expected (!) BUT when SDL_RenderCopy is called SDL_GetError() shows an 'error code' (or just some address/value as it is different each time).
Re: Derelict / SDL error
On Mon, 08 Dec 2014 13:37:20 + Paul via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: The program now works from a terminal as expected (!) BUT when SDL_RenderCopy is called SDL_GetError() shows an 'error code' (or just some address/value as it is different each time). FYI: SDL_GetError() returns 'char*', not string. you can print error message with this code, for example: private void sdl_print_error () @trusted nothrow @nogc { import core.stdc.stdio : stderr, fprintf; auto sdl_error = SDL_GetError(); fprintf(stderr, SDL ERROR: %s\n, sdl_error); } besides, i don't think that you'll get something sane from `SDL_GetError()` in the case of segfault. signature.asc Description: PGP signature
Re: Derelict / SDL error
On 12/8/2014 10:37 PM, Paul wrote: I added this around the problem line to catch the problem: try{ SDL_RenderCopy(renderer, texture, sourceRect, destRect); } catch{} finally { writeln( Error: , SDL_GetError() ); } The program now works from a terminal as expected (!) BUT when SDL_RenderCopy is called SDL_GetError() shows an 'error code' (or just some address/value as it is different each time). import std.conv : to; writeln( Error: , to!string( SDL_GetError() ));
Re: Delegate returning itself
On Saturday, 6 December 2014 at 15:46:16 UTC, Adam D. Ruppe wrote: The problem is the recursive *alias* rather than the delegate. Just don't use the alias name inside itself so like alias MyDelegate = void delegate() delegate(); will work. The first void delegate() is the return value of the MyDelegate type. Yes I tried that as well. It still doesn't solve the issue. The delegate being returned doesn't return a delegate, it returns the void type. You would need to write delegate() delegate() delegate() delegate() ...FOREVER. I can't figure out a way to write this in the language even though the machine code it generates should be quite trivial.
Re: Derelict / SDL error
On Monday, 8 December 2014 at 13:48:27 UTC, Mike Parker wrote: import std.conv : to; writeln( Error: , to!string( SDL_GetError() )); Cleaner! Any ideas where to look for the source of the problem?
Re: Derelict / SDL error
On Monday, 8 December 2014 at 13:47:47 UTC, ketmar via Digitalmars-d-learn wrote: On Mon, 08 Dec 2014 13:37:20 + Paul via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: besides, i don't think that you'll get something sane from `SDL_GetError()` in the case of segfault. Your're right, no help at all. I should also have checked that when I forced errors the SDL error messages were being displayed (which they weren't of course). That'll teach me to play while at work ;)
Re: Delegate returning itself
On Monday, 8 December 2014 at 14:08:33 UTC, Jonathan Marler wrote: On Saturday, 6 December 2014 at 15:46:16 UTC, Adam D. Ruppe wrote: The problem is the recursive *alias* rather than the delegate. Just don't use the alias name inside itself so like alias MyDelegate = void delegate() delegate(); will work. The first void delegate() is the return value of the MyDelegate type. Yes I tried that as well. It still doesn't solve the issue. The delegate being returned doesn't return a delegate, it returns the void type. You would need to write delegate() delegate() delegate() delegate() ...FOREVER. I can't figure out a way to write this in the language even though the machine code it generates should be quite trivial. I did some digging and realized that C/C++ have the same problem. I found a nice post on it with 2 potential solutions (http://c-faq.com/decl/recurfuncp.html). I liked the second solution so I wrote up an example in D. If anyone has any other ideas or can think of a way to improve my example feel free to post and let me know, thanks.import std.stdio; struct StateFunc { StateFunc function() func; } StateFunc state1() { writeln(state1); return StateFunc(state2); } StateFunc state2() { writeln(state2); return StateFunc(state3); } StateFunc state3() { writeln(state3); return StateFunc(null); } void main(string[] args) { StateFunc state = StateFunc(state1); while(state.func != null) { state = state.func(); } }
Re: Derelict / SDL error
On Mon, 08 Dec 2014 14:13:54 + Paul via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Monday, 8 December 2014 at 13:48:27 UTC, Mike Parker wrote: import std.conv : to; writeln( Error: , to!string( SDL_GetError() )); Cleaner! ah, sure. i just wanted to use libc's fprintf() to avoid importing std.stdio, so copy-pasted that code. but you get the idea anyway. ;-) Any ideas where to look for the source of the problem? sorry, no. you can try to update SDL2 to the latest version and Derelict bindings to git head though. i don't think that this will help, but you at least be sure that the problem is not in some obsolete version of the code. signature.asc Description: PGP signature
Re: Delegate returning itself
On Monday, 8 December 2014 at 14:31:53 UTC, Jonathan Marler wrote: On Monday, 8 December 2014 at 14:08:33 UTC, Jonathan Marler wrote: On Saturday, 6 December 2014 at 15:46:16 UTC, Adam D. Ruppe wrote: The problem is the recursive *alias* rather than the delegate. Just don't use the alias name inside itself so like alias MyDelegate = void delegate() delegate(); will work. The first void delegate() is the return value of the MyDelegate type. Yes I tried that as well. It still doesn't solve the issue. The delegate being returned doesn't return a delegate, it returns the void type. You would need to write delegate() delegate() delegate() delegate() ...FOREVER. I can't figure out a way to write this in the language even though the machine code it generates should be quite trivial. I did some digging and realized that C/C++ have the same problem. I found a nice post on it with 2 potential solutions (http://c-faq.com/decl/recurfuncp.html). I liked the second solution so I wrote up an example in D. If anyone has any other ideas or can think of a way to improve my example feel free to post and let me know, thanks.import std.stdio; struct StateFunc { StateFunc function() func; } StateFunc state1() { writeln(state1); return StateFunc(state2); } StateFunc state2() { writeln(state2); return StateFunc(state3); } StateFunc state3() { writeln(state3); return StateFunc(null); } void main(string[] args) { StateFunc state = StateFunc(state1); while(state.func != null) { state = state.func(); } } Nice! Using alias this, you can call the struct directly: struct StateFunc { StateFunc function() func; alias func this; } state = state(); Now there still needs to be a way to just `return state2;` instead of `return StateFunc(state2);`...
Re: Accented Characters and Counting Syllables
On Sunday, 7 December 2014 at 15:47:45 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Ok, thanks. I just noticed that byGrapheme() lacks bidirectional access. Further it also lacks graphemeStrideBack() in complement to graphemeStride()? Similar to stride() and strideBack(). Is this difficult to implement? Not sure, but I wouldn't be surprised if it is. Unicode algorithms are generally non-trivial. T What's the best source of information for these algorithms? Is it certain that graphemes iteration is backwards iteratable by definition?
Re: Derelict / SDL error
On Monday, 8 December 2014 at 14:35:17 UTC, ketmar via Digitalmars-d-learn wrote: On Mon, 08 Dec 2014 14:13:54 + Paul via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Monday, 8 December 2014 at 13:48:27 UTC, Mike Parker wrote: import std.conv : to; writeln( Error: , to!string( SDL_GetError() )); Cleaner! ah, sure. i just wanted to use libc's fprintf() to avoid importing std.stdio, so copy-pasted that code. but you get the idea anyway. ;-) Any ideas where to look for the source of the problem? sorry, no. you can try to update SDL2 to the latest version and Derelict bindings to git head though. i don't think that this will help, but you at least be sure that the problem is not in some obsolete version of the code. I've only just installed SDL/Derelict on this machine so it should be up to date. I'll keep digging...
Re: Accented Characters and Counting Syllables
On Monday, 8 December 2014 at 14:57:06 UTC, Nordlöw wrote: What's the best source of information for these algorithms? Is it certain that graphemes iteration is backwards iteratable by definition? I guess https://en.wikipedia.org/wiki/Combining_character could be a good start.
Re: Sorted Array Wrapper Range
On Monday, 8 December 2014 at 13:34:33 UTC, Nordlöw wrote: On Sunday, 7 December 2014 at 13:12:06 UTC, Tobias Pankrath wrote: Something like this https://github.com/Panke/phobos/blob/std_container_sorted/std/container/sorted.d It should additionally support c.remove(r), c.removeKey(k), opIn and insertFront/removeFront if the underlying store supports them. But that's pretty much it, I'd say. Sadly, the unittest using an Array!int as store does not compile because of of linker errors. I'm using rdmd -unittest -main std/container/sorted.d but that does not work with std/container/array.d as well. So, my setup seems to be broken. Thanks! I don't get any linker errors using dmd git master. I'll try 2.066 later on. I'll do some polishing :) Was my fault. The phobos checkout didn't match my dmd version. Here is my current state (has some more unittest, bugs fixed, no assignment via SortedRange views on Sorted.): https://github.com/Panke/phobos/blob/sorted/std/container/sorted.d
Re: Derelict / SDL error
On Monday, 8 December 2014 at 12:53:11 UTC, Paul wrote: Sorry this is a bit off topic but as there doesn't seem to be an active forum for Derelict atm This simple test code is giving me an error 'Error executing command run: Program exited with code -11' (or a seg fault if executed from a terminal). The problem line is: SDL_RenderCopy(renderer, texture, sourceRect, destRect); I've tried this call with the 'null' options as well as passing the address of the rects but neither works (I've also tried manually assigning the various struct components rather than using the c style initialisation in case that was the problem). Any ideas please? import derelict.sdl2.sdl; import std.stdio; void main() { scope(exit) SDL_Quit(); DerelictSDL2.load(); writeln( SDL loaded ok); //init sdl if (SDL_Init(SDL_INIT_EVERYTHING) != 0){ writeln(SDL_Init Error: , SDL_GetError() ); return; } //open a window SDL_Window *window = SDL_CreateWindow(Window Title!, 100, 100, 640, 480, SDL_WINDOW_SHOWN); if (window == null){ writeln(SDL_CreateWindow Error: , SDL_GetError() ); return; } //get a renderer (ie buffer), use software renderer for now SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE); if (renderer == null){ writeln( SDL_CreateRenderer Error: , SDL_GetError() ); return; } //load a bitmap SDL_Surface *image = SDL_LoadBMP(./test.bmp); if (image == null){ writeln( SDL_LoadBMP error: , SDL_GetError() ); return; } //create texture for bitmap SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, image); if (texture == null){ writeln( CreateTextureFromSurface error: , SDL_GetError() ); return; } //copy to renderer at correct position scale SDL_Rect sourceRect = { 0, 0, 64, 64 }; SDL_Rect destRect = { 100, 100, 64, 64 }; SDL_RenderCopy(renderer, texture, sourceRect, destRect); //display and pause SDL_RenderPresent(renderer); SDL_Delay(2000); } I'm running ArchLinux 64-bit on Vbox and tested out the code. There haven't been any problems. Have you tried updating whatever tools you're using?(dmd, dub, etc) Might've been an outdated piece of software that's been making the fuss.
Re: Delegate returning itself
On Monday, 8 December 2014 at 14:38:37 UTC, Marc Schütz wrote: On Monday, 8 December 2014 at 14:31:53 UTC, Jonathan Marler wrote: On Monday, 8 December 2014 at 14:08:33 UTC, Jonathan Marler wrote: On Saturday, 6 December 2014 at 15:46:16 UTC, Adam D. Ruppe wrote: The problem is the recursive *alias* rather than the delegate. Just don't use the alias name inside itself so like alias MyDelegate = void delegate() delegate(); will work. The first void delegate() is the return value of the MyDelegate type. Yes I tried that as well. It still doesn't solve the issue. The delegate being returned doesn't return a delegate, it returns the void type. You would need to write delegate() delegate() delegate() delegate() ...FOREVER. I can't figure out a way to write this in the language even though the machine code it generates should be quite trivial. I did some digging and realized that C/C++ have the same problem. I found a nice post on it with 2 potential solutions (http://c-faq.com/decl/recurfuncp.html). I liked the second solution so I wrote up an example in D. If anyone has any other ideas or can think of a way to improve my example feel free to post and let me know, thanks.import std.stdio; struct StateFunc { StateFunc function() func; } StateFunc state1() { writeln(state1); return StateFunc(state2); } StateFunc state2() { writeln(state2); return StateFunc(state3); } StateFunc state3() { writeln(state3); return StateFunc(null); } void main(string[] args) { StateFunc state = StateFunc(state1); while(state.func != null) { state = state.func(); } } Nice! Using alias this, you can call the struct directly: struct StateFunc { StateFunc function() func; alias func this; } state = state(); Now there still needs to be a way to just `return state2;` instead of `return StateFunc(state2);`... Nice addition! I can't think of a way to solve the implicit conversion from function pointer to struct, but not a big deal. I'm mostly glad I found a way to do this with no overhead and no awkward casting. Adding the implicit conversion would be icing on the cake.
Re: Delegate returning itself
On 12/06/2014 07:28 AM, Jonathan Marler wrote: Is there a way to create a delegate that returns itself? Y combinator helps exactly with that: http://rosettacode.org/wiki/Y_combinator#D Copying the code from there: import std.stdio, std.traits, std.algorithm, std.range; auto Y(S, T...)(S delegate(T) delegate(S delegate(T)) f) { static struct F { S delegate(T) delegate(F) f; alias f this; } return (x = x(x))(F(x = f((T v) = x(x)(v; } void main() { // Demo code: auto factorial = Y((int delegate(int) self) = (int n) = 0 == n ? 1 : n * self(n - 1) ); auto ackermann = Y((ulong delegate(ulong, ulong) self) = (ulong m, ulong n) { if (m == 0) return n + 1; if (n == 0) return self(m - 1, 1); return self(m - 1, self(m, n - 1)); }); writeln(factorial: , 10.iota.map!factorial); writeln(ackermann(3, 5): , ackermann(3, 5)); } Ali
How do i use std.functional.binaryFun?
How do i successfully use std.functional.binaryFun in the following example? import std.stdio; import std.functional; class Foo(T, alias greater = a b) if (is(typeof(binaryFun!(greater)(T.init, T.init)) == bool)) { private alias compare = binaryFun!(greater); public this() { writefln(%s, this.compare(2, 1)); } } void main(string[] args) { auto foo = new Foo!(int, a b); // Works auto bar = new Foo!(int, delegate(int a, int b){ return a b; }); // Linker error. } The first instantiation works when using a string but I get a linker error when i try and use a delegate as the compare function. Why is this? and what do i need to do to correct this?
Re: Sorted Array Wrapper Range
On Monday, 8 December 2014 at 15:43:37 UTC, Tobias Pankrath wrote: Was my fault. The phobos checkout didn't match my dmd version. Here is my current state (has some more unittest, bugs fixed, no assignment via SortedRange views on Sorted.): https://github.com/Panke/phobos/blob/sorted/std/container/sorted.d Great! You should do a PR when you're satisfied! :) Is there anything you need help with?
Re: Sorted Array Wrapper Range
On Monday, 8 December 2014 at 15:43:37 UTC, Tobias Pankrath wrote: Was my fault. The phobos checkout didn't match my dmd version. Here is my current state (has some more unittest, bugs fixed, no assignment via SortedRange views on Sorted.): https://github.com/Panke/phobos/blob/sorted/std/container/sorted.d You have an outdated reference to BinaryHeap at line 440 https://github.com/Panke/phobos/blob/sorted/std/container/sorted.d#L440 Should be replaced with Sorted I presume.
Re: Derelict / SDL error
On Monday, 8 December 2014 at 17:48:55 UTC, Jack wrote: I'm running ArchLinux 64-bit on Vbox and tested out the code. There haven't been any problems. Have you tried updating whatever tools you're using?(dmd, dub, etc) Might've been an outdated piece of software that's been making the fuss. Thanks for that. I've just tried the code on a different machine (latest Lubuntu on a 32 bit laptop, latest SDL, dmd and current dub binary) and it has exactly the same problem. Can't think what the problem might be other than something wrong with the way I've compiled SDL...??
Re: How do i use std.functional.binaryFun?
On Monday, 8 December 2014 at 20:08:35 UTC, Gary Willoughby wrote: import std.stdio; import std.functional; class Foo(T, alias greater = a b) if (is(typeof(binaryFun!(greater)(T.init, T.init)) == bool)) { private alias compare = binaryFun!(greater); public this() { writefln(%s, this.compare(2, 1)); } } void main(string[] args) { auto foo = new Foo!(int, a b); // Works auto bar = new Foo!(int, delegate(int a, int b){ return a b; }); // Linker error. } Looks like a compiler bug. A call without this. works. When you insert a call without this., other calls with this. work, too. A delegate with an implicit parameter type works: `Foo!(int, delegate(int a, /*!*/ b){ return a b;})`.
Re: threading issues with D - C - Python
On Monday, 8 December 2014 at 01:17:16 UTC, Ellery Newcomer wrote: On 12/07/2014 03:12 PM, Michael wrote: On Saturday, 6 December 2014 at 00:40:49 UTC, Ellery Newcomer wrote: On 12/04/2014 10:55 PM, Ellery Newcomer wrote: I guess tomorrow I can try messing around with thread_attachThis, as the fullcollect happening in #2 might be screwing with python data. But you aren't really passing anything from python to d or vice versa, so I'm not sure why the gc would need to know about the python threads. by gum, thread_attachThis and thread_detachThis fix the issue! now to figure out how to use them in the general case. This is great.. Thank you. I'm looking forward to being able to try the finished result. It would be great if there were some convenient hook in python to stick these calls. Near as I can tell, there isn't. That leaves you with either explicitly calling attach and detach with an exposed api, or pyd obsessively checking whether the current thread is registered. Actually, I suppose with a thread local flag the latter wouldn't be too bad. Mind if I incorporate your example into pyd's test suite? Not at all. Go for it.
Re: @property usage
as this can break some invalid code (the code where people using properties as functions) Does @property ever make sense for a free floating function? I would have thought no but was recently asked to add it if using the function with uniform call syntax. https://github.com/D-Programming-Language/dub/pull/455#discussion_r21430311
Re: @property usage
On Tue, 09 Dec 2014 07:31:20 + Nicholas Londey via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: as this can break some invalid code (the code where people using properties as functions) Does @property ever make sense for a free floating function? I would have thought no but was recently asked to add it if using the function with uniform call syntax. https://github.com/D-Programming-Language/dub/pull/455#discussion_r21430311 when you want to make a function that acts as getter/setter for delegate callback, for example. private void delegate () cb; @property auto myCB () { return cb; } @property void myCB (void delegate () newcb) { /* some checks */ cb = newcb; } this will work as expected when property enforcement will be fixed -- i.e. you will be able to omit '()' for calling delegate. alas, this is another thing that is cosmetic, so PR with property enforcement will rot on github forever. signature.asc Description: PGP signature