Re: isArray and std.container.Array
On Sunday, 28 September 2014 at 20:24:11 UTC, monarch_dodra wrote: On Sunday, 28 September 2014 at 19:06:09 UTC, Marc Schütz wrote: On Sunday, 28 September 2014 at 16:12:53 UTC, Meta wrote: On Sunday, 28 September 2014 at 08:01:00 UTC, Nordlöw wrote: Is there a reason why isArray!T doesn't match T when T is a std.container.Array? I'm asking because after looking into msgpack-d because of http://forum.dlang.org/thread/aclapseyptgcwntda...@forum.dlang.org#post-aclapseyptgcwntdavwt:40forum.dlang.org I realized that this is the reason why msgpack doesn't correctly pack std.container.Array. It's just an oversight in isArray as far as I can tell. I don't know if there's any specific reason that Array is not considered an array. I don't think so. std.container.Array is just a data structure that behaves like an array, but there could be countless other user defined data structures. It should not get preferred treatment over those other types. At most, isArray could check for the presence of .length, .ptr and indexing/slicing. But I think isArray was intended specifically for built-in arrays. It's description "is an array (static or dynamic [...])" is probably meant to express that, because it lists static and dynamic arrays, but doesn't mention array-like containers. Yes, everything here is correct. Interestingly though, "Array" is not actually "array-like" (it's not a range, it doesn't slice), however "Array.Range" *is* an array-like structure. In regards to "isArrayLike", it would probably be more interesting to instead integrate it as a "isRandomAccessRange" range refinement, which would also allow "opSlice" operations, eg (myRange[0 .. 3] = 5). As for ".ptr", I think no range *trait* should expose (require) that, as it would most probably be an underhanded way to leak some abstraction, which would be better expressed as a direct call *prior*, rather than a range proper. EG: myRange.ptr[0 .. 10].doSomeOperation(); The question is whether you want to call something "array-like" if it isn't stored contiguously in memory. Most algorithms don't depend on it, but it's a significant divergence from what isArray guarantees.
Re: isArray and std.container.Array
On Monday, 29 September 2014 at 10:18:09 UTC, Marc Schütz wrote: On Sunday, 28 September 2014 at 20:24:11 UTC, monarch_dodra wrote: On Sunday, 28 September 2014 at 19:06:09 UTC, Marc Schütz wrote: On Sunday, 28 September 2014 at 16:12:53 UTC, Meta wrote: On Sunday, 28 September 2014 at 08:01:00 UTC, Nordlöw wrote: Is there a reason why isArray!T doesn't match T when T is a std.container.Array? I'm asking because after looking into msgpack-d because of http://forum.dlang.org/thread/aclapseyptgcwntda...@forum.dlang.org#post-aclapseyptgcwntdavwt:40forum.dlang.org I realized that this is the reason why msgpack doesn't correctly pack std.container.Array. It's just an oversight in isArray as far as I can tell. I don't know if there's any specific reason that Array is not considered an array. I don't think so. std.container.Array is just a data structure that behaves like an array, but there could be countless other user defined data structures. It should not get preferred treatment over those other types. At most, isArray could check for the presence of .length, .ptr and indexing/slicing. But I think isArray was intended specifically for built-in arrays. It's description "is an array (static or dynamic [...])" is probably meant to express that, because it lists static and dynamic arrays, but doesn't mention array-like containers. Yes, everything here is correct. Interestingly though, "Array" is not actually "array-like" (it's not a range, it doesn't slice), however "Array.Range" *is* an array-like structure. In regards to "isArrayLike", it would probably be more interesting to instead integrate it as a "isRandomAccessRange" range refinement, which would also allow "opSlice" operations, eg (myRange[0 .. 3] = 5). As for ".ptr", I think no range *trait* should expose (require) that, as it would most probably be an underhanded way to leak some abstraction, which would be better expressed as a direct call *prior*, rather than a range proper. EG: myRange.ptr[0 .. 10].doSomeOperation(); The question is whether you want to call something "array-like" if it isn't stored contiguously in memory. Most algorithms don't depend on it, but it's a significant divergence from what isArray guarantees. Right, but just because it *is* stored contiguous in memory don't mean you want to expose it. Array.Range is contiguous in memory, but it does not provide ".ptr". Also, queue-like containers are not "fully" contiguous in memory, so *couldn't* expose ".ptr". They'd still get major benefit from "myRange[]=5" though. Because of that, I think a trait like "isArrayLike" requiring full array-like behavior is not very useful. Rather, just "isSliceOpRange" would be better.
[dub] Building DLLs
Today I tried to build a dll via dub, unfortunately I didn't succeed. I couldn't find much on the internet about it. Is it at all possible, and if yes, what's the config I have to use? I tried this (and similar configs) { "name": "myDLL32bit", "targetName": "myDLL.dll", "targetType": "dynamicLibrary", // Removed this too "targetPath": "bin/windows/32bit/dll", "platforms": ["windows"], "lflags": [ "-L/IMPLIB", "-Llib/windows/32bit", ], "libs": [ "somelibs ...", ], "sourceFiles-windows-x86-dmd": ["source/dll/myDLL.d", "source/dll/dllmain.d", "dll/32bit/myDLL.def"], "excludedSourceFiles": ["source/app.d"], } I also included "mainSourceFile": "source/dll/dllmain.d", to no avail. If I use a batch file, it works perfectly fine: C:\D\dmd2\windows\bin\dmd.exe -ofbin\windows\32bit\dll\myDLL.dll -L/IMPLIB etc etc
out parameter with default value
Why it does works: void f(out int c) { if(some_cond) c = 10; } but it doesn't? void f(out int c = 1) { if(some_cond) c = 10; } it give compiler error: Error: constant 1 is not an lvalue
Re: out parameter with default value
My question is why it doesn't works and if there's a workaround
Re: out parameter with default value
On Monday, 29 September 2014 at 16:09:11 UTC, AsmMan wrote: My question is why it doesn't works and if there's a workaround For the same reason `ref` wouldn't work in this place: It doesn't accept rvalues. A workaround might be to create a global variable that is initialized to the value you want, and use this as the default value. But this probably isn't what you look for, because you're most likely going to overwrite it, so the next time the function gets called, it will have a different value.
vibe.d https_server example fails
When build and run (using dub) the examples/https_server/ under vibe.d master it prints Target vibe-d ~master is up to date. Use --force to rebuild. Building https-server-example ~master configuration "application", build type debug. Compiling using dmd... Linking... Running ./https-server-example Listening for HTTPS requests on ::1:8080 Listening for HTTPS requests on 127.0.0.1:8080 but when I open the URL 127.0.0.1:8080 in Chrome I get an error message No data is received (translated from swedish) and my server the prints Handling of connection failed: Failed to accept SSL tunnel: What's wrong? Certificates?
Re: vibe.d https_server example fails
On 09/29/2014 06:31 PM, "Nordlöw" wrote: What's wrong? Certificates? Use https instead of http :). https://localhost:8080/
Turn function into infinite range
Does anyone know a construct to turn a lambda into an infinite range. import std.random; unittest { Random gen; foreach(v; xxx!(() => uniform(0, 100, gen)).take(10)) writeln(v); } I though I've seen this around somewhere but can no longer find it.
Re: Turn function into infinite range
On Monday, 29 September 2014 at 17:02:43 UTC, Martin Nowak wrote: Does anyone know a construct to turn a lambda into an infinite range. import std.random; unittest { Random gen; foreach(v; xxx!(() => uniform(0, 100, gen)).take(10)) writeln(v); } I though I've seen this around somewhere but can no longer find it. I can't find anything to do it. That seems weirdly absent. You can abuse recurrence to do it. Random gen; foreach(v; recurrence!((a, n) => uniform(0, 100, gen))(0).dropOne.take(10)) writeln(v);
Re: out parameter with default value
On Mon, 29 Sep 2014 16:07:49 + AsmMan via Digitalmars-d-learn wrote: > but it doesn't? > > void f(out int c = 1) 'cause `out int c` is actually `int* c`. you can't assign int(1) to pointer. signature.asc Description: PGP signature
Re: vibe.d https_server example fails
On Monday, 29 September 2014 at 16:57:52 UTC, Martin Nowak wrote: Use https instead of http :). Doh! https://localhost:8080/ This however crashes the server program as Error executing command run: Program exited with code -11 Maybe I should use a vibe.d version other than master?
Re: vibe.d https_server example fails
On 09/29/2014 08:20 PM, "Nordlöw" wrote: This however crashes the server program as Error executing command run: Program exited with code -11 Maybe I should use a vibe.d version other than master? Please report it https://github.com/rejectedsoftware/vibe.d/issues, there seems to be some issue with interface/class casting and manual class allocation.
Re: Turn function into infinite range
On Monday, 29 September 2014 at 17:02:43 UTC, Martin Nowak wrote: I though I've seen this around somewhere but can no longer find it. AFAIK, this as never existed. We recently merged in "cache" into phobos. This seems like a prime candidate to expand to also take a function/delegate, as on of its built-in feature is that the value of "front" is not changed until "popFront()" is called. Having it also accept a function/delegate would make sense. The issue with *not* having that is that a "dumb" adapter would fail the: r.front == r.front Test. And I'm pretty sure this test is expected to pass, even for the so called "transient" ranges. I think I'll get to it now (this week). Thoughts?
Re: out parameter with default value
I had just forget out and ref are same as pointers... thanks guys
find all public properties at compile time
Hi, There is a way to determine all public properties (not methods) from a struct/class at compile time? I seen that there are traits to get only methods but not properties. Am I wrong? thanks, Bogdan
Re: Turn function into infinite range
V Mon, 29 Sep 2014 19:02:36 +0200 Martin Nowak via Digitalmars-d-learn napsáno: > Does anyone know a construct to turn a lambda into an infinite range. > > import std.random; > > unittest > { > Random gen; > foreach(v; xxx!(() => uniform(0, 100, gen)).take(10)) > writeln(v); > } > > I though I've seen this around somewhere but can no longer find it. http://dlang.org/phobos/std_range.html#.Repeat ?
Re: Turn function into infinite range
On Monday, 29 September 2014 at 20:02:19 UTC, monarch_dodra wrote: I think I'll get to it now (this week). I threw something together, and it really works exceptionally well. Will file PR soon.
Re: Turn function into infinite range
On Monday, 29 September 2014 at 21:16:27 UTC, Daniel Kozák via Digitalmars-d-learn wrote: V Mon, 29 Sep 2014 19:02:36 +0200 Martin Nowak via Digitalmars-d-learn napsáno: Does anyone know a construct to turn a lambda into an infinite range. import std.random; unittest { Random gen; foreach(v; xxx!(() => uniform(0, 100, gen)).take(10)) writeln(v); } I though I've seen this around somewhere but can no longer find it. http://dlang.org/phobos/std_range.html#.Repeat ? That just repeats the value, but doesn't re-evaluate the value on every call to front/popFront.
Re: vibe.d https_server example fails
On Monday, 29 September 2014 at 18:37:28 UTC, Martin Nowak wrote: Please report it https://github.com/rejectedsoftware/vibe.d/issues, there seems to be some issue with interface/class casting and manual class allocation. This time I got: Handling of connection failed: Failed to accept SSL tunnel: (336027804) Handling of connection failed: Failed to accept SSL tunnel: fPu: (336027804) Handling of connection failed: Failed to accept SSL tunnel: fPu: (336027804) Error executing command run: Program exited with code -11 I know nothing about https. Do I have to tell my browser about certificates?
Re: vibe.d https_server example fails
Yes, the ssl_stream should be defined outside the if clause. The FreeLostRef refcount goes to 0 when it goes out of scope in http/server.d On Monday, 29 September 2014 at 21:39:03 UTC, Nordlöw wrote: On Monday, 29 September 2014 at 18:37:28 UTC, Martin Nowak wrote: Please report it https://github.com/rejectedsoftware/vibe.d/issues, there seems to be some issue with interface/class casting and manual class allocation. This time I got: Handling of connection failed: Failed to accept SSL tunnel: (336027804) Handling of connection failed: Failed to accept SSL tunnel: fPu: (336027804) Handling of connection failed: Failed to accept SSL tunnel: fPu: (336027804) Error executing command run: Program exited with code -11 I know nothing about https. Do I have to tell my browser about certificates?
Re: Localizing a D application - best practices?
On Sunday, 28 September 2014 at 21:29:21 UTC, Cliff wrote: Coming from the C# world, all of localization we did was based on defining string resource files (XML-formatted source files which were translated into C# classes with named-string accessors by the build process) that would get included in the final application. For log messages, exception messages (because unhandled exceptions could make it to the user in the case of a bug) and format strings used for the above we would create a string table entry and this file would eventually get localized by the appropriate team. Is there a recommended pattern for applications in D that wish to do localization? Thanks. I don't know. But JSON is very popular in the D community. dub, the package manager uses it for configuration files, I use JSON for the same purpose in my applications. Although the present std.json is not up to current D standards (still?), it is perfectly usable. Alternatively you can have a look at vibe.d's implementation (http://vibed.org/api/vibe.data.json/) which I use in vibe.d apps. I do not recommend XML, not only because it may be overkill for localization, but because the std.xml module should have been put down a long time ago. If you do want to use XML, however, you may have a look at Adam D. Ruppe's dom.d[1][2]. In the D community JSON is usually preferred to XML. [1] https://github.com/adamdruppe/HTML-DOM [2] https://github.com/adamdruppe/arsd
Re: vibe.d https_server example fails
On 09/29/2014 11:41 PM, Etienne wrote: Yes, the ssl_stream should be defined outside the if clause. The FreeLostRef refcount goes to 0 when it goes out of scope in http/server.d Well, how about a pull then? https://github.com/rejectedsoftware/vibe.d/issues/846
Re: Localizing a D application - best practices?
On Sunday, 28 September 2014 at 21:29:21 UTC, Cliff wrote: Coming from the C# world, all of localization we did was based on defining string resource files (XML-formatted source files which were translated into C# classes with named-string accessors by the build process) that would get included in the final application. For log messages, exception messages (because unhandled exceptions could make it to the user in the case of a bug) and format strings used for the above we would create a string table entry and this file would eventually get localized by the appropriate team. Is there a recommended pattern for applications in D that wish to do localization? Thanks. I personally recommend you do this --- void main(){ string name=import("mylang"); } --- and add a folder with mylang with -J . eg: -Jenglish -Jspanish
Re: is there any reason UFCS can't be used with 'new'?
On Sunday, 28 September 2014 at 22:17:03 UTC, Meta wrote: I'm not sure. Maybe it's on the same level as the Lambda Abstraction (14.5), but you'll probably have to do some testing to figure it out exactly. precedence levels seem to be defined in `src/parse.h` (the `PREC` enum) and assigned to operators in `src/parse.c` (`initPrecedence()`).
Re: out parameter with default value
On Mon, 29 Sep 2014 20:22:41 + AsmMan via Digitalmars-d-learn wrote: > I had just forget out and ref are same as pointers... thanks guys yeah, that syntactic sugar can be confusing sometimes. ;-) signature.asc Description: PGP signature
Interfacing with webcam
Hi, Has anyone successfully used D to capture images from a webcam? Something like what you can do with OpenCV or pygame's camera API? Any idea how I can do this without having to know a lot of complex stuff? Thanks!
Re: multidimensional array
Thanks JKPdouble. I was hoping for a clear way to work multidimensional arrays out.