Re: Algebraic changing type when in associative array

2020-02-04 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 5 February 2020 at 01:06:46 UTC, rous wrote: This is an example program that illustrates the issue: import std.variant: Algebraic, This; import std.stdio: writeln; alias Foo = Algebraic!(This[], int); void main() { Foo x = 5; Foo y = 10; Foo z = [x,y]; pragma(msg,

Re: Algebraic changing type when in associative array

2020-02-04 Thread rous via Digitalmars-d-learn
On Tuesday, 4 February 2020 at 12:05:16 UTC, rikki cattermole wrote: On 05/02/2020 12:55 AM, rous wrote: On Tuesday, 4 February 2020 at 11:47:49 UTC, rikki cattermole wrote: It did not change type. "Algebraic data type restricted to a closed set of possible types. It's an alias for VariantN

Re: vibe.d no routes match path

2020-02-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/4/20 10:35 AM, seany wrote:     router.post("/archive", );     router.get("/archive", ); //also tested without this line [snip] Internal error information: No routes match path '/a' Did you go to /a? Looks like you only registered routes for /archive. -Steve

Re: dub for lib & app?

2020-02-04 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 4 February 2020 at 19:21:07 UTC, mark wrote: Ah, thank you. And if I'm doing *separate* individual projects, for an app, dub creates source/app.d (which I rename src/app.d). But what should it be for a library? Should it be src/package.d along with any supporting src/one.d

Re: dub for lib & app?

2020-02-04 Thread mark via Digitalmars-d-learn
On Tuesday, 4 February 2020 at 09:21:17 UTC, Andre Pany wrote: On Tuesday, 4 February 2020 at 09:13:48 UTC, mark wrote: Is it possible to create a dub project that has one library and one or more executables (that use the library)? If so, could someone point me to the docs for this since I

Re: vibe.d no routes match path

2020-02-04 Thread seany via Digitalmars-d-learn
* sorry, i meant 'archive' This is a production server. Is there anything i am doing wrong?

vibe.d no routes match path

2020-02-04 Thread seany via Digitalmars-d-learn
Please consider the code: import vibe.vibe; import std.conv; import std.file; import std.stdio; ushort port = 5502; void main(char[][] args) { auto router = new URLRouter; router.post("/archive", ); router.get("/archive", ); //also tested without this line

Re: Algebraic changing type when in associative array

2020-02-04 Thread rikki cattermole via Digitalmars-d-learn
On 05/02/2020 2:11 AM, Paul Backus wrote: On Tuesday, 4 February 2020 at 11:45:50 UTC, rous wrote: I'm defining an Algebraic type like this: alias Expr = Algebraic!(This[char], string, int); However, when I create an Expr from an associative array of chars and Exprs, the Exprs seem to change

Re: Algebraic changing type when in associative array

2020-02-04 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 4 February 2020 at 11:45:50 UTC, rous wrote: I'm defining an Algebraic type like this: alias Expr = Algebraic!(This[char], string, int); However, when I create an Expr from an associative array of chars and Exprs, the Exprs seem to change from Algebraic to VariantN!32LU types. This

Re: Algebraic changing type when in associative array

2020-02-04 Thread rikki cattermole via Digitalmars-d-learn
On 05/02/2020 12:55 AM, rous wrote: On Tuesday, 4 February 2020 at 11:47:49 UTC, rikki cattermole wrote: It did not change type. "Algebraic data type restricted to a closed set of possible types. It's an alias for VariantN with an appropriately-constructed maximum size."

Re: Algebraic changing type when in associative array

2020-02-04 Thread rous via Digitalmars-d-learn
On Tuesday, 4 February 2020 at 11:47:49 UTC, rikki cattermole wrote: It did not change type. "Algebraic data type restricted to a closed set of possible types. It's an alias for VariantN with an appropriately-constructed maximum size." https://dlang.org/phobos/std_variant.html#.Algebraic

Algebraic changing type when in associative array

2020-02-04 Thread rous via Digitalmars-d-learn
I'm defining an Algebraic type like this: alias Expr = Algebraic!(This[char], string, int); However, when I create an Expr from an associative array of chars and Exprs, the Exprs seem to change from Algebraic to VariantN!32LU types. This is illustrated in the following error message: cannot

Re: Algebraic changing type when in associative array

2020-02-04 Thread rikki cattermole via Digitalmars-d-learn
It did not change type. "Algebraic data type restricted to a closed set of possible types. It's an alias for VariantN with an appropriately-constructed maximum size." https://dlang.org/phobos/std_variant.html#.Algebraic

Re: const pointers C vs. D

2020-02-04 Thread Dennis via Digitalmars-d-learn
On Tuesday, 4 February 2020 at 10:06:03 UTC, Johann Lermer wrote: In C, this would not be valid. So the question for me now is: is const char* in D different from C? Yes, const char* in D reads as const(char*), so it is a char* that cannot be modified. This is similar to the C code: char

const pointers C vs. D

2020-02-04 Thread Johann Lermer via Digitalmars-d-learn
Hi, I'm just wondering about defining const pointers and if there's a difference in C and D. in C, this works: const char* text = "Hello"; text = "world"; but in D it doesn't, because the char* is const. Ff I would like tho have the same behaviour in D as in C, I need to write: const

Re: dub for lib & app?

2020-02-04 Thread Andre Pany via Digitalmars-d-learn
On Tuesday, 4 February 2020 at 09:13:48 UTC, mark wrote: Is it possible to create a dub project that has one library and one or more executables (that use the library)? If so, could someone point me to the docs for this since I couldn't find this in the dub docs? Aside: I'm learning D to

dub for lib & app?

2020-02-04 Thread mark via Digitalmars-d-learn
Is it possible to create a dub project that has one library and one or more executables (that use the library)? If so, could someone point me to the docs for this since I couldn't find this in the dub docs? Aside: I'm learning D to give me something approaching the convenience of Python with

Re: Empty string vs null

2020-02-04 Thread mark via Digitalmars-d-learn
Thanks for that thorough and careful explanation. Since I'm trying to learn to write D in good style and want my code to be reliable and maintainable, I've now switched to using "" rather than null.

Re: Assoc array init

2020-02-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, February 4, 2020 12:52:05 AM MST JN via Digitalmars-d-learn wrote: > int[int] a = [5: 7]; > > void main() > { > } > > > This fails because apparently [5: 7] is a "non-const expression". > How? Why? > > Yes, I know I can just init in a static this() section, but that > feels like a bad

Re: Assoc array init

2020-02-04 Thread Boris Carvajal via Digitalmars-d-learn
On Tuesday, 4 February 2020 at 07:52:05 UTC, JN wrote: int[int] a = [5: 7]; void main() { } This fails because apparently [5: 7] is a "non-const expression". How? Why? Yes, I know I can just init in a static this() section, but that feels like a bad workaround. AFAIK is not implemented.

Re: Empty string vs null

2020-02-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, February 4, 2020 12:33:42 AM MST mark via Digitalmars-d-learn wrote: > I have just discovered that D seems to treat empty and null > strings as the same thing: > > // test.d > import std.stdio; > import std.string; > void main() > { > string x = null; > writeln("x = \"",