Re: Non-blocking keyboard input

2024-01-14 Thread Joe--- via Digitalmars-d-learn
On Wednesday, 27 December 2023 at 13:27:53 UTC, Adam D Ruppe wrote: On Wednesday, 27 December 2023 at 05:07:04 UTC, Joe wrote: ??? Surely there there is a one liner library solution for this? It is not one line because it needs a bit of setup (and

Non-blocking keyboard input

2023-12-26 Thread Joe--- via Digitalmars-d-learn
??? Surely there there is a one liner library solution for this? I have a program that spawns a thread for debugging information and uses the keyboard input which allows me to display the information. If I use getchar or readline then it blocks the

D atomics

2023-12-18 Thread Joe--- via Digitalmars-d-learn
How does one really use atomics in D? shared string[int] AA; AA[s[2]].atomicStore(s[1]); causes a hangup. If I just assign it "works": AA[s[2]] = s[1]; I've had similar issues where: atomicOp!"+="(X[Y],1); fails and I have to use X[Y].atomicStore(1); or

Re: range shortened method not enabled, compile with compiler switch `-preview=shortenedMethods`

2023-09-24 Thread Joe--- via Digitalmars-d-learn
On Sunday, 24 September 2023 at 12:59:57 UTC, Steven Schveighoffer wrote: On Sunday, 24 September 2023 at 10:00:31 UTC, Joe wrote: For absolutely no reason I started getting this error. Last night I compiled the project and it worked just fine. This morning I made a single insignificant

Re: Vibe.d download function, how to get callback when done or error?

2023-09-24 Thread Joe--- via Digitalmars-d-learn
On Saturday, 23 September 2023 at 20:20:31 UTC, Christian Köstlin wrote: On 23.09.23 14:07, j...@bloow.edu wrote: I'm using download(url, filename) to download files in vibe.d. The issue is that I do not know when the download is finished or errors. There is a callback for the streaming side

Re: Vibe.d download function, how to get callback when done or error?

2023-09-24 Thread Joe--- via Digitalmars-d-learn
On Saturday, 23 September 2023 at 15:09:13 UTC, Elias wrote: On Saturday, 23 September 2023 at 12:07:38 UTC, Joe wrote: I'm using download(url, filename) to download files in vibe.d. The issue is that I do not know when the download is finished or errors. There is a callback for the streaming

range shortened method not enabled, compile with compiler switch `-preview=shortenedMethods`

2023-09-24 Thread Joe--- via Digitalmars-d-learn
For absolutely no reason I started getting this error. Last night I compiled the project and it worked just fine. This morning I made a single insignificant change and tried to compile and got that error. Only possible thing is that for some reason some change in updating the compiler may

Vibe.d download function, how to get callback when done or error?

2023-09-23 Thread Joe--- via Digitalmars-d-learn
I'm using download(url, filename) to download files in vibe.d. The issue is that I do not know when the download is finished or errors. There is a callback for the streaming side but not for the file download.

Re: Help on array pointers

2023-09-22 Thread Joe--- via Digitalmars-d-learn
On Monday, 18 September 2023 at 02:49:37 UTC, vino wrote: On Sunday, 17 September 2023 at 18:28:36 UTC, Joe wrote: On Friday, 15 September 2023 at 16:55:34 UTC, Vino wrote: [...] [...] char[] invalid = (cast(char*)malloc(char.sizeof * len))[0..len]; This is not the way to go about it.

Re: Help on array pointers

2023-09-17 Thread Joe--- via Digitalmars-d-learn
On Friday, 15 September 2023 at 16:55:34 UTC, Vino wrote: On Friday, 15 September 2023 at 15:27:00 UTC, Vino wrote: On Friday, 15 September 2023 at 02:25:09 UTC, Joe wrote: On Thursday, 14 September 2023 at 14:21:09 UTC, Vino wrote: [...] A pointer is a type that points to something. It's

Re: Help on array pointers

2023-09-14 Thread Joe--- via Digitalmars-d-learn
On Thursday, 14 September 2023 at 14:21:09 UTC, Vino wrote: Hi All, Request your help to guide me in understanding about pointers, the below code works,I have few question which i need your help for better understanding. Questions:1 ``` char[] invalid = (cast(char*)malloc(char.sizeof *

Re: parallel threads stalls until all thread batches are finished.

2023-08-29 Thread Joe--- via Digitalmars-d-learn
On Monday, 28 August 2023 at 22:43:56 UTC, Ali Çehreli wrote: On 8/28/23 15:37, j...@bloow.edu wrote: > Basically everything is hard coded to use totalCPU's parallel() is a function that dispatches to a default TaskPool object, which uses totalCPUs. It's convenient but as you say, not all

Re: parallel threads stalls until all thread batches are finished.

2023-08-28 Thread Joe--- via Digitalmars-d-learn
On Monday, 28 August 2023 at 10:33:15 UTC, Christian Köstlin wrote: On 26.08.23 05:39, j...@bloow.edu wrote: On Friday, 25 August 2023 at 21:31:37 UTC, Ali Çehreli wrote: On 8/25/23 14:27, j...@bloow.edu wrote: > "A work unit is a set of consecutive elements of range to be processed > by a

Re: parallel threads stalls until all thread batches are finished.

2023-08-25 Thread Joe--- via Digitalmars-d-learn
On Friday, 25 August 2023 at 21:43:26 UTC, Adam D Ruppe wrote: On Wednesday, 23 August 2023 at 13:03:36 UTC, Joe wrote: to download files from the internet. Are they particularly big files? You might consider using one of the other libs that does it all in one thread. (i ask about size cuz

Re: parallel threads stalls until all thread batches are finished.

2023-08-25 Thread Joe--- via Digitalmars-d-learn
On Friday, 25 August 2023 at 21:31:37 UTC, Ali Çehreli wrote: On 8/25/23 14:27, j...@bloow.edu wrote: > "A work unit is a set of consecutive elements of range to be processed > by a worker thread between communication with any other thread. The > number of elements processed per work unit is

Re: parallel threads stalls until all thread batches are finished.

2023-08-25 Thread Joe--- via Digitalmars-d-learn
On Wednesday, 23 August 2023 at 14:43:33 UTC, Sergey wrote: On Wednesday, 23 August 2023 at 13:03:36 UTC, Joe wrote: I use foreach(s; taskPool.parallel(files, numParallel)) { L(s); } // L(s) represents the work to be done. If you make for example that L function return “ok” in case file

Re: parallel threads stalls until all thread batches are finished.

2023-08-25 Thread Joe--- via Digitalmars-d-learn
On Wednesday, 23 August 2023 at 14:43:33 UTC, Sergey wrote: On Wednesday, 23 August 2023 at 13:03:36 UTC, Joe wrote: I use foreach(s; taskPool.parallel(files, numParallel)) { L(s); } // L(s) represents the work to be done. If you make for example that L function return “ok” in case file

parallel threads stalls until all thread batches are finished.

2023-08-23 Thread Joe--- via Digitalmars-d-learn
I use foreach(s; taskPool.parallel(files, numParallel)) { L(s); } // L(s) represents the work to be done. to download files from the internet. Everything works. The issue is this: the foreach will download 8 files at once. BUT it will not start the next batch of 8 *until* ALL of the previous

Re: Code organization, dub, etc.

2023-03-13 Thread Joe via Digitalmars-d-learn
On Monday, 13 March 2023 at 13:58:29 UTC, Adam D Ruppe wrote: I'm not particularly interested in defending dub - i consider it a useless piece of crap that I only suffer through cuz some users demanded it For the record, I wasn't trying to attack dub (or dfmt). I was more interested in

Re: Code organization, dub, etc.

2023-03-13 Thread Joe via Digitalmars-d-learn
On Monday, 13 March 2023 at 13:32:04 UTC, Mike Parker wrote: The package registry is full of libraries, yes. That's what it's primarily for. There aren't a lot of executables uploaded there because they're usually better distributed in other ways. But plenty of people are using dub to build

Re: Code organization, dub, etc.

2023-03-13 Thread Joe via Digitalmars-d-learn
On Monday, 13 March 2023 at 12:56:57 UTC, Bradley Chatha wrote: For better or for worse we're stuck with dub as the standard package manager + build tool one-in-all for most of our open source libraries. Yeah, it seems like it's *only* for libraries (and a few single-exe utilities). Looking

Re: Passing and returning arguments by ref

2023-03-03 Thread Joe via Digitalmars-d-learn
Thanks, Ali. On Friday, 3 March 2023 at 18:09:01 UTC, Ali Çehreli wrote: Think may be due to D not having reference variables. Sometimes one needs to use pointers. Ah! I'm about five chapters away from Pointers ;-). Actually, I had tried changing B.x1() to: `ref X x1() { return [0]; }`

Passing and returning arguments by ref

2023-03-03 Thread Joe via Digitalmars-d-learn
Let's say we have two classes, A and B. The latter has a dynamic array of X and type X has an add() method that can be used to append elements (of type C, another struct) to X's own dynamic array of C. So it's something like the following: ```d struct C {} struct X { C[] cs; void add(C c)

std.math log and family

2018-10-30 Thread Joe via Digitalmars-d-learn
I've discovered that the 'log' function as well several similar functions are only defined as taking a real argument and returning a real, unlike most other std.math functions, which have triple definitions (also supporting double and float types). This created a problem when I tried compiling

Re: Dlang tour - Unittesting example

2018-10-02 Thread Joe via Digitalmars-d-learn
On Tuesday, 2 October 2018 at 13:24:09 UTC, Basile B. wrote: The problem is the NaN madness. Since several values are NaN there's this strange stuff: void main() { import std.stdio; import std.math : isNaN; double d; writeln(d.init);// nan writeln(d); // nan

Re: Dlang tour - Unittesting example

2018-10-02 Thread Joe via Digitalmars-d-learn
On Tuesday, 2 October 2018 at 12:25:19 UTC, Joe wrote: On Tuesday, 2 October 2018 at 09:59:28 UTC, bauss wrote: On Tuesday, 2 October 2018 at 04:13:01 UTC, Joe wrote: There appears to be a problem with the example at https://tour.dlang.org/tour/en/gems/unittesting If compiled with -unittest,

Re: Dlang tour - Unittesting example

2018-10-02 Thread Joe via Digitalmars-d-learn
On Tuesday, 2 October 2018 at 09:59:28 UTC, bauss wrote: On Tuesday, 2 October 2018 at 04:13:01 UTC, Joe wrote: There appears to be a problem with the example at https://tour.dlang.org/tour/en/gems/unittesting If compiled with -unittest, the resulting program crashes. It happens with ldc2 on

Dlang tour - Unittesting example

2018-10-01 Thread Joe via Digitalmars-d-learn
There appears to be a problem with the example at https://tour.dlang.org/tour/en/gems/unittesting If compiled with -unittest, the resulting program crashes. It happens with ldc2 on Linux but it can also be seen if you click on "Export" and run it with dmd -unittest.

Re: Access to structures defined in C

2018-09-18 Thread Joe via Digitalmars-d-learn
On Tuesday, 18 September 2018 at 13:47:50 UTC, Atila Neves wrote: On Tuesday, 18 September 2018 at 02:39:39 UTC, Joe wrote: The second type is like that shown above. The first is a simpler array of pointers to int, e.g., int *yp = {2, 4, 0}; int *yq = {10, 12, 0}; This is valid C in the

Re: Access to structures defined in C

2018-09-17 Thread Joe via Digitalmars-d-learn
On Sunday, 10 June 2018 at 17:59:12 UTC, Joe wrote: That worked but now I have a more convoluted case: a C array of pointers to int pointers, e.g., int **xs[] = {x1, x2, 0}; int *x1[] = {x1a, 0}; int *x2[] = {x2a, x2b, 0}; ... int x2a[] = { 1, 3, 5, 0}; Only the first line is exposed (and

Re: Linking a C program with D library

2018-08-15 Thread Joe via Digitalmars-d-learn
On Wednesday, 15 August 2018 at 06:39:50 UTC, Mike Parker wrote: String literals are implicitly convertible to const(char)* and are guaranteed to be nul-terminated like a C string, so this works: [...] Does that help? Yes, indeed. I think I possibly read about literal strings being

Re: Linking a C program with D library

2018-08-14 Thread Joe via Digitalmars-d-learn
On Wednesday, 15 August 2018 at 01:56:34 UTC, Mike Parker wrote: The correct thing to do is to keep the original C function signatures in the converted code, i.e. don't change char* to string[]. And don't use anything from Phobos internally that requires linking. In other words, treat your

Linking a C program with D library

2018-08-14 Thread Joe via Digitalmars-d-learn
I'm attempting a piecemeal conversion of some C programs. I've converted a few that depend on C modules that are in a library and now I'm sort of in the middle of converting those C modules. One of them has an array of strings, i.e., array of char*, which most easily translated to D's

?? How to subscribe to Multicast Broadcasts ??

2018-08-12 Thread Joe via Digitalmars-d-learn
Hello All! I've been trying every possible combination and cannot get anything working. (>_<) This is I think the closest I've got, I think the problem may be with the 3 argument. I'm not sure how to join the Multicast IP membership? (this code currently does not work - throws error:

How the Heck Do I Subscribe to Receiving Multicast Messages Broadcast to Organization's IP ??

2018-08-10 Thread Joe via Digitalmars-d
Hello All! I've been trying every possible combination and cannot get anything working. (>_<) This is I think the closest I've got, I think the problem may be with the 3 argument. I'm not sure how to join the Multicast IP membership? (this code currently does not work - throws error:

Re: How to call a C function from D that takes a FILE * as an argument?

2018-07-03 Thread Joe via Digitalmars-d-learn
On Wednesday, 4 July 2018 at 02:16:00 UTC, Seb wrote: Hmm, calling e.g. fprintf with stdout should just work: --- void main() { import core.stdc.stdio; fprintf(stdout, "Hello %s", "world".ptr); } --- Could you maybe provide your whole code? This short test program shows the error:

Re: How to call a C function from D that takes a FILE * as an argument?

2018-07-03 Thread Joe via Digitalmars-d-learn
On Wednesday, 4 July 2018 at 01:58:15 UTC, Seb wrote: So just add the declaration to your D file: --- extern(C) void myCfunction(FILE* stream); --- I do have a similar declaration in D. It appears the problem is that the C program I'm trying to convert passes stdout as the argument and the

How to call a C function from D that takes a FILE * as an argument?

2018-07-03 Thread Joe via Digitalmars-d-learn
The subject basically says it all. The C function uses the argument to call fprintf and also passes it to other functions where it's used to call fileno, fprintf or putc.

Re: Access to structures defined in C

2018-06-10 Thread Joe via Digitalmars-d-learn
On Sunday, 10 June 2018 at 17:59:12 UTC, Joe wrote: That worked but now I have a more convoluted case: a C array of pointers to int pointers, e.g., int **xs[] = {x1, x2, 0}; int *x1[] = {x1a, 0}; int *x2[] = {x2a, x2b, 0}; ... int x2a[] = { 1, 3, 5, 0}; Only the first line is exposed (and

Re: Access to structures defined in C

2018-06-10 Thread Joe via Digitalmars-d-learn
On Wednesday, 14 March 2018 at 02:17:57 UTC, Adam D. Ruppe wrote: The type system would *like* to know, certainly for correct range errors, but if you declare it as the wrong length and use the .ptr, it still works like it does in C: extern(C) __gshared extern char*[1] files; // still works

Re: unittests, dub and libraries

2018-03-27 Thread Joe via Digitalmars-d-learn
On Wednesday, 28 March 2018 at 03:07:23 UTC, Jonathan M Davis wrote: Run dub test The problem is that an executable needs a main, and a library doesn't have one, whereas when you're testing a library, you need an executable. So, a main must be inserted - e.g. with the -main flag to dmd.

unittests, dub and libraries

2018-03-27 Thread Joe via Digitalmars-d-learn
I'm trying to build a very simple library. For now it just has a single class, constructor, destructor and one method. I added a unit test right after the method, declared the targetType to be "library" and a buildType of "unittest" (with options "unittests", "debugMode", "debugInfo"). When I

Re: core.stdc.stdlib._compare_fp_t and qsort

2018-03-18 Thread Joe via Digitalmars-d-learn
On Sunday, 18 March 2018 at 19:01:11 UTC, Joe wrote: I managed to get it working by declaring a D dynamic array, appending n_recs pointers to it and using it as argument to sort. Unfortunately, I then had to copy from the dynamic array to the fixed array in order to continue using the latter.

Re: core.stdc.stdlib._compare_fp_t and qsort

2018-03-18 Thread Joe via Digitalmars-d-learn
On Sunday, 18 March 2018 at 18:11:02 UTC, Dmitry Olshansky wrote: Well since recs is array of pointers this looks like a null pointer in your data. The usual ways to fix that is either print stuff or poke around in debugger to see if a Record* is null or .name is null. The problem is that

Re: core.stdc.stdlib._compare_fp_t and qsort

2018-03-18 Thread Joe via Digitalmars-d-learn
On Sunday, 18 March 2018 at 13:10:08 UTC, Dmitry Olshansky wrote: Do this to get the usual ptr + length: sort!((a, b) => to!string((*a).name) < to!string((*b).name))(recs[]); Also to!string would be computed on each compare anew. May want to use schwartzSort to avoid that, on 10 elements

Re: core.stdc.stdlib._compare_fp_t and qsort

2018-03-18 Thread Joe via Digitalmars-d-learn
On Monday, 12 March 2018 at 03:50:42 UTC, Joe wrote: On Monday, 12 March 2018 at 03:13:08 UTC, Seb wrote: Out of interest: I wonder what's your usecase for using qsort. Or in other words: why you can't use the high-level std.algorithm.sorting.sort? This is only temporary. I will be using

Access to structures defined in C

2018-03-13 Thread Joe via Digitalmars-d-learn
What is the correct way to declare and access storage managed by C? For example, say a C module defines an array of filenames, e.g., char *files[] = { "one", "two", "three", 0}; The C header of course declares this as: extern char *files[]; The way to declare it in a D module appears to be:

Re: core.stdc.stdlib._compare_fp_t and qsort

2018-03-11 Thread Joe via Digitalmars-d-learn
On Monday, 12 March 2018 at 03:13:08 UTC, Seb wrote: Out of interest: I wonder what's your usecase for using qsort. Or in other words: why you can't use the high-level std.algorithm.sorting.sort? This is only temporary. I will be using std.algorithm.sorting.sort. I was converting a C program

Re: core.stdc.stdlib._compare_fp_t and qsort

2018-03-11 Thread Joe via Digitalmars-d-learn
On Monday, 12 March 2018 at 01:45:54 UTC, Adam D. Ruppe wrote: I just reformatted it but now the difference should be visible: `extern(C)` is missing on your callback. The scope things might make a difference too, but I know for sure extern(C) is necessary on your callback function. I saw

Re: core.stdc.stdlib._compare_fp_t and qsort

2018-03-11 Thread Joe via Digitalmars-d-learn
On Sunday, 11 March 2018 at 23:26:04 UTC, Stefan Koch wrote: You have to pass a pointer to the function. Otherwise it'll be a parenthsis-less call. use : qsort(recs, num_recs, (Record *).sizeof, ); After passing a pointer, getting some other error messages, I changed the call to

core.stdc.stdlib._compare_fp_t and qsort

2018-03-11 Thread Joe via Digitalmars-d-learn
I'm getting a compiler error in a qsort() call as follows: qsort(recs, num_recs, (Record *).sizeof, compar); Record is a struct, recs is a fixed array of pointers to Record's and num_recs is a size_t that holds the number of valid records. compar is this: int compar(const void *p1,

Re: Article: Why Const Sucks

2018-03-11 Thread joe via Digitalmars-d-announce
On Thursday, 8 March 2018 at 15:13:09 UTC, Steven Schveighoffer wrote: On 3/8/18 9:58 AM, joe wrote: On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote: Here's something I wrote up on const: /snip May be not entirely related, but a little gotcha. given: interface XY {} class

Re: Article: Why Const Sucks

2018-03-08 Thread joe via Digitalmars-d-announce
On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote: Here's something I wrote up on const: /snip May be not entirely related, but a little gotcha. given: interface XY {} class Foo: XY {} class Bar: XY {} void doSomething(in XY sth) { auto foo = cast(Foo)sth; // error in @safe

Re: Article: Why Const Sucks

2018-03-05 Thread joe via Digitalmars-d-announce
On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote: Here's something I wrote up on const: http://jmdavisprog.com/articles/why-const-sucks.html I suppose that it's not exactly the most positive article, but I feel that it's accurate. - Jonathan M Davis Interesting read and it

Re: Postgres and other database interfaces

2018-02-25 Thread Joe via Digitalmars-d
On Sunday, 25 February 2018 at 16:31:45 UTC, Denis F wrote: What are these sacrifices for? I do not like idea that I should drop some functionality of Postgres for conpatibility with another RDBMSes. Personally, I like specific databases because it have nuances of functionality that they

Re: Postgres and other database interfaces

2018-02-25 Thread Joe via Digitalmars-d
On Sunday, 25 February 2018 at 09:23:18 UTC, rikki cattermole wrote: On IRC earlier today we discussed database libs a bit, we agreed that both "?" and "@name" needed to be supported. No other suggestions came up. We don't really need a third or fourth form I think. "@name"? Which DBMS uses

Re: Postgres and other database interfaces

2018-02-25 Thread Joe via Digitalmars-d
On Sunday, 25 February 2018 at 09:07:34 UTC, Denis F wrote: Libraries already are similar automatically because RDBMSes uses similar principles. But it is impossible to make libraries absolutely identical due to the presence of important significant nuances in each engine. I don't see how

Re: Postgres and other database interfaces

2018-02-24 Thread Joe via Digitalmars-d
On Saturday, 24 February 2018 at 23:04:39 UTC, Denis F wrote: If anyone really want to impliment your idea, at my first glance at the PEP 249 I had a feeling that this is work for time less than a 1-2 weeks. It can be a simple wrapper over dpq2, mysql-native, sqlite3, etc. I'm not saying

Re: Postgres and other database interfaces

2018-02-24 Thread Joe via Digitalmars-d
On Saturday, 24 February 2018 at 18:56:23 UTC, Denis F wrote: It seems to me that this is a common misconception that it is possible to create a good universal tool for accessing the database in place of the many existing ones. I don't think what is needed a "good universal tool" but a good

Re: Postgres and other database interfaces

2018-02-24 Thread Joe via Digitalmars-d
On Saturday, 24 February 2018 at 18:41:21 UTC, Denis F wrote: On Saturday, 24 February 2018 at 05:33:56 UTC, Joe wrote: 2. dpq2. Second most downloaded and built on top of derelict-pq. The "documentation" consists of a README listing the features and a single example, which appears to focus

Re: Postgres and other database interfaces

2018-02-24 Thread Joe via Digitalmars-d
On Saturday, 24 February 2018 at 15:44:49 UTC, Paolo Invernizzi wrote: Joe: I think this is also a terrific 'welcome aboard' about how fast and quickly things can be done in D! I'm a bit overwhelmed by all the replies and "goodies" but I'd like to say thanks to Adam while I digest it all.

Re: Postgres and other database interfaces

2018-02-24 Thread Joe via Digitalmars-d
On Saturday, 24 February 2018 at 10:13:35 UTC, Paolo Invernizzi wrote: Have you tried to generate the documentation? Look for example inside the source files... https://github.com/pszturmaj/ddb/blob/bd55beea0df6e5da86a71535ff6d9800c0711c7c/source/ddb/postgres.d#L2

Postgres and other database interfaces

2018-02-23 Thread Joe via Digitalmars-d
Back on 13 January, I posted in the Learn forum some questions regarding using Postgres and got a reply that stated the following: On Monday, 15 January 2018 at 02:28:29 UTC, Matthias Klumpp wrote: In any case, please don't start another Postgres library and consider contributing to one of

Re: Understanding the AST...

2018-02-22 Thread joe via Digitalmars-d-learn
On Thursday, 22 February 2018 at 14:53:11 UTC, Seb wrote: On Tuesday, 6 February 2018 at 12:03:06 UTC, joe wrote: Hello everybody! Last week end I found this post ( https://dlang.org/blog/2017/08/01/a-dub-case-study-compiling-dmd-as-a-library/ ) on the Blog and thought to myself awesome.

Re: Understanding the AST...

2018-02-22 Thread joe via Digitalmars-d-learn
On Thursday, 22 February 2018 at 13:44:51 UTC, RazvanN wrote: On Thursday, 22 February 2018 at 13:21:04 UTC, joe wrote: [...] Indeed, @Stefan is right. The ParseTimeVisitor only contains information available at parse time. If you are interested in the parent you have 2 options: either (1)

Re: Negative index range violation

2018-02-22 Thread joe via Digitalmars-d-learn
On Thursday, 22 February 2018 at 02:41:30 UTC, Steven Schveighoffer wrote: On 2/21/18 7:30 PM, SrMordred wrote: But with a slice negative indexes are never allowed, even on a pointer. youd have to do (c-1)[0 .. 1]; Nice! Thank you both! In D Slice article it says "You can even use

Re: Understanding the AST...

2018-02-22 Thread joe via Digitalmars-d-learn
On Monday, 12 February 2018 at 08:47:58 UTC, RazvanN wrote: Hi Joe, /SNIP On Tuesday, 6 February 2018 at 12:03:06 UTC, joe wrote: [...] The FuncDeclaration node contains all the information for that. For example, you can access fd.parent to see if the function is declared at top-level (in

Re: Understanding the AST...

2018-02-22 Thread joe via Digitalmars-d-learn
On Monday, 12 February 2018 at 08:47:58 UTC, RazvanN wrote: Hi Joe, I suggest you watch this video which explains how the parse time visitors work: https://www.youtube.com/watch?v=tK072jcoWv4 . On Tuesday, 6 February 2018 at 12:03:06 UTC, joe wrote: [...] The FuncDeclaration node

Re: dub segfault

2018-02-10 Thread Joe via Digitalmars-d
On Sunday, 11 February 2018 at 00:59:10 UTC, Seb wrote: Ideally you could verify whether this also happens with the official release. Installing the official (ldc) release doesn't cause the problem, so presumably this is a problem with the Debian buster release. However, I notice the

dub segfault

2018-02-10 Thread Joe via Digitalmars-d
I'm getting a segmentation fault when I run 'dub build' and I specify a dependency. Specifically, the dependency is 'derelict-pq' but it could be anything (I tried 'dpq2' and even 'mysql-native', just for kicks). The segfault occurs when it's supposedly searching for the dependency. Here's

Understanding the AST...

2018-02-06 Thread joe via Digitalmars-d-learn
Hello everybody! Last week end I found this post ( https://dlang.org/blog/2017/08/01/a-dub-case-study-compiling-dmd-as-a-library/ ) on the Blog and thought to myself awesome. So I built the library and everything went smooth. Thanks for the effort of all the involved people who made that

Further questions on interfacing to Postgres libpq

2018-01-26 Thread Joe via Digitalmars-d-learn
An example test program that I'm using to learn D to C interfacing (specifically calling the libpq library) has a call to a C function declared as follows: void PQprint(FILE *fout, /* output stream */ const PGresult *res, const PQprintOpt *po);

Re: Using Postgres connection functions

2018-01-20 Thread Joe via Digitalmars-d-learn
On Saturday, 20 January 2018 at 04:54:47 UTC, Adam D. Ruppe wrote: Same as above. The general pattern is: C_Type[] name = new C_Type[](requested_size); // pass as `name.ptr`. This becomes a C_Type* Thanks, Adam. Perhaps something like this ought to make its way into the "D for C Programmers"

Re: Using Postgres connection functions

2018-01-19 Thread Joe via Digitalmars-d-learn
On Saturday, 13 January 2018 at 05:28:17 UTC, Joe wrote: Going beyond the connection, there are various other libpq functions that use a similar pattern of values passed using multiple parallel C arrays, e.g., PGresult *PQexecParams(PGconn *conn, const char *command,

Re: Using Postgres connection functions

2018-01-15 Thread Joe via Digitalmars-d-learn
On Monday, 15 January 2018 at 02:28:29 UTC, Matthias Klumpp wrote: In any case, please don't start another Postgres library and consider contributing to one of the existing ones, so that we maybe have one really awesome, 100% complete library at some point. If, on the other hand, your goal

Re: Using Postgres connection functions

2018-01-13 Thread Joe via Digitalmars-d-learn
On Saturday, 13 January 2018 at 10:10:41 UTC, Jacob Carlborg wrote: There's a native D library, ddb [1], for connecting to Postgres. Then you don't have to worry about null-terminated strings. There are several D libraries that I would consider "native": derelict-pq, dpq, dpq2 and ddb. The

Re: Using Postgres connection functions

2018-01-12 Thread Joe via Digitalmars-d-learn
Going beyond the connection, there are various other libpq functions that use a similar pattern of values passed using multiple parallel C arrays, e.g., PGresult *PQexecParams(PGconn *conn, const char *command, int nParams,

Re: Using Postgres connection functions

2018-01-12 Thread Joe via Digitalmars-d-learn
On Saturday, 13 January 2018 at 04:26:06 UTC, Adam D. Ruppe wrote: If and only if the values are known at compile time, you can do: const char** keywords = ["hostaddr".ptr, "port".ptr, "dbname".ptr, null].ptr; or even do it inline: PQconnectdbParams(["hostaddr".ptr, "port".ptr,

Using Postgres connection functions

2018-01-12 Thread Joe via Digitalmars-d-learn
I'm trying to learn how to use D to connect (and send queries) to Postgres, i.e., libpq in C. Postgres has three families of connection functions: PQsetdbLogin which takes multiple individual arguments (all as const char *), PQconnectdb which takes a single connection string (which Postgres