alias with lambda syntax: alias fun2=a=fun(a);

2014-06-05 Thread Timothee Cour via Digitalmars-d-learn
Is there a way to do this? import std.algorithm; auto fun(T)(T a){return a;} template fun2(T){auto fun2(T a){return fun(a);}}//OK but heavy syntax and cannot be nested inside test() void main(){ //alias fun2=fun!int; //OK but needs to specify template params //none of those work: //alias

Re: alias with lambda syntax: alias fun2=a=fun(a);

2014-06-05 Thread timotheecour via Digitalmars-d-learn
On Thursday, 5 June 2014 at 06:58:50 UTC, Timothee Cour via Digitalmars-d-learn wrote: Is there a way to do this? import std.algorithm; auto fun(T)(T a){return a;} template fun2(T){auto fun2(T a){return fun(a);}}//OK but heavy syntax and cannot be nested inside test() void main(){

Re: alias with lambda syntax: alias fun2=a=fun(a);

2014-06-05 Thread Timothee Cour via Digitalmars-d-learn
ok I remembered we can use std.typetuple.Alias for that. On Wed, Jun 4, 2014 at 11:58 PM, Timothee Cour thelastmamm...@gmail.com wrote: Is there a way to do this? import std.algorithm; auto fun(T)(T a){return a;} template fun2(T){auto fun2(T a){return fun(a);}}//OK but heavy syntax and

Re: Arrays as template parameters

2014-06-05 Thread anonymous via Digitalmars-d-learn
On Wednesday, 4 June 2014 at 23:25:13 UTC, cal wrote: I have the following code (on dpaste, http://dpaste.dzfl.pl/636c04430a33): enum : uint { a, b, c } enum list = [a, b]; void foo(T...)() { pragma(msg, T[0].length); // fine pragma(msg, T[0][0]); // fine pragma(msg, T[0][1]);

Re: alias with lambda syntax: alias fun2=a=fun(a);

2014-06-05 Thread Artur Skawina via Digitalmars-d-learn
On 06/05/14 08:58, Timothee Cour via Digitalmars-d-learn wrote: Is there a way to do this? auto fun(T)(T a){return a;} template fun2(T){auto fun2(T a){return fun(a);}}//OK but heavy syntax and cannot be nested inside test() alias fun2(T) = fun!T; But this will prevent IFTI, so

Re: alias with lambda syntax: alias fun2=a=fun(a);

2014-06-05 Thread Artur Skawina via Digitalmars-d-learn
On 06/05/14 08:58, Timothee Cour via Digitalmars-d-learn wrote: //none of those work: //alias fun2=a=fun(a); alias fun2=ALIAS!(a=fun(a)); That 'ALIAS' template will need to be in module scope. alias ALIAS(alias A) = A; artur

Re: Kernel in D

2014-06-05 Thread 1100110 via Digitalmars-d-learn
On 5/31/14, 7:57, ed wrote: On Saturday, 31 May 2014 at 07:28:32 UTC, Mineko wrote: So, I've gotten interested in kernel programming in D.. And as much as I like C/C++, I wanna try innovating, I'm aware that phobos/gc and any OS-specific issues are going to be a problem, but I'm willing to

Re: Kernel in D

2014-06-05 Thread 1100110 via Digitalmars-d-learn
On 6/5/14, 6:05, 1100110 wrote: On 5/31/14, 7:57, ed wrote: On Saturday, 31 May 2014 at 07:28:32 UTC, Mineko wrote: So, I've gotten interested in kernel programming in D.. And as much as I like C/C++, I wanna try innovating, I'm aware that phobos/gc and any OS-specific issues are going to be a

Re: Kernel in D

2014-06-05 Thread ed via Digitalmars-d-learn
On Thursday, 5 June 2014 at 11:07:54 UTC, 1100110 wrote: On 6/5/14, 6:05, 1100110 wrote: On 5/31/14, 7:57, ed wrote: On Saturday, 31 May 2014 at 07:28:32 UTC, Mineko wrote: So, I've gotten interested in kernel programming in D.. And as much as I like C/C++, I wanna try innovating, I'm aware

dub: strange behavior

2014-06-05 Thread Chris via Digitalmars-d-learn
I've just had the case where after changing the code and running $ dub nothing changed in the output. I couldn't make sense of it. Then I ran $ dub --force and the output was as expected. Has this happened to anyone. I think I came across this before.

Writing to file problem (Kernelbase exeption)

2014-06-05 Thread Konrad via Digitalmars-d-learn
Hi guys! I have problem with writing to a file. My function looks like this: [code] int game_change_config(string _player_spritesheet, string _flame_spritesheet) { string info = _player_spritesheet~\n~_flame_spritesheet; auto config_file = File(Data/config.ini);

Re: Example of filtering a Linked List that hold a custom class (Tango)

2014-06-05 Thread Justin Whear via Digitalmars-d-learn
On Thu, 05 Jun 2014 17:50:37 +, JJDuck wrote: let say I have a Linked List(tango) that holds custom class and how do I filter the LinkedList to extract the items that I want according to a particular field (a integer field) from my custom class? Is it easier to do it using phobos'

Example of filtering a Linked List that hold a custom class (Tango)

2014-06-05 Thread JJDuck via Digitalmars-d-learn
let say I have a Linked List(tango) that holds custom class and how do I filter the LinkedList to extract the items that I want according to a particular field (a integer field) from my custom class? Is it easier to do it using phobos' Array? If it does, care to have an example on Phobos too?

Re: Writing to file problem (Kernelbase exeption)

2014-06-05 Thread Kagamin via Digitalmars-d-learn
Try to reduce it: remove code from the program piece by piece until you find a fragment, which causes the problem.

Using D static library from C

2014-06-05 Thread George Sapkin via Digitalmars-d-learn
I'm trying to link a simple D static library to C code, but I'm can't figure out how to do it properly without getting a segfault when running it. test.d --- import std.stdio; extern(C) void funcD() { writeln(From D); } main.c ---

Re: Using D static library from C

2014-06-05 Thread Stefan Koch via Digitalmars-d-learn
You need to link the druntime too, I think.

Re: Using D static library from C

2014-06-05 Thread George Sapkin via Digitalmars-d-learn
On Thursday, 5 June 2014 at 18:55:13 UTC, Stefan Koch wrote: You need to link the druntime too, I think. At which stage? Can you provide a full command? Thanks.

Re: Writing to file problem (Kernelbase exeption)

2014-06-05 Thread Konrad via Digitalmars-d-learn
Well, there is a problem with config_file.write(info); but when I'm changing it to write(Data/config.ini, info); (as it states in http://dlang.org/phobos/std_file.html#.write) I'm getting an error of conflict between std.stdio.write and std.file.write. That's why I was using the first line.

Re: Using D static library from C

2014-06-05 Thread Dave Wilson via Digitalmars-d-learn
You can create a static library from one or more .o files using ar, if that helps (unless I've failed to understand the question). ar r libtest.a test.o should do the job.

Re: Using D static library from C

2014-06-05 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 5 June 2014 at 19:00:24 UTC, George Sapkin wrote: On Thursday, 5 June 2014 at 18:55:13 UTC, Stefan Koch wrote: You need to link the druntime too, I think. At which stage? Can you provide a full command? Thanks. Err ... I just remeberd linking d with gcc needs a few libs

Re: Writing to file problem (Kernelbase exeption)

2014-06-05 Thread Stefan Koch via Digitalmars-d-learn
config_file needs to be the string not a struct File .

When is a slice not a slice?

2014-06-05 Thread Alix Pexton via Digitalmars-d-learn
In CTFE it seems. Only tested with DMD on Windows though. Is this a known limitation, or a bug, I couldn't find anything that seemed to match it in the bugzilla. import std.array; struct DataAndView { int[] data, view; this(int x) { data = [1, 2, 3,

Re: When is a slice not a slice?

2014-06-05 Thread Philippe Sigaud via Digitalmars-d-learn
enum b = DataAndView(1); assert (!sameTail(b.data, b.view)); I suppose it's because enums are manifest constants: the value they represent is 'copy-pasted' anew everywhere it appears in the code. So for arrays and associative arrays, it means recreating a new value each and

Re: When is a slice not a slice?

2014-06-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thu, 05 Jun 2014 15:56:00 -0400, Philippe Sigaud via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: enum b = DataAndView(1); assert (!sameTail(b.data, b.view)); I suppose it's because enums are manifest constants: the value they represent is 'copy-pasted'

Re: Writing to file problem (Kernelbase exeption)

2014-06-05 Thread Konrad via Digitalmars-d-learn
Right now I have: import file = std.file; import std.stdio; int game_change_config(string _player_spritesheet, string _flame_spritesheet) { string info = _player_spritesheet~\n~_flame_spritesheet; char[] info_table; for(int i = 0; i info.length; i++) { info_table.length++;

Re: Writing to file problem (Kernelbase exeption)

2014-06-05 Thread Ali Çehreli via Digitalmars-d-learn
On 06/05/2014 01:39 PM, Konrad wrote: Right now I have: import file = std.file; import std.stdio; int game_change_config(string _player_spritesheet, string _flame_spritesheet) { string info = _player_spritesheet~\n~_flame_spritesheet; char[] info_table; for(int i = 0; i

Re: Writing to file problem (Kernelbase exeption)

2014-06-05 Thread Konrad via Digitalmars-d-learn
Ok, I have rebuilded whole solution in MSVS (I'm using VisualD plugin) and everything started to work with my previously pasted code. @Ali, thank you for advise with concatenation, I haven't thought about that. Also thank you to all of you, guys, all that you wrote was very helpfull.

Re: Separate allocation and construction?

2014-06-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 5 June 2014 at 22:22:16 UTC, Chris Williams wrote: If I wanted to allocate memory for a class and then call its constructor as two separate steps, while still having the object be managed by the garbage collector, is there any way to do that? Check out std.conv.emplace

Separate allocation and construction?

2014-06-05 Thread Chris Williams via Digitalmars-d-learn
If I wanted to allocate memory for a class and then call its constructor as two separate steps, while still having the object be managed by the garbage collector, is there any way to do that? I believe that I've figured out a way to accomplish the first step, but not the second. import

Re: Separate allocation and construction?

2014-06-05 Thread Chris Williams via Digitalmars-d-learn
On Thursday, 5 June 2014 at 22:25:03 UTC, Adam D. Ruppe wrote: On Thursday, 5 June 2014 at 22:22:16 UTC, Chris Williams wrote: If I wanted to allocate memory for a class and then call its constructor as two separate steps, while still having the object be managed by the garbage collector, is

Linking with C on Windows

2014-06-05 Thread Mark Isaacson via Digitalmars-d-learn
I'm having a very difficult time figuring out exactly how to do this. I've compiled my D code into a .obj file with dmd, but I don't know what C compiler I should use (or if it makes any difference). I've attempted to use MinGW gcc, which spits out .o files, and Visual Studio, which does...

Re: Linking with C on Windows

2014-06-05 Thread bearophile via Digitalmars-d-learn
Mark Isaacson: My attempts to have either the MinGW linker or the Visual Studio linker accept my D .objs have all failed. Try using the dmc compiler for the C code. Bye, bearophile

Re: Linking with C on Windows

2014-06-05 Thread Mark Isaacson via Digitalmars-d-learn
On Thursday, 5 June 2014 at 22:59:48 UTC, bearophile wrote: Mark Isaacson: My attempts to have either the MinGW linker or the Visual Studio linker accept my D .objs have all failed. Try using the dmc compiler for the C code. Bye, bearophile I'd considered that, but in the long term that

Re: Separate allocation and construction?

2014-06-05 Thread Ali Çehreli via Digitalmars-d-learn
On 06/05/2014 03:47 PM, Chris Williams wrote: On Thursday, 5 June 2014 at 22:25:03 UTC, Adam D. Ruppe wrote: On Thursday, 5 June 2014 at 22:22:16 UTC, Chris Williams wrote: If I wanted to allocate memory for a class and then call its constructor as two separate steps, while still having the

Re: alias with lambda syntax: alias fun2=a=fun(a);

2014-06-05 Thread Meta via Digitalmars-d-learn
On Thursday, 5 June 2014 at 07:19:07 UTC, timotheecour wrote: ok I remembered we can use std.typetuple.Alias for that. Or std.functional.unaryFun.

Re: Linking with C on Windows

2014-06-05 Thread Mark Isaacson via Digitalmars-d-learn
Still unresolved, but a thought: I decided to take a step back and try to link with C on Linux first. I found out that if I did the linking step with dmd things worked, but not with gcc. The reason then became apparent: dmd knows to pass druntime and phobos and all of that stuff to the linker.

Re: Using D static library from C

2014-06-05 Thread George Sapkin via Digitalmars-d-learn
On Thursday, 5 June 2014 at 19:10:17 UTC, Dave Wilson wrote: You can create a static library from one or more .o files using ar, if that helps (unless I've failed to understand the question). ar r libtest.a test.o should do the job. I don't have trouble creating a static library with dmd, I

Re: Using D static library from C

2014-06-05 Thread George Sapkin via Digitalmars-d-learn
On Thursday, 5 June 2014 at 19:14:34 UTC, Stefan Koch wrote: On Thursday, 5 June 2014 at 19:00:24 UTC, George Sapkin wrote: On Thursday, 5 June 2014 at 18:55:13 UTC, Stefan Koch wrote: You need to link the druntime too, I think. At which stage? Can you provide a full command? Thanks. Err

Re: Using D static library from C

2014-06-05 Thread George Sapkin via Digitalmars-d-learn
On Thursday, 5 June 2014 at 19:14:34 UTC, Stefan Koch wrote: On Thursday, 5 June 2014 at 19:00:24 UTC, George Sapkin wrote: On Thursday, 5 June 2014 at 18:55:13 UTC, Stefan Koch wrote: You need to link the druntime too, I think. At which stage? Can you provide a full command? Thanks. Err

Re: Linking with C on Windows

2014-06-05 Thread Ellery Newcomer via Digitalmars-d-learn
On Thursday, 5 June 2014 at 23:12:56 UTC, Mark Isaacson wrote: I need to eventually be able to export a dll that can talk with anything. how would using dmc conflict with this goal? dmd/dmc output omf object files, windows infrastructure is all coff object files. linux/mingw/etc are..

Re: Using D static library from C

2014-06-05 Thread Mark Isaacson via Digitalmars-d-learn
I found that if I told dmd rather than gcc to do the linking that everything just magically worked. In other words: gcc -c cstuff.c dmd -c dstuff.d dmd cstuff.o dstuff.o I presume that dmd would be similarly smart with static libraries.

Re: Using D static library from C

2014-06-05 Thread George Sapkin via Digitalmars-d-learn
On Friday, 6 June 2014 at 02:01:12 UTC, Mark Isaacson wrote: I found that if I told dmd rather than gcc to do the linking that everything just magically worked. In other words: gcc -c cstuff.c dmd -c dstuff.d dmd cstuff.o dstuff.o I presume that dmd would be similarly smart with static

Re: Using D static library from C

2014-06-05 Thread Ellery Newcomer via Digitalmars-d-learn
On Thursday, 5 June 2014 at 18:51:25 UTC, George Sapkin wrote: I'm trying to link a simple D static library to C code, but I'm can't figure out how to do it properly without getting a segfault when running it. try this: dmd -lib test.d -defaultlib=libphobos2.a -oflibtest.a gcc main.c

Re: Using D static library from C

2014-06-05 Thread George Sapkin via Digitalmars-d-learn
On Friday, 6 June 2014 at 02:13:08 UTC, Ellery Newcomer wrote: On Thursday, 5 June 2014 at 18:51:25 UTC, George Sapkin wrote: I'm trying to link a simple D static library to C code, but I'm can't figure out how to do it properly without getting a segfault when running it. try this: dmd -lib

Re: Using D static library from C

2014-06-05 Thread Ellery Newcomer via Digitalmars-d-learn
On Friday, 6 June 2014 at 02:17:50 UTC, George Sapkin wrote: On Friday, 6 June 2014 at 02:13:08 UTC, Ellery Newcomer wrote: On Thursday, 5 June 2014 at 18:51:25 UTC, George Sapkin wrote: I'm trying to link a simple D static library to C code, but I'm can't figure out how to do it properly

D array to c

2014-06-05 Thread Harpo via Digitalmars-d-learn
Hello I need to pass a array in D to c. I have edited the code to the important parts. Normally in C I would just do this: void myFunction(int *array) { } Then pass it a array of whatever size. However I actually need the array to be in a struct so... typedef struct{int* array;}

Re: D array to c

2014-06-05 Thread Philpax via Digitalmars-d-learn
On Friday, 6 June 2014 at 03:40:41 UTC, Harpo wrote: Hello I need to pass a array in D to c. I have edited the code to the important parts. Normally in C I would just do this: void myFunction(int *array) { } Then pass it a array of whatever size. However I actually need the array to be in a

Re: D array to c

2014-06-05 Thread Harpo via Digitalmars-d-learn
sorry thats: struct examplestruct {int* array;} int numar[50]; examplestruct parameters; parameters.array = numuar; When I do that I get type conflictions. Error: cannot implicitly convert expression (numar) of type int[50] to int*... I am not sure what setup I need to have here. Anyone know

Re: D array to c

2014-06-05 Thread Harpo via Digitalmars-d-learn
Thanks that was perfect. Also I am aware of the use of the 64bit numbers. Thank you for pointing it out though.