Re: Temporary @trusted scope

2018-12-18 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 10:14:50 UTC, Per Nordlöw wrote: What's the preferred way of creating a temporary @trusted scope without writing a separate function? Jonathan's idea might also be encapsulated in a function, just like assumeUnique in Phobos: import std.stdio; template

Checking if CTFE is used?

2018-12-18 Thread berni via Digitalmars-d-learn
Is there a way to check if a function is indeed executed at compile time or not? (Other than going through the whole executable binaries...) I tried static this() { if (__ctfe) pragma(msg,"works"); // some other stuff } but unfortunatley this "if" is also executed at compile time,

Re: Reverse and sort array elements

2018-12-18 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 12:07:37 UTC, Andrey wrote: Hi, Have array: enum array = ["qwerty", "a", "baz"]; Need to reverse and sort array elements to get this result: [a, ytrewq, zab] Did this: enum result = array.map!(value => value.retro()).sort(); Got: Error: template

Re: Reverse and sort array elements

2018-12-18 Thread angel via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 12:07:37 UTC, Andrey wrote: Hi, Have array: enum array = ["qwerty", "a", "baz"]; Need to reverse and sort array elements to get this result: [a, ytrewq, zab] Did this: enum result = array.map!(value => value.retro()).sort(); Got: Error: template

Re: Temporary @trusted scope

2018-12-18 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 10:42:51 UTC, Jonathan M Davis wrote: Unfortunately, D does not currently have a way to do that. Only functions can be marked with @trusted. However, the typical approach to this problem is to use a lambda, which is more or less syntactically the same except

Re: Temporary @trusted scope

2018-12-18 Thread rikki cattermole via Digitalmars-d-learn
On 19/12/2018 1:34 AM, Per Nordlöw wrote: On Tuesday, 18 December 2018 at 10:42:51 UTC, Jonathan M Davis wrote: Unfortunately, D does not currently have a way to do that. Only functions can be marked with @trusted. However, the typical approach to this problem is to use a lambda, which is more

Re: Checking if CTFE is used?

2018-12-18 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Dec 18, 2018 at 1:25 PM berni via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > Is there a way to check if a function is indeed executed at > compile time or not? (Other than going through the whole > executable binaries...) > > I tried > > > static this() > > { > >

Temporary @trusted scope

2018-12-18 Thread Per Nordlöw via Digitalmars-d-learn
What's the preferred way of creating a temporary @trusted scope without writing a separate function? Similar to Rust's unsafe { /* unsafe stuff here */ }

Reverse and sort array elements

2018-12-18 Thread Andrey via Digitalmars-d-learn
Hi, Have array: enum array = ["qwerty", "a", "baz"]; Need to reverse and sort array elements to get this result: [a, ytrewq, zab] Did this: enum result = array.map!(value => value.retro()).sort(); Got: Error: template std.algorithm.sorting.sort cannot deduce function from argument types

Re: Doubt about this book: The D Programming Language

2018-12-18 Thread Ron Tarrant via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 01:16:54 UTC, Adam D Ruppe wrote: They're obvious. Stuff like doubled ; at the end of lines in code samples, or curly quotes when they should be straight. (They are the result of me fighting Microsoft Word and the review process with the publisher.) A few

Re: Temporary @trusted scope

2018-12-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, December 18, 2018 3:14:50 AM MST Per Nordlöw via Digitalmars-d- learn wrote: > What's the preferred way of creating a temporary @trusted scope > without writing a separate function? > > Similar to Rust's > > unsafe { /* unsafe stuff here */ } Unfortunately, D does not currently have

Re: Reverse and sort array elements

2018-12-18 Thread Andrey via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 12:32:35 UTC, angel wrote: On Tuesday, 18 December 2018 at 12:07:37 UTC, Andrey wrote: Thank you everybody. Here was another problem that local variable 'array' shadows function 'array()' from std.array.

Re: Temporary @trusted scope

2018-12-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/18/18 6:29 AM, Simen Kjærås wrote: On Tuesday, 18 December 2018 at 10:14:50 UTC, Per Nordlöw wrote: What's the preferred way of creating a temporary @trusted scope without writing a separate  function? Jonathan's idea might also be encapsulated in a function, just like assumeUnique in

Re: Checking if CTFE is used?

2018-12-18 Thread berni via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 13:53:01 UTC, Stefan Koch wrote: Why would you need to know? Well, first out of curiosity. But there are also other reasons: I've got a large immutable array. Without CTFE I'd use some php script and add it as a large literal. With CTFE I don't need that php

Re: Reverse and sort array elements

2018-12-18 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 12:47:59 UTC, Andrey wrote: On Tuesday, 18 December 2018 at 12:32:35 UTC, angel wrote: On Tuesday, 18 December 2018 at 12:07:37 UTC, Andrey wrote: Thank you everybody. Here was another problem that local variable 'array' shadows function 'array()' from

Re: Temporary @trusted scope

2018-12-18 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 13:52:29 UTC, Steven Schveighoffer wrote: template unsafe(alias fn) {     @trusted auto unsafe(T...)(T args) {     return fn(args);     } } Very nice! What about proposing this for inclusion into `std.typecons` or `std.meta`?

Re: Checking if CTFE is used?

2018-12-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 14:23:38 UTC, berni wrote: import std.stdio; class A { static immutable int[4] clue; static this() { if(__ctfe) assert(0, "Yep, CTFE used"); foreach (i;0..4) clue[i] = i; } } CTFE is used if and only if it MUST be used by

How to build dmd properly?

2018-12-18 Thread unDEFER via Digitalmars-d-learn
Hello, I have the next code (minimized with DustMite): struct Tup(T...) { bool opEquals() { foreach (i; T) static if (__traits(compiles, mixin("new InputRangeObject11261!(abs_class)"))) msg; } } /**/ void test3() {

Re: Checking if CTFE is used?

2018-12-18 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 12:21:44 UTC, berni wrote: Is there a way to check if a function is indeed executed at compile time or not? (Other than going through the whole executable binaries...) I tried static this() { if (__ctfe) pragma(msg,"works"); // some other stuff } but

Re: Reverse JSON toPrettyString

2018-12-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/17/18 5:09 PM, Anonymouse wrote: I have a JSON string[][string] associative array object that I want to take the .toPrettyString value of. However, it sorts the output alphabetically. string[][string] aa = [ "abc" : [], "def" : [], "ghi" : [] ]; auto asJSON = JSONValue(aa);

Re: Checking if CTFE is used?

2018-12-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/18/18 7:21 AM, berni wrote: Is there a way to check if a function is indeed executed at compile time or not? (Other than going through the whole executable binaries...) I tried static this() {   if (__ctfe) pragma(msg,"works");   // some other stuff } but unfortunatley this "if" is

Re: How to build dmd properly?

2018-12-18 Thread unDEFER via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 15:54:28 UTC, Seb wrote: On Tuesday, 18 December 2018 at 14:35:46 UTC, unDEFER wrote: What I could build wrong and how to build dmd properly? Maybe you built dmd.d with debug assertions? (ENABLE_DEBUG=1) You can build dmd with the `./build.d` script or `make

Re: How to build dmd properly?

2018-12-18 Thread unDEFER via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 16:19:33 UTC, unDEFER wrote: Yes, thank you for the hint. You are almost right. I did not ENABLE_DEBUG=1, but I also did not ENABLE_RELEASE=1 So it is the bug. I will report about it. https://issues.dlang.org/show_bug.cgi?id=19500

Re: How to build dmd properly?

2018-12-18 Thread Seb via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 14:35:46 UTC, unDEFER wrote: What I could build wrong and how to build dmd properly? Maybe you built dmd.d with debug assertions? (ENABLE_DEBUG=1) You can build dmd with the `./build.d` script or `make -f posix.mak -j4` (assuming you are in `src). Anyway,

Re: Checking if CTFE is used?

2018-12-18 Thread berni via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 14:32:29 UTC, Adam D. Ruppe wrote: CTFE is used if and only if it MUST be used by context. That's a runtime function, so no ctfe. Do something like: int[4] generate() { int[4] tmp; foreach(i; 0..4) tmp[i] = i; return tmp; } static immutable int[4]

Re: Temporary @trusted scope

2018-12-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/18/18 10:53 AM, H. S. Teoh wrote: On Tue, Dec 18, 2018 at 08:52:29AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: On 12/18/18 6:29 AM, Simen Kjærås wrote: On Tuesday, 18 December 2018 at 10:14:50 UTC, Per Nordlöw wrote: What's the preferred way of creating a temporary

Re: Temporary @trusted scope

2018-12-18 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 18, 2018 at 08:52:29AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 12/18/18 6:29 AM, Simen Kjærås wrote: > > On Tuesday, 18 December 2018 at 10:14:50 UTC, Per Nordlöw wrote: > > > What's the preferred way of creating a temporary @trusted scope > > > without writing

Re: Temporary @trusted scope

2018-12-18 Thread aliak via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 13:52:29 UTC, Steven Schveighoffer wrote: On 12/18/18 6:29 AM, Simen Kjærås wrote: On Tuesday, 18 December 2018 at 10:14:50 UTC, Per Nordlöw wrote: What's the preferred way of creating a temporary @trusted scope without writing a separate  function? Jonathan's

Re: Tricky DMD bug, but I have no idea how to report

2018-12-18 Thread JN via Digitalmars-d-learn
On Monday, 17 December 2018 at 22:22:05 UTC, H. S. Teoh wrote: A less likely possibility might be an optimizer bug -- do you get different results if you add / remove '-O' (and/or '-inline') from your dmd command-line? If some combination of -O and -inline (or their removal thereof) "fixes"

Re: saving std.random RNG state

2018-12-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/17/18 8:18 PM, Neia Neutuladh wrote: On Mon, 17 Dec 2018 22:20:54 +, harfel wrote: I am looking for a way to serialize/deserialize the state of the std.random.Random number generator, ideally using orange (https://github.com/jacob-carlborg/orange) or another serialization library.

Re: Bug in shifting

2018-12-18 Thread Rainer Schuetze via Digitalmars-d-learn
On 14/12/2018 02:56, Steven Schveighoffer wrote: > On 12/13/18 7:16 PM, Michelle Long wrote: >> byte x = 0xF; >> ulong y = x >> 60; > > Surely you meant x << 60? As x >> 60 is going to be 0, even with a ulong. It doesn't work as intuitive as you'd expect: void main() { int x = 256;

Re: Tricky DMD bug, but I have no idea how to report

2018-12-18 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 18, 2018 at 10:29:07PM +, JN via Digitalmars-d-learn wrote: > On Monday, 17 December 2018 at 22:22:05 UTC, H. S. Teoh wrote: > > A less likely possibility might be an optimizer bug -- do you get > > different results if you add / remove '-O' (and/or '-inline') from > > your dmd

Re: Checking if CTFE is used?

2018-12-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, December 18, 2018 9:20:11 AM MST berni via Digitalmars-d-learn wrote: > On Tuesday, 18 December 2018 at 14:32:29 UTC, Adam D. Ruppe wrote: > > CTFE is used if and only if it MUST be used by context. That's > > a runtime function, so no ctfe. > > > > Do something like: > > > > int[4]

Re: Temporary @trusted scope

2018-12-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, December 18, 2018 5:42:12 AM MST rikki cattermole via Digitalmars-d-learn wrote: > On 19/12/2018 1:34 AM, Per Nordlöw wrote: > > On Tuesday, 18 December 2018 at 10:42:51 UTC, Jonathan M Davis wrote: > >> Unfortunately, D does not currently have a way to do that. Only > >> functions