Re: Single exe vibe.d app
On Thursday, 6 April 2017 at 17:39:15 UTC, Stefan Koch wrote: On Wednesday, 5 April 2017 at 12:13:38 UTC, Satoshi wrote: Hi, How can I build single exe application with vibe.d (windows)? now it require zlib.dll, libeay32.dll and ssleay32.dll But I need it as single app. One solution would be to compile vibe.d without ssl support that way it will not need libeay32 and ssleay32 It should not need zlib, really as zlib is already linked into phobos. Could anybody give very easy explanation about what different between static and dynamic libs. I read a lot of information that dynamic lib allow to loading at runtime and bla-bla-bla, but still do not understand what different between compilation at dynamic and static lib. For example: 1. Does every lib can be compiler as static and as dynamic? 2. Can already compiled lib be converted to from static to dynamic and vise-versa. 3. If I have any dynamic lib, the only way is distribute it with app (or use import) or there is way to embed code from it to app? Personaly I like if I can get single bin without any external dependence. In a lot of cases size do not important, it's better to have single bin, than heap of libs.
Re: Single exe vibe.d app
I'm going to give you a very bad but still a good place to begin with explanation. So, what is an executable? Well in modern operating systems that is a file with a very complex structure inside, like PE-COFF or ELF. It has a bunch of things as part of this, a dynamic relocation table, sections and symbols. Now, there is a very important symbol it provides a "main" function. Normally the libc takes ownership of this and then on calls to the c-main that we all know and love (druntime uses this and then passes it to another symbol called _Dmain). What is the difference between a shared library and an executable? Well not much, no main function for starters (although Win32 based ones do have something like it in its place) and a couple of attributes stored in the file. Executables like shared libraries are final binaries, they cannot be further linked with, at least with the most common formats + linkers anyway. You asked about the difference between a static library and a shared library, it isn't quite the right comparison. You should be asking about static libraries versus object files. In essence a static library is just a group of object files. Not too complicated.
Re: Creating Tuple or AliasSeq
On 04/06/2017 10:43 PM, ANtlord wrote: Hello! I've got an issue related to making a Tuple or AliasSeq using income template arguments. I want to create template makes an array of objects from array of arrays have different sizes and different types of values. Here is a solution: auto objectFactory(ObjectType, Args...)(Args args) { import std.algorithm : cartesianProduct, map; import std.array : array; return cartesianProduct(args).map!(a => ObjectType(a.expand)).array; } struct Pair { int number; string name; } import std.stdio; void main() { auto pairKit = objectFactory!(Pair)([1, 2], ["qwe", "asd"]); auto pairSet = pairKit; writeln(pairSet); } Ali
Re: Testing D codes
06.04.2017 19:34, Russel Winder via Digitalmars-d-learn пишет: I am still wondering about separating integration and system tests out of the module source leaving the unit tests in the module source. I do this. I have unittests in the module sources and have a separate subpackage intended for more advanced testing only.
Re: Creating Tuple or AliasSeq
On Friday, 7 April 2017 at 07:46:40 UTC, Ali Çehreli wrote: Here is a solution: auto objectFactory(ObjectType, Args...)(Args args) { import std.algorithm : cartesianProduct, map; import std.array : array; return cartesianProduct(args).map!(a => ObjectType(a.expand)).array; } struct Pair { int number; string name; } import std.stdio; void main() { auto pairKit = objectFactory!(Pair)([1, 2], ["qwe", "asd"]); auto pairSet = pairKit; writeln(pairSet); } Ali It's great! Thanks a lot!
Re: Testing D codes
On Thursday, 6 April 2017 at 13:49:11 UTC, Russel Winder wrote: Is there any need for the unittest block in the application created to run the integration tests? If you don't care to call each and all of them by hand. Test frameworks are handy for extensive testing, builtin unittests work best for the most basic stuff.
Re: Function names and lambdas
On Thu, 2017-04-06 at 18:45 +, Adam D. Ruppe via Digitalmars-d- learn wrote: > On Thursday, 6 April 2017 at 18:37:51 UTC, Russel Winder wrote: > > I am used to a function name being a reference to the function > > body, cf. lots of other languages. However D rejects: > > > > iterative > > Try > > &iterative > > > > The compiler would probably optimize out a trivial thing anyway, > but &foo should work too in most cases. No don't I look like a real idiot. Of course I should have known that. :-) It works exactly as required. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: Creating Tuple or AliasSeq
On Friday, 7 April 2017 at 07:46:40 UTC, Ali Çehreli wrote: Here is a solution: auto objectFactory(ObjectType, Args...)(Args args) { import std.algorithm : cartesianProduct, map; import std.array : array; return cartesianProduct(args).map!(a => ObjectType(a.expand)).array; } struct Pair { int number; string name; } import std.stdio; void main() { auto pairKit = objectFactory!(Pair)([1, 2], ["qwe", "asd"]); auto pairSet = pairKit; writeln(pairSet); } Ali I can't understand. Documentation of cartesianProduct points out about finite arrays. At least one of arrays must be a inifinte array. As far as I know finite arrays is `int[3]` and infinite is `int[]` (https://dlang.org/library/std/range/primitives/is_infinite.html). Am I right? If I am then I can't understand why DMD return error about finite ranges compiling following code. struct Hay { int a; @disable this(this); @disable this(); this(int a){ this.a = a; } } Hay[] params = [ Hay(1), Hay(23) ]; auto products = cartesianProduct(params, params); Error text: static assert "cartesianProduct involving finite ranges must have at least one finite forward range" I noticed that removing disabling default constructors helps. Does that mean an array contains objects of a struct with disabled default constructor is finite?
Re: is char[] faster than string?
On Wednesday, 5 April 2017 at 22:05:07 UTC, H. S. Teoh wrote: If you are doing lots of concatenation and produce a single big string at the end, take a look at std.array.appender. Though if you're concerned about performance, you really should run a profiler. Last I heard, appender may not be that much faster than using ~=, but I could be wrong. If my understanding serves, and it's very likely that it doesn't, then it works precisely as normally appending does but keeps track of array capacity on its own, so the GC doesn't have to do (expensive?) queries upon every append. But when it comes to optimization, my advice is, profile, profile, profile. This. valgrind --tool=callgrind, ddemangle and QCachegrind are your best friends.
Re: Function names and lambdas
On Thu, 2017-04-06 at 11:45 -0700, Ali Çehreli via Digitalmars-d-learn wrote: > […] > I think it's just a design choice. C implicitly converts the name of > the > function to a pointer to that function. D requires the explicit & > operator: One of the dangers of being a bit like and a replacement for another language is that often people carry ideas over incorrectly, as I have here. > alias Func = int function(int); > > int foo(int i) { > return i; > } > > void main() { > Func[] funcs = [ &foo ]; > } I just did: immutable funcs = [tuple(&foo, "foo")]; as I don't need the name of the type, but I do need a string form of the name of the function. > Close to what you mentioned, name of the function can be used as an > alias template parameter: > > void bar(alias func)() { > func(42); > } > > int foo(int i) { > return i; > } > > void main() { > bar!foo(); > } Good to know but for situation here the &foo was what was needed. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Is DMD breaking BigInt?
Simple Dub build of a Factorial example using Unit-Threaded for testing. Works fine with ldc2 breaks with dmd. This is on Debian Sid fully up to date. |> ldc2 --version LDC - the LLVM D compiler (1.1.1): based on DMD v2.071.2 and LLVM 3.9.1 built with LDC - the LLVM D compiler (1.1.0) Default target: x86_64-pc-linux-gnu Host CPU: broadwell http://dlang.org - http://wiki.dlang.org/LDC |> dmd --version DMD64 D Compiler v2.073.2 |> dub test --compiler=ldc2 Package factorial (configuration "unittest") defines no import paths, use {"importPaths": [...]} or the default package directory structure to fix this. Running custom 'unittest' configuration. Performing "unittest" build using ldc2 for x86_64. unit-threaded 0.7.11: target for configuration "library" is up to date. factorial ~master: building configuration "unittest"... Running pre-build commands... Building package unit-threaded in /home/users/russel/.dub/packages/unit-threaded-0.7.11/unit-threaded/ Performing "$DFLAGS" build using dmd for x86_64. unit-threaded 0.7.11: building configuration "gen_ut_main"... Linking... Running ../../../../.dub/packages/unit-threaded-0.7.11/unit-threaded/gen_ut_main -f ut_main.d To force a rebuild of up-to-date targets, run again with --force. Running ./factorial-test Automatically generated file ut_main.d Running unit tests from dirs ["."] factorial.Check the base case for all algorithms.: factorial.Check the property for all algorithms.: factorial.Traditional example-based testing.: Time taken: 34 ms, 363 μs, and 2 hnsecs 3 test(s) run, 0 failed. OK! |> dub test Package factorial (configuration "unittest") defines no import paths, use {"importPaths": [...]} or the default package directory structure to fix this. Running custom 'unittest' configuration. Performing "unittest" build using dmd for x86_64. unit-threaded 0.7.11: target for configuration "library" is up to date. factorial ~master: building configuration "unittest"... Running pre-build commands... Building package unit-threaded in /home/users/russel/.dub/packages/unit-threaded-0.7.11/unit-threaded/ Performing "$DFLAGS" build using dmd for x86_64. unit-threaded 0.7.11: building configuration "gen_ut_main"... Linking... Running ../../../../.dub/packages/unit-threaded-0.7.11/unit-threaded/gen_ut_main -f ut_main.d factorial.d(71,15): Error: template std.bigint.BigInt.__ctor cannot deduce function from argument types !()(string) immutable, candidates are: /usr/include/dmd/phobos/std/bigint.d(64,5): std.bigint.BigInt.__ctor(Range)(Range s) if (isBidirectionalRange!Range && isSomeChar!(ElementType!Range) && !isInfinite!Range) /usr/include/dmd/phobos/std/bigint.d(146,5): std.bigint.BigInt.__ctor(T)(T x) if (isIntegral!T) /usr/include/dmd/phobos/std/bigint.d(162,5): std.bigint.BigInt.__ctor(T)(T x) if (is(Unqual!T == BigInt)) dmd failed with exit code 1. If anyone has any useful intelligence as to what happening and how I can workaround it, I'd be a grateful bunny. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: Function names and lambdas
On Thursday, 6 April 2017 at 18:45:26 UTC, Ali Çehreli wrote: On 04/06/2017 11:37 AM, Russel Winder via Digitalmars-d-learn wrote: [...] I think it's just a design choice. C implicitly converts the name of the function to a pointer to that function. D requires the explicit & operator: alias Func = int function(int); int foo(int i) { return i; } void main() { Func[] funcs = [ &foo ]; } Close to what you mentioned, name of the function can be used as an alias template parameter: void bar(alias func)() { func(42); } int foo(int i) { return i; } void main() { bar!foo(); } Ali Main reason is probably UFCS.
Re: Is DMD breaking BigInt?
On Friday, 7 April 2017 at 17:06:31 UTC, Russel Winder wrote: Simple Dub build of a Factorial example using Unit-Threaded for testing. Works fine with ldc2 breaks with dmd. Can you post the code your using?
Re: Is DMD breaking BigInt?
On Friday, 7 April 2017 at 17:06:31 UTC, Russel Winder wrote: If anyone has any useful intelligence as to what happening and how I can workaround it, I'd be a grateful bunny. You might want to check with LDC from Git master first to see whether it is in fact a 2.073-related problem. — David
Re: Function names and lambdas
On 04/07/2017 11:19 AM, Yuxuan Shui wrote: > On Thursday, 6 April 2017 at 18:45:26 UTC, Ali Çehreli wrote: >> On 04/06/2017 11:37 AM, Russel Winder via Digitalmars-d-learn wrote: >>> [...] >> >> I think it's just a design choice. C implicitly converts the name of >> the function to a pointer to that function. D requires the explicit & >> operator: >> >> alias Func = int function(int); >> >> int foo(int i) { >> return i; >> } >> >> void main() { >> Func[] funcs = [ &foo ]; >> } >> >> Close to what you mentioned, name of the function can be used as an >> alias template parameter: >> >> void bar(alias func)() { >> func(42); >> } >> >> int foo(int i) { >> return i; >> } >> >> void main() { >> bar!foo(); >> } >> >> Ali > > Main reason is probably UFCS. Main reason for D not supporting the name-to-pointer mapping? I don't think so because as far as I know this has been the case since very early on but UFCS came very much later. Ali
Re: Is DMD breaking BigInt?
On Friday, 7 April 2017 at 17:06:31 UTC, Russel Winder wrote: Simple Dub build of a Factorial example using Unit-Threaded for testing. Works fine with ldc2 breaks with dmd. This is on Debian Sid fully up to date. |> ldc2 --version LDC - the LLVM D compiler (1.1.1): based on DMD v2.071.2 and LLVM 3.9.1 built with LDC - the LLVM D compiler (1.1.0) Default target: x86_64-pc-linux-gnu Host CPU: broadwell http://dlang.org - http://wiki.dlang.org/LDC |> dmd --version DMD64 D Compiler v2.073.2 |> dub test --compiler=ldc2 Package factorial (configuration "unittest") defines no import paths, use {"importPaths": [...]} or the default package directory structure to fix this. Running custom 'unittest' configuration. Performing "unittest" build using ldc2 for x86_64. unit-threaded 0.7.11: target for configuration "library" is up to date. factorial ~master: building configuration "unittest"... Running pre-build commands... Building package unit-threaded in /home/users/russel/.dub/packages/unit-threaded-0.7.11/unit-threaded/ Performing "$DFLAGS" build using dmd for x86_64. unit-threaded 0.7.11: building configuration "gen_ut_main"... Linking... Running ../../../../.dub/packages/unit-threaded-0.7.11/unit-threaded/gen_ut_main -f ut_main.d To force a rebuild of up-to-date targets, run again with --force. Running ./factorial-test Automatically generated file ut_main.d Running unit tests from dirs ["."] factorial.Check the base case for all algorithms.: factorial.Check the property for all algorithms.: factorial.Traditional example-based testing.: Time taken: 34 ms, 363 μs, and 2 hnsecs 3 test(s) run, 0 failed. OK! |> dub test Package factorial (configuration "unittest") defines no import paths, use {"importPaths": [...]} or the default package directory structure to fix this. Running custom 'unittest' configuration. Performing "unittest" build using dmd for x86_64. unit-threaded 0.7.11: target for configuration "library" is up to date. factorial ~master: building configuration "unittest"... Running pre-build commands... Building package unit-threaded in /home/users/russel/.dub/packages/unit-threaded-0.7.11/unit-threaded/ Performing "$DFLAGS" build using dmd for x86_64. unit-threaded 0.7.11: building configuration "gen_ut_main"... Linking... Running ../../../../.dub/packages/unit-threaded-0.7.11/unit-threaded/gen_ut_main -f ut_main.d factorial.d(71,15): Error: template std.bigint.BigInt.__ctor cannot deduce function from argument types !()(string) immutable, candidates are: /usr/include/dmd/phobos/std/bigint.d(64,5): std.bigint.BigInt.__ctor(Range)(Range s) if (isBidirectionalRange!Range && isSomeChar!(ElementType!Range) && !isInfinite!Range) /usr/include/dmd/phobos/std/bigint.d(146,5): std.bigint.BigInt.__ctor(T)(T x) if (isIntegral!T) /usr/include/dmd/phobos/std/bigint.d(162,5): std.bigint.BigInt.__ctor(T)(T x) if (is(Unqual!T == BigInt)) dmd failed with exit code 1. If anyone has any useful intelligence as to what happening and how I can workaround it, I'd be a grateful bunny. Do you have the -dip1000 switch enabled?
Using template mixin, with or without mixin ?
I want to use mixin to generate function in-place. In template declaration, I can see 'mixin' keyword is optional. Is it true? What is the difference and when I must use one way over another? This is my program: // This works with and without 'mixin' attribute. mixin template funcgen(T, U){ T func1(string pr2){ writeln("Func1: ", pr2); } U func2(string pr3){ writeln("Func2: ", pr3); } } int main(string[] args){ mixin funcgen!(void, void); func1("func1"); func2("func2"); return 0; }
Re: Using template mixin, with or without mixin ?
On 04/07/2017 04:47 PM, biocyberman wrote: I want to use mixin to generate function in-place. In template declaration, I can see 'mixin' keyword is optional. Is it true? What is the difference and when I must use one way over another? This is my program: // This works with and without 'mixin' attribute. mixin template funcgen(T, U){ T func1(string pr2){ writeln("Func1: ", pr2); } U func2(string pr3){ writeln("Func2: ", pr3); } } int main(string[] args){ mixin funcgen!(void, void); func1("func1"); func2("func2"); return 0; } The difference is that you can't use funcgen as a regular template: funcgen!(void, void); Error: template instance funcgen!(void, void) mixin templates are not regular templates I think it's good practice to use 'mixin template' if it's intended to be so. Ali
Re: Creating Tuple or AliasSeq
On Friday, 7 April 2017 at 10:26:24 UTC, ANtlord wrote: On Friday, 7 April 2017 at 07:46:40 UTC, Ali Çehreli wrote: [...] I can't understand. Documentation of cartesianProduct points out about finite arrays. At least one of arrays must be a inifinte array. As far as I know finite arrays is `int[3]` and infinite is `int[]` (https://dlang.org/library/std/range/primitives/is_infinite.html). Am I right? If I am then I can't understand why DMD return error about finite ranges compiling following code. struct Hay { int a; @disable this(this); @disable this(); this(int a){ this.a = a; } } Hay[] params = [ Hay(1), Hay(23) ]; auto products = cartesianProduct(params, params); Error text: [...] I noticed that removing disabling default constructors helps. Does that mean an array contains objects of a struct with disabled default constructor is finite? No, int[] is a finite array. isInfinite is meant to test for ranges which are statically defined to *never* be empty, no matter how many times you consume them. See std.range.repeat(T) for an example of such a range.
overring binary
I have a custom type and I'm trying to do things like x~1 and 1~x. I can get x~1 no problem by overriding the op "~" but how to I get 1~x to convert 1 in to typeof(x)? instead of x in to typeof(1) so to speak? I really want D to realize that 1~x is suppose to use ~ of x, not 1.
Re: overring binary
On 08/04/2017 7:46 AM, Jethro wrote: I have a custom type and I'm trying to do things like x~1 and 1~x. I can get x~1 no problem by overriding the op "~" but how to I get 1~x to convert 1 in to typeof(x)? instead of x in to typeof(1) so to speak? I really want D to realize that 1~x is suppose to use ~ of x, not 1. struct Foo { int x; Foo opBinaryRight(string op)(int y) { static if (op == "~") { return Foo(x + y); } else static assert(0, "not implemented"); } } void main() { import std.stdio; writeln(1 ~ Foo(2)); }