Re: Comparison of Enumerations with base type of String?

2017-08-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, August 27, 2017 03:47:58 Michael Reiland via Digitalmars-d-learn 
wrote:
> You can randomly assign a string to an enum?  Or am I
> misunderstanding that last bit of code?

No, you can't directly assign a string to an enum of type string. That's
part of why they don't pass isInputRange. This code fails to compile

enum S : string
{
a = "foo",
b = "bar"
}

void main()
{
S s = "baz";
}

though you can force it with a cast, e.g.

S s = cast(S)"baz";

Unfortunately however, enums in D really aren't very strongly typed. So,
while direct assignment will fail, stuff like

S s = S.a;
s ~= "blah";

will compile. And enums of base type int have the same problem - e.g.

E e = E.a | E.b;

In both cases, you trivially end up with a value that is not valid for that
enum type and will likely cause problems with final switch (which will
result in an Error being thrown when not compiling with -release but will do
who-knows-what when -release is used, because there is no check with
-release).

The result is that a variable of an enum type does not entirely act like the
base type even when you're not considering stuff like using is expressions
or std.traits to test something based on its type. It's implicitly
convertible to its base type but is not its base type. However, a bunch of
operations that IMHO really should not be legal on an enum are (e.g.
appending), and some which could be legal but should result in the base type
rather than the enum type (e.g concatenation or |ing) result in the enum
type, making it trivial to create enum variables with values that aren't in
the enum if you're not careful. Discussions have been had on this in the
past, and I'm firmly of the belief that the current design is a mistake in
this regard, but some (Andrei included) have argued that it's perfectly
legitimate to have an enum variable which is not one of the listed enum
values with the idea that you're defining a general type that has a few
known constants but the constants aren't all of the values. I think this
violates the idea of what an enum is (I think that an enum should always
define all valid values for that enum and no other values should be legal),
and it definitely doesn't play nicely with final switch, but for the moment,
we're stuck.

> Also it sounds to me like string enums are going to be slower
> performance wise than integer enums.

I expect so. How efficient an enum is depends entirely on what its base type
is and what you're doing with it. However, if all you're really looking for
is to have a string representation of the name of an enum, then you can have
the base type be int, and to!string and writeln will give you the string
representation of the name of the enum without the enum needing to be a
string. Whether it makes sense to use string as the base type of an enum
depends entirely on what you're trying to do with the enum, just like
whether you use a struct as the base type of an enum makes sense depends on
what you're doing. Sometimes, it can be very useful, but that doesn't mean
that it's always the best solution.

- Jonathan M Davis



[Issue 17783] New: "invalid" leftmost column string in a delimited string does not compile

2017-08-26 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17783

  Issue ID: 17783
   Summary: "invalid" leftmost column string in a delimited string
does not compile
   Product: D
   Version: D2
  Hardware: x86_64
OS: Linux
Status: NEW
  Severity: normal
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: nmtigor.w...@googlemail.com

The following code does not compile:

@safe unittest
{
string str1 = q"DLANG
q"123"
DLANG";
assert( str1 == "q\"123\"\n" );
}

But the following compiles:

@safe unittest
{
string str1 = q"DLANG
 q"123"
DLANG";
assert( str1 == " q\"123\"\n" );
}

--


[Issue 17782] The identifier delimiter of a delimited string can not begin with '_'

2017-08-26 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17782

--- Comment #1 from nmtigor.w...@googlemail.com ---
https://github.com/dlang/dmd/pull/7105

--


Re: Comparison of Enumerations with base type of String?

2017-08-26 Thread Michael Reiland via Digitalmars-d-learn
You can randomly assign a string to an enum?  Or am I 
misunderstanding that last bit of code?


Also it sounds to me like string enums are going to be slower 
performance wise than integer enums.


[Issue 17782] New: The identifier delimiter of a delimited string can not begin with '_'

2017-08-26 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17782

  Issue ID: 17782
   Summary: The identifier delimiter of a delimited string can not
begin with '_'
   Product: D
   Version: D2
  Hardware: x86_64
OS: Linux
Status: NEW
  Severity: normal
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: nmtigor.w...@googlemail.com

The following code does not compile:

@safe unittest
{
string str = q"_DLANG
123
_DLANG";
assert( str == "123\n" );
}

Replacing "_DLANG" with "DLANG", it then compiles.

--


[Issue 17780] Malformed DDOC links in std.range

2017-08-26 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17780

--- Comment #2 from b2.t...@gmx.com ---
(In reply to b2.temp from comment #1)
> and https://dlang.org/phobos/std_range.html#.stride has one too... text
> rendered is not in order ! "as hasLength.std.range.primitives is true."

this one is rendered correctly in the doc distributed with the latest beta but
not those for drop / dropExactly

--


Re: ATTN: Andrej Mitrovic: Port Audio

2017-08-26 Thread Johnson via Digitalmars-d-learn

On Sunday, 27 August 2017 at 02:23:32 UTC, Johnson wrote:

On Sunday, 27 August 2017 at 02:00:22 UTC, Johnson wrote:
You wrote a thread a while back about your callbacks not being 
called and you had a fix.


[...]


After going through the code a bit, seems there are some bugs 
with  Only OpenStream seems to take a ** so the other 
functions are getting passed junk.


At least, I got sound! Scared the shit out of me too!


I should mention that the callback is still not being called, but 
I used the sawtooth to modify a buffer and used Pa_WriteStream. 
Pa_SetStreamFinishedCallback is working.


PaStreamFlags.PrimeOutputBuffersUsingStreamCallback still causes 
an access violation.


Seems like the callback address is not being correctly 
transmitted to PA.




[Issue 17764] [scope][DIP1000] Escape checker defeated by composition transformations

2017-08-26 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17764

Walter Bright  changed:

   What|Removed |Added

 CC||bugzi...@digitalmars.com

--- Comment #2 from Walter Bright  ---
Starting with this one:

> void use0x2(scope char[]* arr)
> {
> global = *arr; // NG - accepts invalid
> }

`scope` is not transitive. It applies to the 'head' only. `*arr` is no longer
the head, and `scope` doesn't apply to it. A casual look at the rest of the
cases shows similar.

If you would please filter out all the cases of more than one indirection, I
can look at the rest.

--


[Issue 17763] [scope][DIP1000] The compiler treats implicit and explicit static array slicing differently

2017-08-26 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17763

Walter Bright  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |INVALID

--- Comment #3 from Walter Bright  ---
(In reply to ZombineDev from comment #0)
> The problem is that the compiler disallows explicitly slicing a static array
> and passing the slice to a scope parameter, while if you rely on the
> implicit slicing it works without a problem.

Let's examine:

> use(c);// OK - this compiles.

The address of c is implicitly taken by its coercion to the parameter type of
Context[]. But this is allowed because the parameter is 'scope', and it cannot
escape.


> use(c[]);  // NG - doesn't compile, though should be
>// equivalent to the statement above.

What's happening here is the semantic analysis is bottom up, meaning `c[]` is
evaluated without regard to what context it appears in. The compiler doesn't
see that the result is being passed as `scope`, and so assumes the worst, and
issues an error.

It is not a bug in the compiler.

Trying to add some form of top down in addition to bottom up is a huge increase
in complexity, and will produce all kinds of weird corner cases. You can reopen
it as an enhancement request if you prefer, but I don't think it is practical
to implement at least in the near future.

--


Re: ATTN: Andrej Mitrovic: Port Audio

2017-08-26 Thread Johnson via Digitalmars-d-learn

On Sunday, 27 August 2017 at 02:00:22 UTC, Johnson wrote:
You wrote a thread a while back about your callbacks not being 
called and you had a fix.


[...]


After going through the code a bit, seems there are some bugs 
with  Only OpenStream seems to take a ** so the other 
functions are getting passed junk.


At least, I got sound! Scared the shit out of me too!


Re: Comparison of Enumerations with base type of String?

2017-08-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, August 27, 2017 01:43:14 Michael Reiland via Digitalmars-d-learn 
wrote:
> Hey guys,
>
> I was running through a tutorial and I noticed that enums can
> have a base type of string.  Which is interesting, but I'm
> wondering about comparisons.
>
> I'm guessing the comparison boils down to a pointer comparison,
> but I thought I'd confirm.

No, it'll do the normal string comparison, just like enums that are ints do
a normal integer comparison. The fact the strings are enums doesn't really
change much except for stuff that's specifically doing something differently
for enums. It just means that instead of having separate constants which are
strings, you have them grouped together, and final switch statements will
require that the cases cover all of them. Some stuff like std.conv.to!string
or writeln will end up using the names of the enums rather than their values
like they do with other enums even though they're strings, but in general,
having

enum S : string
{
foo = "yes",
bar = "no",
}

isn't all that different from just doing

enum foo = "yes";
enum bar = "no";

except that declaring the enum S essentially puts them in a namespace called
S. It does create a new type S, which affects some stuff (e.g. S is not a
range, whereas string is), so operating an an S is not completely identical
to operating on a string, but S doesn't magically end up implementing
operations differently than occurs with string. It's just that some of the
operations on S are more restricted than a naked string, and since they
implicitly convert to string rather than being a string, some functions that
looks at the type will operate on an S differently than they would for a
naked string.

- Jonathan M Davis



[Issue 17780] Malformed DDOC links in std.range

2017-08-26 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17780

--- Comment #1 from b2.t...@gmx.com ---
and https://dlang.org/phobos/std_range.html#.stride has one too... text
rendered is not in order ! "as hasLength.std.range.primitives is true."

--


ATTN: Andrej Mitrovic: Port Audio

2017-08-26 Thread Johnson via Digitalmars-d-learn
You wrote a thread a while back about your callbacks not being 
called and you had a fix.


http://www.digitalmars.com/d/archives/digitalmars/D/learn/Anyone_using_Portaudio_22343.html

I'm trying to get portAudio to work on my machine and it seems 
everything passes yet my callbacks are not being called.



I do not know if it is the same issue you had or what. Could you 
describe your fixes, if you remember? You said it was alias 
issues, my source uses alias, so maybe I have the updated one.


Also, using paPrimeOutputBuffersUsingStreamCallback causes an 
access violation ;/


Here are some dll's I'm using

https://github.com/spatialaudio/portaudio-binaries



I'm including the two files needed to compile what I have in case 
you(or anyone else) decide to help figure this out:


Make sure to change the dll location in the DLL_PortAudio struct 
and set the appropriate audio interface to use(I have it set to 
12, but have tried every value on my system with no luck).



module mPortAudio;
import std.stdio, std.conv;


enum PaError : int
{   
NoError = 0,
NotInitialized = -1,
UnanticipatedHostError,
InvalidChannelCount,
InvalidSampleRate,
InvalidDevice,
InvalidFlag,
SampleFormatNotSupported,
BadIODeviceCombination,
InsufficientMemory,
BufferTooBig,
BufferTooSmall,
NullCallback,
BadStreamPtr,
TimedOut,
InternalError,
DeviceUnavailable,
IncompatibleHostApiSpecificStreamInfo,
StreamIsStopped,
StreamIsNotStopped,
InputOverflowed,
OutputUnderflowed,
HostApiNotFound,
InvalidHostApi,
CanNotReadFromACallbackStream,
CanNotWriteToACallbackStream,
CanNotReadFromAnOutputOnlyStream,
CanNotWriteToAnInputOnlyStream,
IncompatibleStreamHostApi,
BadBufferPtr,
FormatIsSupported = 0,
};

enum PaSampleFormat : ulong
{
Float32  = 0x0001,
Int32= 0x0002,
Int24= 0x0004,
Int16= 0x0008,
Int8 = 0x0010,
UInt8= 0x0020,
CustomFormat = 0x0001,
NonInterleaved = 0x8000
}

enum PaHostApiTypeId : int
{
InDevelopment=0,
DirectSound=1,
MME=2,
ASIO=3,
SoundManager=4,
CoreAudio=5,
OSS=7,
ALSA=8,
AL=9,
BeOS=10,
WDMKS=11,
JACK=12,
WASAPI=13,
AudioScienceHPI=14
};


enum PaStreamCallbackResult : int
{
paContinue=0,   /**< Signal that the stream should continue 
invoking the callback and processing audio. */
paComplete=1,   /**< Signal that the stream should stop 
invoking the callback and finish once all output samples have 
played. */
paAbort=2   /**< Signal that the stream should stop 
invoking the callback and finish as soon as possible. */

};





enum PaStreamFlags : ulong
{
NoFlag = 0,
ClipOff = 0x0001,
DitherOff = 0x0002,
NeverDropInput = 0x0004,
PrimeOutputBuffersUsingStreamCallback = 0x0008,
PlatformSpecificFlags = 0x,
}

alias void PaStream;
enum paFramesPerBufferUnspecified = 0;
enum PaStreamCallbackFlags : ulong
{
InputUnderflow = 0x0001,
InputOverflow = 0x0002,
OutputUnderflow = 0x0004,
OutputOverflow = 0x0008,
PrimingOutput = 0x0010,
}



alias extern(C) int function(const(void) *input, void *output, 
ulong frameCount, const(PaStreamCallbackTimeInfo)* timeInfo, 
PaStreamCallbackFlags statusFlags, void *userData ) 
PaStreamCallback;

alias void function( void *userData ) PaStreamFinishedCallback;

alias int PaDeviceIndex;
enum paNoDevice = cast(PaDeviceIndex)-1;
enum paUseHostApiSpecificDeviceSpecification =  
cast(PaDeviceIndex)-2;

alias int PaHostApiIndex;
alias double PaTime;


struct PaHostApiInfo
{
int structVersion;
PaHostApiTypeId type;
const(char) *name;
int deviceCount;
PaDeviceIndex defaultInputDevice;
PaDeviceIndex defaultOutputDevice;
};

struct PaDeviceInfo
{
int structVersion;
const(char) *name;
PaHostApiIndex hostApi;
int maxInputChannels;
int maxOutputChannels;
PaTime defaultLowInputLatency;
PaTime defaultLowOutputLatency;
PaTime defaultHighInputLatency;
PaTime defaultHighOutputLatency;
double defaultSampleRate;
};

struct PaStreamCallbackTimeInfo
{
PaTime inputBufferAdcTime;
PaTime currentTime;
PaTime outputBufferDacTime;
};

struct PaStreamInfo
{
int structVersion;
PaTime inputLatency;
PaTime outputLatency;
double sampleRate;
};


struct PaHostErrorInfo
{
PaHostApiTypeId hostApiType;
long errorCode;
const(char) *errorText;
};

struct PaStreamParameters
{
PaDeviceIndex device;
int channelCount;
PaSampleFormat sampleFormat;
PaTime suggestedLatency;
void *hostApiSpecificStreamInfo;
};
























struct DLL_PortAudio
{
@("DLLImport") public static 

Re: How to store data when using parallel processing

2017-08-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, August 27, 2017 00:26:33 Andrew Chapman via Digitalmars-d-learn 
wrote:
> Hi all, just wanting some advice on parallel processing and
> specifically how to deal with access violations.
>
> I am reading a list of words from a file like this:
>
> auto fileHandle = File("wordlist.txt", "r");
>
> string word;
> string[] words;
> string[ulong] hashMap;
>
> while ((word = fileHandle.readln()) !is null) {
>   words ~= word;
> }
>
> Then I'm doing some processing on the words.  I want to make this
> run as quickly as possible so I am doing the processing across
> the cores of my CPU like this:
>
> foreach (thisWord; parallel(words)) {
>   string wordLower = thisWord.strip().toLower();
>   ulong key = keyMaker.createKeyForWord(wordLower);
>
>  // hashMap[key] = wordLower;
> }
>
> The question is, in the above loop, how can I make the commented
> out line work without having an access violation.  Do I need to
> use a different data structure?  Or rethink what I'm doing?

std.parallelism is designed to work on stuff that's truly parallel, whereas
adding a value to an AA is not. For multiple threads to be able to access
it, it needs to be protected by a mutex or a synchronized block, in which
case the assignment is no longer parallel. Whether that matters much depends
on how expensive the rest of what the loop is doing is. If it's cheap
enough, then the threads will all just end up blocking on the mutex,
effectively making the code serial and making the parallelism pointless,
whereas if it's expensive enough that the threads will spend most of their
time doing the rest of the loop, then you can get an increase in performance
over just doing it in one thread. It wouldn't surprise me if simply doing
all of the work in the first loop and not creating the words array in the
first place would be faster than trying to parallelize the second loop, but
I don't know. You'd have to test it and see.

But std.parallelism cheats with regards to shared (which is part of why it's
@system). hiding the fact that you're dealing with multiple threads, but all
of the issues when using shared data remain (e.g. needing to use mutexes to
protect against data races). std.parallelism just normally manages to avoid
that problem by operating on separate pieces of data simultaneously rather
than operating on the same data on multiple threads at the same time,
whereas what you're doing with regards to the result involves operating on
the same data from multiple threads at the same time, which doesn't work
without mutexes.

An alternative would be to have a separate AA per thread, and then you
combine them after the loop, but that requires checking which thread you're
on so that you grab the correct one in a particular iteration of the loop. I
assume that std.parallelism provides a reasonably easy way to do that, but I
haven't done much with it, so I don't know. Worst case, you can probably go
off of the thread ID using core.thread.

std.parallelism may offer other ways to accomplish this, but I'd have to
study it to be sure. Either way, fundamentally, you're either going to have
to protect the hash table with a mutex, and the writes will be synchronous
even if the data creation is parallelized, or you have to store the data
from each thread separately while the threads are running and then combine
the data when the threads are done.

- Jonathan M Davis



Comparison of Enumerations with base type of String?

2017-08-26 Thread Michael Reiland via Digitalmars-d-learn

Hey guys,

I was running through a tutorial and I noticed that enums can 
have a base type of string.  Which is interesting, but I'm 
wondering about comparisons.


I'm guessing the comparison boils down to a pointer comparison, 
but I thought I'd confirm.




[Issue 17781] New: printing "Shared libraries are not yet supported on OSX." should be optional

2017-08-26 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17781

  Issue ID: 17781
   Summary: printing "Shared libraries are not yet supported on
OSX."  should be optional
   Product: D
   Version: D2
  Hardware: x86
OS: Mac OS X
Status: NEW
  Severity: regression
  Priority: P1
 Component: druntime
  Assignee: nob...@puremagic.com
  Reporter: timothee.co...@gmail.com

although Shared libraries are indeed to 100% supported on OSX, there are
existing use caes that do work, and having this message printed to stderr
(druntime/src/rt/sections_osx_x86_64.d) every time they're being used is
annoying.
Could we have an option to make printing this optional?

classifying it as regression since this wasn't printed before

--


Re: Promoting TutorialsPoint's D tutorial

2017-08-26 Thread ag0aep6g via Digitalmars-d

On 08/27/2017 01:53 AM, Ryion wrote:
* D website starts with a big blog of texts Module, ModuleDeclaration 
DeclDefs DeclDefs. What am i reading. Chinese?


You're reading the spec. Teaching is not the spec's first priority. It's 
not a tutorial or a programming textbook.


Have you tried Ali's book? The page on modules is here:

http://ddili.org/ders/d.en/modules.html

Wait a second. Large parts of that are word-for-word the same as on the 
tutorialspoint page [1]. Looks like one of the authors copied from the 
other one. From the bad impression I've got of tutorialspoint, I'd guess 
that they copied from Ali.



[1] https://www.tutorialspoint.com/d_programming/d_programming_modules.htm


How to store data when using parallel processing

2017-08-26 Thread Andrew Chapman via Digitalmars-d-learn
Hi all, just wanting some advice on parallel processing and 
specifically how to deal with access violations.


I am reading a list of words from a file like this:

auto fileHandle = File("wordlist.txt", "r");

string word;
string[] words;
string[ulong] hashMap;

while ((word = fileHandle.readln()) !is null) {
words ~= word;
}

Then I'm doing some processing on the words.  I want to make this 
run as quickly as possible so I am doing the processing across 
the cores of my CPU like this:


foreach (thisWord; parallel(words)) {
string wordLower = thisWord.strip().toLower();
ulong key = keyMaker.createKeyForWord(wordLower);

// hashMap[key] = wordLower;
}

The question is, in the above loop, how can I make the commented 
out line work without having an access violation.  Do I need to 
use a different data structure?  Or rethink what I'm doing?


Thanks in advance.
Andrew.


Re: Promoting TutorialsPoint's D tutorial

2017-08-26 Thread Adam D. Ruppe via Digitalmars-d

On Saturday, 26 August 2017 at 23:53:27 UTC, Ryion wrote:
I have the same issue with the Library. The flow of information 
is bad, too much walls of text, with too much assumption that


Have you tried my alternative? It is the same content (well it 
lags a version or two cuz i haven't updated my computer yet) but 
laid out differently.


http://dpldocs.info/

http://dpldocs.info/experimental-docs/std.stdio.html
for example


Re: No CTFE of function

2017-08-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, August 26, 2017 23:53:36 Cecil Ward via Digitalmars-d-learn 
wrote:
> On Saturday, 26 August 2017 at 23:49:30 UTC, Cecil Ward wrote:
> > On Saturday, 26 August 2017 at 18:16:07 UTC, ag0aep6g wrote:
> >> On Saturday, 26 August 2017 at 16:52:36 UTC, Cecil Ward wrote:
> >>> Any ideas as to why GDC might just refuse to do CTFE on
> >>> compile-time-known inputs in a truly pure situation?
> >>
> >> That's not how CTFE works. CTFE only kicks in when the
> >> *result* is required at compile time. For example, when you
> >> assign it to an enum. The inputs must be known at compile
> >> time, and the interpreter will refuse to go on when you try
> >> something impure. But those things don't trigger CTFE.
> >>
> >> The compiler may choose to precompute any constant expression,
> >> but that's an optimization (constant folding), not CTFE.
> >
> > I think I understand, but I'm not sure. I should have explained
> > properly. I suspect what I should have said was that I was
> > expecting an _optimisation_ and I didn't see it. I thought that
> > a specific instance of a call to my pure function that has all
> > compile-time-known arguments would just produce generated code
> > that returned an explicit constant that is worked out by CTFE
> > calculation, replacing the actual code for the general function
> > entirely. So for example
> >
> > auto foo() { return bar( 2, 3 ); }
> >
> > (where bar is strongly pure and completely CTFE-able) should
> > have been replaced by generated x64 code looking exactly
> > literally like
> >
> > auto foo() { return 5; }
> >
> > expect that the returned result would be a fixed-length literal
> > array of 32-but numbers in my case (no dynamic arrays anywhere,
> > these I believe potentially involve RTL calls and the allocator
> > internally).
>
> I was expecting this optimisation to 'return literal constant
> only' because I have seen it before in other cases with GDC.
> Obviously generating a call that involves running the algorithm
> at runtime is a performance disaster when it certainly could have
> all been thrown away in the particular case in point and been
> replaced by a return of a precomputed value with zero runtime
> cost. So this is actually an issue with specific compilers, but I
> was wondering if I have missed anything about any D general rules
> that make CTFE evaluation practically impossible?

I don't know what you've seen before, but CTFE _only_ happens when the
result must be known at compile time - e.g. it's used to directly initialize
an enum or static variable. You will _never_ see CTFE done simply because
you called the function with literals. It's quite possible that GDC's
optimizer could inline the function and do constant folding and
significantly reduce the code that you actually end up with (maybe even
optimize it out entirely in some cases), but it would not be CTFE. It would
simply be the compiler backend optimizing the code. CTFE is done by the
frontend, and it's the same across dmd, ldc, and gdc so long as they have
the same version of the frontend (though the current version of gdc is quite
old, so if anything, it's behind on what it can do). So, if you want CTFE to
occur, then you _must_ assign the result to something that must have its
value known at compile time, and that will be the same across the various
compilers so long as the frontend version is the same. Any optimizations
which might optimize out function calls would be highly dependent on the
compiler backend and could easily differ across compiler versions.

My guess is that you previously saw your code optimized down such that you
thought that the compiler used CTFE when it didn't and that you're not
seeing such an optimization now, because your function is too large. If you
want to guarantee that the call is made at compile time and not worry about
whether the optimizer will do what you want, just assign the result to an
enum and then use the enum rather than hoping that the optimizer will
optimize the call out for you.

- Jonathan M Davis



[Issue 17763] [scope][DIP1000] The compiler treats implicit and explicit static array slicing differently

2017-08-26 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17763

Walter Bright  changed:

   What|Removed |Added

 CC||bugzi...@digitalmars.com

--- Comment #2 from Walter Bright  ---
(In reply to ZombineDev from comment #1)
> While previous case was rejects-valid, here's a similar one where the
> compile accepts invalid code:

Reducing the case to:

  struct Context { char[] str; }

  void main() {
Context[1] c;
use(c);
  }

  Context[] global;

  void use(scope ref Context[1] c) @safe {
global = c[];
global = c;
  }

and compiling with no flags:

  test1.d(13): Error: address of variable c assigned to global with longer
lifetime
  test1.d(14): Error: address of variable c assigned to global with longer
lifetime

compiling with -dip1000:

  test1.d(13): Error: cannot take address of scope parameter c in @safe
function use
  test1.d(14): Error: address of variable c assigned to global with longer
lifetime

The different messages are because of the different order things happen due to
the rewriting. But the error messages are still there and are correct.

Perhaps you're testing with an older compiler?

--


Re: Promoting TutorialsPoint's D tutorial

2017-08-26 Thread Ryion via Digitalmars-d

On Saturday, 26 August 2017 at 22:26:00 UTC, Ecstatic Coder wrote:
I've no problem with that, but would it be possible to consider 
adding also a link to this tutorial in the same paragraph ?


https://www.tutorialspoint.com/d_programming/

It's not because TutorialsPoint pay me, but because it may be 
one of the best D tutorials out there for both beginner D 
programmers.


And honestly, at the moment it's not really that easy to reach 
this tutorial from the dlang website.


First you have to push on "Tutorials", then in the middle of 
the page you see a boring flat grey icon with this text beside :


"D programming
Unknown
January 1, 2015
A nice introductory tutorial to D programming. Available 
on-line and in the PDF format.

Website"

The text is fine, but unfortunately the impersonal icon and 
text ("D programming") aren't that inviting...


If you don't want to put the link on the "Further reading 
page", maybe would you consider putting this nice tutorial for 
beginners just under the four official D books, before the more 
advanced readings ?


I guess many beginner D programmers will thank you :)

Because a few month ago I've been that beginner D programmer, 
and sadly I've completely missed this perfect tutorial. And 
I've just explained you why...


So why not supposing other programmers will have the same 
problem, and maybe miss it just like me ?


No, i have the same issue with the website. Tutorialspoint may 
have issues as ag0aep6g pointed out but its very much to the 
point. I prefer to look up information on tutorialspoint compared 
to the D website.


Lets say Arrays:

* D website starts with Pointers, then Static Arrays, then 
Dynamic Arrays then ... A person may simply say: "I just want to 
know how to write a array, i do not need a tutorial talking about 
the different types, because most of my work is simply standard 
arrays".


Instead of splitting the information in different chapters, its 
so much text on a single page. Tutorialspoint simply shows the 
basic information and that is what i need 90% of the time.


How about Modules:

* D website starts with a big blog of texts Module, 
ModuleDeclaration DeclDefs DeclDefs. What am i reading. Chinese? 
By the time you see the visual text how to declare a module, you 
are already 2 pages down.


Tutorialspoint simply shows how to declare modules. Basic, fast 
...



Tutorialspoint indeed misses a lot of information but D website 
has unreadable information overload. Useful for people who have 
time to read half a day but as somebody programming and wanting 
to quickly look up information. D website is not useful. Its 
actually counter intuative.


It feels academic in design, not functional. You expect to get 
simple example and the more advanced items under "advanced".


I have the same issue with the Library. The flow of information 
is bad, too much walls of text, with too much assumption that the 
programmer reading it is familiar with the more advanced features 
or programming knowledge. Links and references to variables that 
frankly, are unneeded. If it takes 15 minutes to know in 
std.parallelism that you can not get a thread ID in a simply 
way... then the purpose as a information source fails.


A simple:

https://dlang.org/phobos/std_datetime_date.html

Why do you need to wade past 2 pages for

jan
feb
mar
apr
may
jun
jul
aug
sep
oct
nov
dec
sun

mon
tue
wed
thu
fri
sat
...

Then the whole Jump to: 2, Jump to: 2, Jump to: 2 ...

Function naming...

Expect: bool validTimeUnits(string[] units...);

Gets: pure nothrow @safe bool validTimeUnits(string[] units...);

... Visual noise that is not important. Details like that need to 
be in a sub page.


People care about the function, parameter, return type. The rest 
is "advanced" and only useful under specific sitations.


After months i still do not use the library/documentation. I end 
up googling for examples or use tutorialspoint for some quick 
basic lookup's. If i am really stuck i may go into the library 
and get frustrated with the wall of text. Its is too much a time 
sink, while its supposed to be a help.


I do not know how to explain it but the documentation is at times 
more frustrating then the issue i am trying to solve. If i had to 
give a score, the D documentation is at best 4/10. Its not the 
lack of information but the simply bad presentation, overflow of 
information where you do not need it. No clear separation. Mobile 
friendly it is NOT. Even 4K friendly it also not. And plenty of 
other issues.


Re: No CTFE of function

2017-08-26 Thread Cecil Ward via Digitalmars-d-learn

On Saturday, 26 August 2017 at 23:53:36 UTC, Cecil Ward wrote:

On Saturday, 26 August 2017 at 23:49:30 UTC, Cecil Ward wrote:

[...]


I was expecting this optimisation to 'return literal constant 
only' because I have seen it before in other cases with GDC. 
Obviously generating a call that involves running the algorithm 
at runtime is a performance disaster when it certainly could 
have all been thrown away in the particular case in point and 
been replaced by a return of a precomputed value with zero 
runtime cost. So this is actually an issue with specific 
compilers, but I was wondering if I have missed anything about 
any D general rules that make CTFE evaluation practically 
impossible?


I suspect I posted this in the wrong category completely, should 
have been under GDC (poss applies to LDC too, will test that)


Re: No CTFE of function

2017-08-26 Thread Cecil Ward via Digitalmars-d-learn

On Saturday, 26 August 2017 at 23:49:30 UTC, Cecil Ward wrote:

On Saturday, 26 August 2017 at 18:16:07 UTC, ag0aep6g wrote:

On Saturday, 26 August 2017 at 16:52:36 UTC, Cecil Ward wrote:
Any ideas as to why GDC might just refuse to do CTFE on 
compile-time-known inputs in a truly pure situation?


That's not how CTFE works. CTFE only kicks in when the 
*result* is required at compile time. For example, when you 
assign it to an enum. The inputs must be known at compile 
time, and the interpreter will refuse to go on when you try 
something impure. But those things don't trigger CTFE.


The compiler may choose to precompute any constant expression, 
but that's an optimization (constant folding), not CTFE.


I think I understand, but I'm not sure. I should have explained 
properly. I suspect what I should have said was that I was 
expecting an _optimisation_ and I didn't see it. I thought that 
a specific instance of a call to my pure function that has all 
compile-time-known arguments would just produce generated code 
that returned an explicit constant that is worked out by CTFE 
calculation, replacing the actual code for the general function 
entirely. So for example


auto foo() { return bar( 2, 3 ); }

(where bar is strongly pure and completely CTFE-able) should 
have been replaced by generated x64 code looking exactly 
literally like

auto foo() { return 5; }
expect that the returned result would be a fixed-length literal 
array of 32-but numbers in my case (no dynamic arrays anywhere, 
these I believe potentially involve RTL calls and the allocator 
internally).


I was expecting this optimisation to 'return literal constant 
only' because I have seen it before in other cases with GDC. 
Obviously generating a call that involves running the algorithm 
at runtime is a performance disaster when it certainly could have 
all been thrown away in the particular case in point and been 
replaced by a return of a precomputed value with zero runtime 
cost. So this is actually an issue with specific compilers, but I 
was wondering if I have missed anything about any D general rules 
that make CTFE evaluation practically impossible?


Re: Promoting TutorialsPoint's D tutorial

2017-08-26 Thread 12345swordy via Digitalmars-d

On Saturday, 26 August 2017 at 22:26:00 UTC, Ecstatic Coder wrote:

First I'd like to say the Dlang-Tour is a very good idea.

Personally, *everytime* I push the "next" button I'm surprised 
there is *only* 1 example, while I'd expect at least 3 or 4 
examples showing :
1. how to declare, use and print variables, including strings, 
slices and maps.

2. how to declare imperative functions
3. how to declare classes with attributes and methods
4. how to call functions and methods with the same dot 
notation, with or without parentheses


Anyway, that's not what I wanted to say in this post.

My point is that when you arrive to the further reading, you 
are invited to buy Ali's book :


"Basic resources

New to programming? This book is a great starting place for 
beginners"


I've no problem with that, but would it be possible to consider 
adding also a link to this tutorial in the same paragraph ?


https://www.tutorialspoint.com/d_programming/

It's not because TutorialsPoint pay me, but because it may be 
one of the best D tutorials out there for both beginner D 
programmers.


And honestly, at the moment it's not really that easy to reach 
this tutorial from the dlang website.


First you have to push on "Tutorials", then in the middle of 
the page you see a boring flat grey icon with this text beside :


"D programming
Unknown
January 1, 2015
A nice introductory tutorial to D programming. Available 
on-line and in the PDF format.

Website"

The text is fine, but unfortunately the impersonal icon and 
text ("D programming") aren't that inviting...


If you don't want to put the link on the "Further reading 
page", maybe would you consider putting this nice tutorial for 
beginners just under the four official D books, before the more 
advanced readings ?


I guess many beginner D programmers will thank you :)

Because a few month ago I've been that beginner D programmer, 
and sadly I've completely missed this perfect tutorial. And 
I've just explained you why...


So why not supposing other programmers will have the same 
problem, and maybe miss it just like me ?
The tutorial needs to cover advance topics such as manual memory 
management and the standard phobos library. It only scratchs the 
surface of the D programming language and it is not showing how 
powerful that D is, when it comes to the template programming 
when comparing to c++ template programming.




Re: No CTFE of function

2017-08-26 Thread Cecil Ward via Digitalmars-d-learn

On Saturday, 26 August 2017 at 18:16:07 UTC, ag0aep6g wrote:

On Saturday, 26 August 2017 at 16:52:36 UTC, Cecil Ward wrote:
Any ideas as to why GDC might just refuse to do CTFE on 
compile-time-known inputs in a truly pure situation?


That's not how CTFE works. CTFE only kicks in when the *result* 
is required at compile time. For example, when you assign it to 
an enum. The inputs must be known at compile time, and the 
interpreter will refuse to go on when you try something impure. 
But those things don't trigger CTFE.


The compiler may choose to precompute any constant expression, 
but that's an optimization (constant folding), not CTFE.


I think I understand, but I'm not sure. I should have explained 
properly. I suspect what I should have said was that I was 
expecting an _optimisation_ and I didn't see it. I thought that a 
specific instance of a call to my pure function that has all 
compile-time-known arguments would just produce generated code 
that returned an explicit constant that is worked out by CTFE 
calculation, replacing the actual code for the general function 
entirely. So for example


auto foo() { return bar( 2, 3 ); }

(where bar is strongly pure and completely CTFE-able) should have 
been replaced by generated x64 code looking exactly literally like

auto foo() { return 5; }
expect that the returned result would be a fixed-length literal 
array of 32-but numbers in my case (no dynamic arrays anywhere, 
these I believe potentially involve RTL calls and the allocator 
internally).


Re: Promoting TutorialsPoint's D tutorial

2017-08-26 Thread ag0aep6g via Digitalmars-d

On 08/27/2017 12:26 AM, Ecstatic Coder wrote:
My point is that when you arrive to the further reading, you are invited 
to buy Ali's book :


You can read Ali's book online for free.

[...]
I've no problem with that, but would it be possible to consider adding 
also a link to this tutorial in the same paragraph ?


https://www.tutorialspoint.com/d_programming/


I'd vote against that. It seems poorly written.

* There are multiple grammatical errors in the first paragraph alone.
* The hello work example is repeated multiple times on the first pages, 
always with a pointless `args` parameter on `main`.

* The download links go to 2.064.2, which is several years old.
* The "first D program" has the line `writeln("test!");`. Its output is 
given as "test", missing the exclamation mark.


As far as I see, it's just not good.


Re: Promoting TutorialsPoint's D tutorial

2017-08-26 Thread Ecstatic Coder via Digitalmars-d
And btw, I actually consider this tutorial more like the fifth D 
book.


Because once you download the PDF, honestly it's quite close to a 
real printed book.


Hence my suggestion to put it AT LEAST under the four official 
books.


I know it's not perfect. It could be simpler at some places, and 
more complete here and there.


But it's quite good, easy to download, and maybe the best D book 
0 dollars can buy you (unless you are kind enough and can afford 
to pay for it).


LDC 1.4.0-beta1

2017-08-26 Thread kinke via Digitalmars-d-announce

Hi everyone,

on behalf of the LDC team, I'm glad to announce LDC 1.4.0-beta1. 
The highlights of version 1.4 in a nutshell:


* Based on D 2.074.1.
* Shipping with ldc-build-runtime, a small D tool to easily 
(cross-)compile the runtime libraries yourself.

* Full Android support, incl. emulated TLS.
* Improved support for AddressSanitizer and libFuzzer. The 
libraries are shipped with the prebuilt Linux x86_64 and OSX 
packages.
* Prebuilt Linux x86_64 package shipping with LTO plugin, 
catching up with the OSX package.


Full release log and downloads: 
https://github.com/ldc-developers/ldc/releases/tag/v1.4.0-beta1


Thanks to everybody contributing!


Re: What's the best D programming book

2017-08-26 Thread Ecstatic Coder via Digitalmars-d

On Friday, 25 August 2017 at 21:08:59 UTC, Macdonal wrote:

What is the best D-Programming Book?


This one is good too :

https://www.tutorialspoint.com/d_programming/d_programming_pdf_version.htm

Not as good as Andrei or Ali's book, but still good enough for 
both beginner and experienced programmers, and you can download 
it quickly and easily for free (or a few dollars if you want to 
pay them for their good work).


Hence my suggestion to promote it more like the four official 
books you can buy...


Promoting TutorialsPoint's D tutorial

2017-08-26 Thread Ecstatic Coder via Digitalmars-d

First I'd like to say the Dlang-Tour is a very good idea.

Personally, *everytime* I push the "next" button I'm surprised 
there is *only* 1 example, while I'd expect at least 3 or 4 
examples showing :
1. how to declare, use and print variables, including strings, 
slices and maps.

2. how to declare imperative functions
3. how to declare classes with attributes and methods
4. how to call functions and methods with the same dot notation, 
with or without parentheses


Anyway, that's not what I wanted to say in this post.

My point is that when you arrive to the further reading, you are 
invited to buy Ali's book :


"Basic resources

New to programming? This book is a great starting place for 
beginners"


I've no problem with that, but would it be possible to consider 
adding also a link to this tutorial in the same paragraph ?


https://www.tutorialspoint.com/d_programming/

It's not because TutorialsPoint pay me, but because it may be one 
of the best D tutorials out there for both beginner D programmers.


And honestly, at the moment it's not really that easy to reach 
this tutorial from the dlang website.


First you have to push on "Tutorials", then in the middle of the 
page you see a boring flat grey icon with this text beside :


"D programming
Unknown
January 1, 2015
A nice introductory tutorial to D programming. Available on-line 
and in the PDF format.

Website"

The text is fine, but unfortunately the impersonal icon and text 
("D programming") aren't that inviting...


If you don't want to put the link on the "Further reading page", 
maybe would you consider putting this nice tutorial for beginners 
just under the four official D books, before the more advanced 
readings ?


I guess many beginner D programmers will thank you :)

Because a few month ago I've been that beginner D programmer, and 
sadly I've completely missed this perfect tutorial. And I've just 
explained you why...


So why not supposing other programmers will have the same 
problem, and maybe miss it just like me ?




Re: wrapping a C style delegate

2017-08-26 Thread Ali Çehreli via Digitalmars-d-learn

On 08/25/2017 05:49 PM, Nicholas Wilson wrote:

> I was thinking of something along those lines: but what about the
> lifetime of the passed delegate (the address of a local variable)? How
> can I ensure that it won't segfault when callback goes out of scope?
> I could new it with the GC but
> a) I'd rather have the wrapper be @nogc and
> b) i'd have to hold a reference to it or pin it because
> SomeAPIaddCallback will be in a driver somewhere and wouldn't get
> scanned by the GC.

Good points. I think you have to store a copy of the delegate in 
MyStruct and pass e.g. the array index of it as userData to 
intermediateCallback(). I think a Mallocator-based array would make the 
wrapper nogc.


Ali



Re: in for testing

2017-08-26 Thread Temtaime via Digitalmars-d

On Saturday, 26 August 2017 at 21:50:14 UTC, Johnson wrote:

while(str[i] in [' ', '\r', ...])

rather than having to do each test individually.


while(str[i].among(' ', '\r', ...))


Getting error in dmd testsuite

2017-08-26 Thread Thomas Mader via Digitalmars-d-learn

Hello,

I am building ldc on Nix (https://nixos.org/nix/) but keep 
getting an error while running the cppa.d test from the dmd 
testsuite (https://github.com/ldc-developers/dmd-testsuite).


1588:  ... runnable/cppa.d -L-lstdc++ (-g) -O
1588: Test failed.  The logged output:
1588: /tmp/nix-build-ldc-1.3.0.drv-0/build/bin/ldmd2 -conf= -m64 
-Irunnable  -L-lstdc++  
-od/tmp/nix-build-ldc-1.3.0.drv-0/build/dmd-testsuite/runnable 
-of/tmp/nix-build-ldc-1.3.0.drv-0/build/dmd-testsuite/runnable/cppa_0 runnable/cppa.d /tmp/nix-build-ldc-1.3.0.drv-0/build/dmd-testsuite/runnable/cppb.cpp.o
1588: 
/tmp/nix-build-ldc-1.3.0.drv-0/build/dmd-testsuite/runnable/cppa_0.o: In function `_Dmain':
1588: runnable/cppa.d:(.text._Dmain[_Dmain]+0x49f): undefined 
reference to `int foo15372(int)'
1588: runnable/cppa.d:(.text._Dmain[_Dmain]+0x4b2): undefined 
reference to `Foo15802::boo(int)'
1588: 
/tmp/nix-build-ldc-1.3.0.drv-0/build/dmd-testsuite/runnable/cppa_0.o:(.data.rel.ro._D4cppa6C131616__vtblZ[_D4cppa6C131616__vtblZ]+0x0): undefined reference to `C13161::dummyfunc()'
1588: 
/tmp/nix-build-ldc-1.3.0.drv-0/build/dmd-testsuite/runnable/cppa_0.o:(.data.rel.ro._D4cppa4Test6__vtblZ[_D4cppa4Test6__vtblZ]+0x0): undefined reference to `C13161::dummyfunc()'
1588: 
/tmp/nix-build-ldc-1.3.0.drv-0/build/dmd-testsuite/runnable/cppa_0.o:(.data.rel.ro._D4cppa7C13161a6__vtblZ[_D4cppa7C13161a6__vtblZ]+0x0): undefined reference to `C13161a::dummyfunc()'
1588: 
/tmp/nix-build-ldc-1.3.0.drv-0/build/dmd-testsuite/runnable/cppa_0.o:(.data.rel.ro._D4cppa5Testa6__vtblZ[_D4cppa5Testa6__vtblZ]+0x0): undefined reference to `C13161a::dummyfunc()'

1588: collect2: error: ld returned 1 exit status
1588: Error: 
/nix/store/df84hkmhrhx1c2zpvrhmk6aprhlzkasx-gcc-wrapper-6.4.0/bin/gcc failed with status: 1

1588:
1588:
1588: ==
1588: Test failed: expected rc == 0, exited with rc == 1
1588:
1588: make[2]: *** [Makefile:335: 
/tmp/nix-build-ldc-1.3.0.drv-0/build/dmd-testsuite/runnable/cppa.d.out] Error 1


Apart from that all other tests pass.
Any ideas?

It's running on Linux with gcc 6.4.0.


in for testing

2017-08-26 Thread Johnson via Digitalmars-d

while(str[i] in [' ', '\r', ...])

rather than having to do each test individually.


Re: HTOD

2017-08-26 Thread 12345swordy via Digitalmars-d

On Thursday, 24 August 2017 at 19:08:04 UTC, Jacob Carlborg wrote:

On 2017-08-24 17:02, 12345swordy wrote:


They have plans to add c++ support?


D can already link with C++, but not all features are 
supported. Like lambdas, for example, are not supported.


I am not asking that, I'm asking regarding the project mention 
earlier.


Re: @safe(bool)

2017-08-26 Thread 12345swordy via Digitalmars-d

On Saturday, 26 August 2017 at 02:19:53 UTC, bitwise wrote:

On Saturday, 26 August 2017 at 01:13:56 UTC, 12345swordy wrote:

On Friday, 25 August 2017 at 18:18:14 UTC, bitwise wrote:
On Thursday, 24 August 2017 at 14:59:05 UTC, 12345swordy 
wrote:

[...]

How about actually answering the question instead of 
assuming that I can't look up the definition of any words?


While your statement may sound nice to you, and to some 
others in this thread, that does not make it well-founded.
It's not a statement it's a question. Stop beating around the 
bush and just answer it already.


Ok..gonna have to assume your just trolling at this point.
Then you don't mind me dismissing your position as you fail to 
provide specific examples that I requested.


[Issue 17730] [scope][dip1000] std.algorithm.move can escape references to scope classes

2017-08-26 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17730

Walter Bright  changed:

   What|Removed |Added

Summary|[scope][dip1000] Can escape |[scope][dip1000]
   |references to scope classes |std.algorithm.move can
   |by moving   |escape references to scope
   ||classes

--


[Issue 17730] [scope][dip1000] Can escape references to scope classes by moving

2017-08-26 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17730

Walter Bright  changed:

   What|Removed |Added

 CC||bugzi...@digitalmars.com
  Component|dmd |phobos
   Hardware|x86_64  |All
 OS|Linux   |All

--- Comment #1 from Walter Bright  ---
Breaking it down to the following code:

import std.algorithm;

T moveImpl(T)(ref T source) {
T result = void;
moveEmplace(source, result);
return result;
}

T trustedMoveImpl(T)(ref T source) @trusted {
return moveImpl(source);
}

T move(T)(ref T source) {
// test @safe destructible
static if (__traits(compiles, (T t) @safe {}))
return trustedMoveImpl(source); // this is the path taken
else
return moveImpl(source);
}

class A { }

A makeA() @safe {
scope a = new A();
return move(a);   // should fail
}

The trouble is that moveEmplace() is @system, but trustedMoveImpl() paints it
to be @trusted, thus defeating the scope checks.

Re-categorized as a Phobos issue.

--


Re: Article: Writing Julia style multiple dispatch code in D

2017-08-26 Thread jmh530 via Digitalmars-d-announce
On Saturday, 26 August 2017 at 02:14:59 UTC, data pulverizer 
wrote:

On Friday, 25 August 2017 at 20:54:05 UTC, jmh530 wrote:
See below. I haven't implemented the random variables yet, but 
otherwise it seems to be working well. There is some 
trickiness with deprecated stuff that I had to hard code, but 
other than that it's pretty generic. Also, I think it is 
ignoring my check to only include public/export stuff. Not 
sure why that is.


module distribAlt;
...


Wow, I didn't realise that you'd go off and work on it. You 
need to start a package for it! I'll bookmark this one as a 
little reminder of mixin techniques.


Something I had wanted for a long time and once your article got 
my juices flowing. I had a hard time stopping once you got me 
started!


I'm going to try to add support for the random number generators 
and then create a PR for dstats.


Re: Future of export

2017-08-26 Thread Jerry via Digitalmars-d
Export was being implemented as an attribute last I saw of it, by 
the guy that made that DIP. Looks like he last worked on it some 
time in July.


https://github.com/Ingrater/dmd/commits/DllSupportD2


Re: Beta 2.076.0

2017-08-26 Thread Meta via Digitalmars-d-announce

On Saturday, 26 August 2017 at 12:32:54 UTC, Martin Nowak wrote:

On 08/18/2017 02:58 PM, Martin Nowak wrote:

First beta for the 2.076.0 release.


Second beta out now!

http://dlang.org/download.html#dmd_beta 
http://dlang.org/changelog/2.076.0.html


Compiler changes

AVX2 was added as -mcpu=avx2 architecture.
Fix Issue 17697 - Ddoc: automatically highlight URLs outside of 
macro arguments

**Implement DIP 1010 - Static foreach**

Awesome.


Re: Retrieve the data of all the threads together once all threads are completed in a task pool

2017-08-26 Thread vino via Digitalmars-d-learn

On Saturday, 26 August 2017 at 17:38:37 UTC, Vino.B wrote:

Hi,

  Can some one provide me an example of how to wait for all the 
threads to be completed in a taskPool and then retrieve the 
data of all the threads together instead of getting the data of 
each threads(after successfully executed). For example, the 
below test program outputs only one string "Welcome" but not 
the string "Home".


import std.stdio;
import std.parallelism;

string Data;
auto Textarr = [ "Welcome", "Home" ];

string fn (string text)
{ return text; }

string Submain ()
{
 foreach ( i; taskPool.parallel(Textarr[0 .. $], 1))
   {
auto Task = task(, i);
Task.executeInNewThread();
auto TaskData = Task.workForce;
Data ~= TaskData;
  }
  return Data;
}

void main ()
{
 Submain;
 writeln(Data[0 .. $]);
}

From,
Vino.B


Hi All,

  Was able to find a solution, but the output writes additional 
empty lines., request your help on how to print without the empty 
lines.


Program:
import std.stdio;
import std.parallelism;
import std.algorithm;
import std.string;
string Data;
auto Textarr = [ "Welcome", "Home" ];
string endresult;
string fn (string text)
{ return text; }

void main ()
{
 string text;
 auto endresult = taskPool.workerLocalStorage(text);
 foreach ( i; parallel(Textarr[0 .. $], 1))
   {
auto Task = task(, i);
Task.executeInNewThread();
auto TaskData = Task.workForce;
endresult.get ~= TaskData;
  }
  foreach (i; sums.toRange)
   { writeln(i); }
}

Output:
C:\Users\admin\Desktop\Script>rdmd test.d
Welcome
Home







C:\Users\admin\Desktop\Script>


Re: How do I send a message to a struct member function?

2017-08-26 Thread Enjoys Math via Digitalmars-d-learn

On Saturday, 26 August 2017 at 10:05:31 UTC, drug wrote:

26.08.2017 09:49, Enjoys Math пишет:


I have a series of structs each of which needs to spawn a 
worker thread on initialization.  There seems to be no way to 
send a message back to the struct for instance to cause a 
member function call on /that/ structs data.


Please advise me.
If it is appropriate for you the better way would be to send 
/that/ structs to the corresponding worker thread and then it 
can call any method.
Another way is you can during worker thread spawning pass 
thread id and then pass messages back to parent thread.


I can't do the second approach because the parent thread creates 
many instances of the struct, each of which need a call back to a 
method.


How do I do the first method (in code) because I've tried 20 
different ways already.


Re: No CTFE of function

2017-08-26 Thread ag0aep6g via Digitalmars-d-learn

On Saturday, 26 August 2017 at 16:52:36 UTC, Cecil Ward wrote:
Any ideas as to why GDC might just refuse to do CTFE on 
compile-time-known inputs in a truly pure situation?


That's not how CTFE works. CTFE only kicks in when the *result* 
is required at compile time. For example, when you assign it to 
an enum. The inputs must be known at compile time, and the 
interpreter will refuse to go on when you try something impure. 
But those things don't trigger CTFE.


The compiler may choose to precompute any constant expression, 
but that's an optimization (constant folding), not CTFE.


[Issue 6495] array(file.byLine()) is a problem

2017-08-26 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=6495

b2.t...@gmx.com changed:

   What|Removed |Added

 CC||b2.t...@gmx.com

--- Comment #11 from b2.t...@gmx.com ---
Isn't .byLineCopy fix this issue ?

--


[Issue 9253] Review Phobos algorithms and make them transient-safe where possible

2017-08-26 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=9253

b2.t...@gmx.com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |WONTFIX

--- Comment #4 from b2.t...@gmx.com ---
It looks like a failed initiative, not maintained since > 4 years.
Since summer 2016 and the initiative to put annotations on all the unittest
it's easier to locate the candidates.

--


[Issue 9882] Add UFCS-friendly printing functions

2017-08-26 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=9882

b2.t...@gmx.com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |WORKSFORME

--- Comment #9 from b2.t...@gmx.com ---
std.range.tee was added.

--


[Issue 10194] std.variant.Variant doesn't call the dtor of struct values

2017-08-26 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=10194

b2.t...@gmx.com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--


[Issue 17780] New: Malformed DDOC links in std.range

2017-08-26 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17780

  Issue ID: 17780
   Summary: Malformed DDOC links in std.range
   Product: D
   Version: D2
  Hardware: All
OS: All
Status: NEW
  Severity: normal
  Priority: P1
 Component: phobos
  Assignee: nob...@puremagic.com
  Reporter: b2.t...@gmx.com

See https://dlang.org/phobos/std_range.html#drop
and https://dlang.org/phobos/std_range.html#dropExactly

--


[Issue 11494] std.array.appender is not nothrow

2017-08-26 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=11494

b2.t...@gmx.com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |INVALID

--


No CTFE of function

2017-08-26 Thread Cecil Ward via Digitalmars-d-learn
I have a pure function that has constant inputs, known at 
compile-time, contains no funny stuff internally - looked at the 
generated code, and no RTL calls at all. But in a test call with 
constant literal values (arrays initialised to literal) passed to 
the pure routine GDC refuses to CTFE the whole thing, as I would 
expect it (based on previous experience with d and GDC) to simply 
generate a trivial function that puts out a block of 
CTFE-evaluated constant data corresponding to the input.


Unfortunately it's a bit too long to post in here. I've tried 
lots of variations. Function is marked nogc safe pure nothrow


Any ideas as to why GDC might just refuse to do CTFE on 
compile-time-known inputs in a truly pure situation? Haven't 
tried DMD yet. Can try LDC. Am using d.godbolt.org to look at the 
result, as I don't have a machine here to run a d compiler on.


Other things I can think of. Contains function-in-a-function 
calls, which are all unlined out in the generated code nicely, 
and not the first time I've done that with GDC either.


Switches: Am using -Os or -O2 or -O3 - tried all. Tuning to 
presume + enable the latest x86-64 instructions. release build, 
no bounds-checks.


[Issue 5093] improve error for importing std.c.windows.windows

2017-08-26 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=5093

b2.t...@gmx.com changed:

   What|Removed |Added

  Component|phobos  |dmd
 OS|Linux   |All

--


Re: gdc and ldc in MacPorts

2017-08-26 Thread Moritz Maxeiner via Digitalmars-d

On Saturday, 26 August 2017 at 15:28:32 UTC, MacPortsUser wrote:
On Wednesday, 23 August 2017 at 22:55:20 UTC, Moritz Maxeiner 
wrote:

[...]

If you aren't set on MacPorts, you can use homebrew for ldc.
With regards to gdc: A word of caution: Supporting it as a 
separate package is a bit of a hassle, since it technically 
lives as part of the main gcc codebase (and you actually 
compile gcc with the D frontend enabled).


I currently use MacPorts. The latest available version of DMD 
on MacPorts is also outdated (2.0.73.2 vs 2.0.75.1). How can I 
request to get the latest version into the MacPorts 
repositories?


No idea, I've never used MacPorts.


Re: gdc and ldc in MacPorts

2017-08-26 Thread MacPortsUser via Digitalmars-d
On Wednesday, 23 August 2017 at 22:55:20 UTC, Moritz Maxeiner 
wrote:
On Wednesday, 23 August 2017 at 18:03:22 UTC, lanphuonglien 
wrote:
Whilst DMD seems to be in MacPorts, GDC and LDC appear not to 
be. Is this right? If it is then it is wrong – it would be 
great if the person handling the DMD port could be supported 
to get a LDC and GDC ports in place.


I am a user of MacOS maybe once per year, but I'll help as I 
can.


If you aren't set on MacPorts, you can use homebrew for ldc.
With regards to gdc: A word of caution: Supporting it as a 
separate package is a bit of a hassle, since it technically 
lives as part of the main gcc codebase (and you actually 
compile gcc with the D frontend enabled).


I currently use MacPorts. The latest available version of DMD on 
MacPorts is also outdated (2.0.73.2 vs 2.0.75.1). How can I 
request to get the latest version into the MacPorts repositories?


Re: Compile Imported Modules

2017-08-26 Thread Jonathan Marler via Digitalmars-d

On Saturday, 26 August 2017 at 06:31:11 UTC, user1234 wrote:
On Friday, 25 August 2017 at 19:20:15 UTC, Jonathan Marler 
wrote:

On Friday, 25 August 2017 at 13:15:35 UTC, Daniel N wrote:
On Friday, 25 August 2017 at 13:03:11 UTC, Jonathan Marler 
wrote:

I can do:

dmd -ci prog.d -Isomelib -Ianotherlib


I love it, thanks for doing this!


Thanks, I think this is a really nice feature.  I've uploaded 
my build so that people can try it out here 
(https://github.com/marler8997/dmd/releases/tag/preview-compileimports).


Just download and unzip dmd2.zip, then run the addtopath.bat 
script in any shell you want to use this compiler in.  Thanks 
in advance to anyone who gives it a try and shares their 
thoughts.


How does that mix with implicit imports (public imports located 
in an explicit import) ?


All imported modules need to be compiled whether they were 
imported "explicitly" or "implicitly".  So both kinds work the 
same when it comes to this feature.


P.S. There are some cases where you can "get away" with not 
compiling a module, if it only contains declarations and 
templates for example.  In this case it kind of behaves like a 
header file in C/C++.


[Issue 17779] New: [REG2.075.0] Link failure (undefined references) with std.regex and std.conv

2017-08-26 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17779

  Issue ID: 17779
   Summary: [REG2.075.0] Link failure (undefined references) with
std.regex and std.conv
   Product: D
   Version: D2
  Hardware: All
OS: Linux
Status: NEW
  Keywords: link-failure, rejects-valid
  Severity: regression
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: dlang-bugzi...@thecybershadow.net

 test.d ///
import std.conv;
import std.regex;

void fun(string s = text(0)) {}
enum foo = regex(``);

void main() {}
///

dmd test.d

produces:

test.o: In function
`_D3std4conv17__T6toImplTAyaTiZ6toImplFNaNbNeikE3std5ascii10LetterCaseZAya':
test.d:(.text._D3std4conv17__T6toImplTAyaTiZ6toImplFNaNbNeikE3std5ascii10LetterCaseZAya[_D3std4conv17__T6toImplTAyaTiZ6toImplFNaNbNeikE3std5ascii10LetterCaseZAya]+0x5e):
undefined reference to
`_D3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6Result'
test.o: In function
`_D3std5array96__T5arrayTS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6ResultZ5arrayFNaNbNfS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6ResultZAa':
test.d:(.text._D3std5array96__T5arrayTS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6ResultZ5arrayFNaNbNfS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6ResultZAa[_D3std5array96__T5arrayTS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6ResultZ5arrayFNaNbNfS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6ResultZAa]+0xd):
undefined reference to
`_D3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6Result6lengthMFNaNbNdNiNfZm'
test.d:(.text._D3std5array96__T5arrayTS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6ResultZ5arrayFNaNbNfS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6ResultZAa[_D3std5array96__T5arrayTS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6ResultZ5arrayFNaNbNfS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6ResultZAa]+0x4f):
undefined reference to
`_D3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6Result5emptyMFNaNbNdNiNfZb'
test.d:(.text._D3std5array96__T5arrayTS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6ResultZ5arrayFNaNbNfS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6ResultZAa[_D3std5array96__T5arrayTS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6ResultZ5arrayFNaNbNfS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6ResultZAa]+0x5c):
undefined reference to
`_D3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6Result5frontMFNaNbNdNiNfZa'
test.d:(.text._D3std5array96__T5arrayTS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6ResultZ5arrayFNaNbNfS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6ResultZAa[_D3std5array96__T5arrayTS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6ResultZ5arrayFNaNbNfS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6ResultZAa]+0x9f):
undefined reference to
`_D3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6Result8popFrontMFNaNbNiNfZv'
test.o: In function
`_D3std4conv110__T8textImplTAyaTAyaTPvTAyaTiTAyaTiTAyaTaTAyaThTAyaThTAyaTbTAyaTbTAyaTbTAyaTbTAyaTbTAyaTbTAyaTAxaTAyaTAxaTAyaZ8textImplFNaNfAyaPvAyaiAyaiAyaaAyahAyahAyabAyabAyabAyabAyabAyabAyaAxaAyaAxaAyaZAya':
test.d:(.text._D3std4conv110__T8textImplTAyaTAyaTPvTAyaTiTAyaTiTAyaTaTAyaThTAyaThTAyaTbTAyaTbTAyaTbTAyaTbTAyaTbTAyaTbTAyaTAxaTAyaTAxaTAyaZ8textImplFNaNfAyaPvAyaiAyaiAyaaAyahAyahAyabAyabAyabAyabAyabAyabAyaAxaAyaAxaAyaZAya[_D3std4conv110__T8textImplTAyaTAyaTPvTAyaTiTAyaTiTAyaTaTAyaThTAyaThTAyaTbTAyaTbTAyaTbTAyaTbTAyaTbTAyaTbTAyaTAxaTAyaTAxaTAyaZ8textImplFNaNfAyaPvAyaiAyaiAyaaAyahAyahAyabAyabAyabAyabAyabAyabAyaAxaAyaAxaAyaZAya]+0xb9):
undefined reference to
`_D3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZS3std4conv47__T7toCharsVii10TaVE3std5ascii10LetterCasei1TiZ7toCharsFNaNbNiNfiZ6Result'

Re: Beta 2.076.0

2017-08-26 Thread user1234 via Digitalmars-d-announce

On Saturday, 26 August 2017 at 12:33:44 UTC, Martin Nowak wrote:

On 08/24/2017 09:40 PM, user1234 wrote:
I have a warning about the RPM package signature. It was 
already the case with 2.075.1


Please be so kind to file a bug report 
(https://issues.dlang.org/) with

a few more details and at best link it here :).


During today's beta setup i get:

---
Error : INVALID :dmd-2.076.0~b2-0.x86_64 (file-f5179ace): 
Signature check failure [6-File is unsigned]
Header hash SHA1 : OK 
(630453579fcada2ba9c4b86be40f0e21e10cd979)

MD5 : OK (7c1d4f49b7f0c10559cbbb7a976b68f2)
Package is not signed!
---

Note that i don't really care about the signature itself. The 
site where we download is secure but the error message is 
annoying.


Re: Building (and including libraries) without dub

2017-08-26 Thread Adam D. Ruppe via Digitalmars-d-learn

On Saturday, 26 August 2017 at 09:03:03 UTC, Hasen Judy wrote:
Building simple programs without dub is easy, just pass a list 
of .d source files to `dmd` or `ldc2`.


What if I want to include a 3rd party library?


It is also easy, just pass the list of its d source files to the 
compiler as well. Quite trivial, really.


Re: Beta 2.076.0

2017-08-26 Thread Martin Nowak via Digitalmars-d-announce
On 08/24/2017 09:40 PM, user1234 wrote:
> I have a warning about the RPM package signature. It was already the
> case with 2.075.1

Please be so kind to file a bug report (https://issues.dlang.org/) with
a few more details and at best link it here :).


Re: Beta 2.076.0

2017-08-26 Thread Martin Nowak via Digitalmars-d-announce
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

On 08/18/2017 02:58 PM, Martin Nowak wrote:
> First beta for the 2.076.0 release.

Second beta out now!

http://dlang.org/download.html#dmd_beta
http://dlang.org/changelog/2.076.0.html
-BEGIN PGP SIGNATURE-

iQIzBAEBCgAdFiEEpzRNrTw0HqEtE8TmsnOBFhK7GTkFAlmhanYACgkQsnOBFhK7
GTk0Ew/6A+W8X6qwG89zi0xeuQE6fhfpSU6xeXdfGqrR+sI3JVpQKBLj9Rw55cTn
dospw96SY0LPI33aoI9GyldjMVionei1IA3qoi7jlHsMJJIqEq5X7Z6qWQ+l2Zr2
Ba7IPQQuIIKRNIo7yLvOo0Qlx0pN9YZQdAi5NeTpjor5GOhxxlMBlRySKAk8MhzD
ZUUs7UHiJv7CtOvLIUjfm1k3gaaILeyX5cdHw4DCvciI6jzi55TLxKCkbOglJoGK
iqbSK4LosMnF85u+f/U79yqY4CGJzHEwV3katzSLN1rF/vtxb0w7a8fbb8O4dy0J
DSv2oJZVPKe+6GT7p0zs6wW63TFMyEm+s8DGOyp/foaexKl+OF0hKLp5YqG4RRQy
w5QeheF12pXWvZJGxS1+ANrVIJCyzeCIkTDVauOOnkqi3YrztzYqnAA3K8m465Pq
/MRbsoMWNJ+nmrTcaFc7TOa/G0ZZoftwErFhlc92WdF1YuJoabS+osRTvhguKN0S
3tuskrdXnT9cRIDlaowqyv+wsV/WwMnIfP2hmw9WpOPtEBhkhqKfo5ySUuxWGREQ
BeK71B6n3QroFe24PFPvWKT5RWyACD0/4y8i4KO8KKnXtwb7GawWmzL0AQ/YgyEf
d+doW+3MQE/293DJMM90/WDNf/VFatUJ0rfOzDeHzXCuuSTxIeM=
=wvD6
-END PGP SIGNATURE-


Re: Building (and including libraries) without dub

2017-08-26 Thread Mike Wey via Digitalmars-d-learn

On 26-08-17 12:02, drug wrote:

26.08.2017 12:03, Hasen Judy пишет:
Building simple programs without dub is easy, just pass a list of .d 
source files to `dmd` or `ldc2`.


What if I want to include a 3rd party library? Surely before dub 
existed, people were incorporating other libraries in their projects.


I want to learn how this works from first principles. I've been 
working with dynamic/interpreted languages for too long, I forgot what 
it's like to build native programs without a dependency manager.


Any help would be appreciated!


It's like C++. If you use Linux then:
```
dmd  -L/path/to/lib 
-llibrarynamewithoutlibprefix

```
or example
```
dmd myapp.d -L../otherproject/lib -lcool
```
line above compiles `myapp.d` file and links it with library `libcool` 
that is place in directory `../otherproject/lib`


You will need an extra `-L` to pass things to the linker with dmd.

```
dmd myapp.d -L-L../otherproject/lib -L-lcool
```

--
Mike Wey


Re: 2 Dimensional Array Sorting

2017-08-26 Thread Vino.B via Digitalmars-d-learn

On Saturday, 26 August 2017 at 10:45:13 UTC, Vino.B wrote:

On Saturday, 26 August 2017 at 10:07:53 UTC, user1234 wrote:

[...]


Hi,

 Now there is no duplicate , but the sequence is still not 
correct


[...]


Hi,

  If I execute the script several time's i still get the 
duplicate entries.


From,
Vino.B


Re: 2 Dimensional Array Sorting

2017-08-26 Thread Vino.B via Digitalmars-d-learn

On Saturday, 26 August 2017 at 10:07:53 UTC, user1234 wrote:

On Saturday, 26 August 2017 at 09:53:44 UTC, Vino.B wrote:

On Saturday, 26 August 2017 at 06:12:57 UTC, user1234 wrote:

[...]


Hi,
  I tired you logic, but doesn't seem to be working, as every 
time i execute the order of the file list is different as in 
the below program i have used the sort based on the file name.


[...]


Try with (a,b) => a[1].to!int < b[1].to!int as predicate. T


Hi,

 Now there is no duplicate , but the sequence is still not correct

Output: the File C:\Temp\TEAM2\PROD_TEAM\dir1 is after 
C:\Temp\TEAM3\EXPORT\dir2

C:\Users\admin\Desktop\Script\D>rdmd Ftest.d
C:\Temp\TEAM2\BACKUP\dir1 
35732

C:\Temp\TEAM2\TEAM\DIR1   40
C:\Temp\TEAM2\TEAM\DIR2   2228
C:\Temp\TEAM2\EXPORT\dir2 30
C:\Temp\TEAM3\BACKUP\dir1 
71465

C:\Temp\TEAM3\EXPORT\dir2 61
C:\Temp\TEAM2\PROD_TEAM\dir1  
35772


Required output
C:\Temp\TEAM2\BACKUP\dir1 
35732

C:\Temp\TEAM2\TEAM\DIR1   40
C:\Temp\TEAM2\TEAM\DIR2   2228
C:\Temp\TEAM2\EXPORT\dir2 30
C:\Temp\TEAM2\PROD_TEAM\dir1  
35772
C:\Temp\TEAM3\BACKUP\dir1 
71465

C:\Temp\TEAM3\EXPORT\dir2 61

From,
Vino.B


Re: 2 Dimensional Array Sorting

2017-08-26 Thread user1234 via Digitalmars-d-learn

On Saturday, 26 August 2017 at 09:53:44 UTC, Vino.B wrote:

On Saturday, 26 August 2017 at 06:12:57 UTC, user1234 wrote:

[...]


Hi,
  I tired you logic, but doesn't seem to be working, as every 
time i execute the order of the file list is different as in 
the below program i have used the sort based on the file name.


[...]


Try with (a,b) => a[1].to!int < b[1].to!int as predicate. T


Re: How do I send a message to a struct member function?

2017-08-26 Thread drug via Digitalmars-d-learn

26.08.2017 09:49, Enjoys Math пишет:


I have a series of structs each of which needs to spawn a worker thread 
on initialization.  There seems to be no way to send a message back to 
the struct for instance to cause a member function call on /that/ 
structs data.


Please advise me.
If it is appropriate for you the better way would be to send /that/ 
structs to the corresponding worker thread and then it can call any method.
Another way is you can during worker thread spawning pass thread id and 
then pass messages back to parent thread.


Re: Building (and including libraries) without dub

2017-08-26 Thread Hasen Judy via Digitalmars-d-learn

On Saturday, 26 August 2017 at 10:02:03 UTC, drug wrote:

It's like C++. If you use Linux then:
```
dmd  -L/path/to/lib 
-llibrarynamewithoutlibprefix

```
or example
```
dmd myapp.d -L../otherproject/lib -lcool
```
line above compiles `myapp.d` file and links it with library 
`libcool` that is place in directory `../otherproject/lib`


Thanks for your response!

So if I may make a guess, when you include a dependency in a dub 
project, what it ends up doing is compiling the dependency 
separately into a lib file then statically link the lib with your 
project?


Re: Building (and including libraries) without dub

2017-08-26 Thread drug via Digitalmars-d-learn

26.08.2017 12:03, Hasen Judy пишет:
Building simple programs without dub is easy, just pass a list of .d 
source files to `dmd` or `ldc2`.


What if I want to include a 3rd party library? Surely before dub 
existed, people were incorporating other libraries in their projects.


I want to learn how this works from first principles. I've been working 
with dynamic/interpreted languages for too long, I forgot what it's like 
to build native programs without a dependency manager.


Any help would be appreciated!


It's like C++. If you use Linux then:
```
dmd  -L/path/to/lib 
-llibrarynamewithoutlibprefix

```
or example
```
dmd myapp.d -L../otherproject/lib -lcool
```
line above compiles `myapp.d` file and links it with library `libcool` 
that is place in directory `../otherproject/lib`


Re: D for Android beta

2017-08-26 Thread Joakim via Digitalmars-d-announce

On Thursday, 1 June 2017 at 19:45:17 UTC, Ali Çehreli wrote:

Very exciting! :)

On 06/01/2017 12:31 PM, Joakim wrote:

> I will write up instructions on how to write an Android app
in D _on_
> your Android device

I hope it will be detailed enough for people who are very new 
to programming on the Android.


Ali


I've finally written up full instructions on building D apps for 
Android by using the linux cross-compiler or native Android 
compiler I provide:


https://wiki.dlang.org/Build_D_for_Android

The upcoming ldc 1.4 beta will be the first to include Android 
cross-compilation support for all supported host platforms, ie 
Windows, Mac, and linux, as all my Android patches have now been 
merged.  I'll stop putting out my own cross-compiler builds, 
though I'll maintain the native ldc package in the Termux package 
repo, once that's accepted.


If you want to build full OpenGLES GUI Android apps on your 
Android device, this wiki page shows you how to do that too.  You 
too can be one of the elite few building mobile apps on your 
mobile device, and in D!


Re: 2 Dimensional Array Sorting

2017-08-26 Thread Vino.B via Digitalmars-d-learn

On Saturday, 26 August 2017 at 06:12:57 UTC, user1234 wrote:

On Saturday, 26 August 2017 at 06:11:37 UTC, user1234 wrote:

On Saturday, 26 August 2017 at 06:01:15 UTC, Vino.B wrote:

Hi,

 Can someone provide me a example of sorting 2 Dimensional 
Array containing Filename and Size, and should be sorted by 
Size.


From,
Vino.B


void main(string[] args)
{
import std.stdio;
import std.algorithm.sorting;

string[2][] nameAndSize = [["b", "2"], ["a", "1"]];
auto s = nameAndSize.sort!((a,b) => a[0] < b[0] && a[1] < 
b[1]);

writeln(s);
}


I missed the "by Size" directive. So it's just:

void main(string[] args)
{
import std.stdio;
import std.algorithm.sorting;

string[2][] nameAndSize = [["b", "2"], ["a", "1"]];
auto s = nameAndSize.sort!((a,b) => a[1] < b[1]);
writeln(s);
}


Hi,
  I tired you logic, but doesn't seem to be working, as every 
time i execute the order of the file list is different as in the 
below program i have used the sort based on the file name.


Program:
import std.file: dirEntries, isFile, SpanMode;
import std.stdio: writeln, writefln;
import std.algorithm: filter, map, sort;
import std.path: globMatch, baseName;
import std.array: array, replace;
import std.typecons: tuple;
import std.parallelism;
import std.conv;
int SizeDir = 10;
string[][] Subdata;

auto Dirlst = [ "C:\\Temp\\TEAM2\\TEAM", 
"C:\\Temp\\TEAM2\\PROD_TEAM", "C:\\Temp\\TEAM3\\BACKUP", 
"C:\\Temp\\TEAM3\\EXPORT"];

string[][] SizeDirList (string Fs)
{
ulong subdirTotal = 0;
auto unc = "?\\"~Fs;
auto dFiles = dirEntries(unc, SpanMode.shallow).filter!(a => 
a.isDir && !globMatch(a.baseName, "*DND*")).map!(a => 
tuple(a.name, a.size)).array;

  foreach (d; dFiles)
{
auto SdFiles = dirEntries(d[0], SpanMode.depth).map!(a => 
tuple(a.size)).array;

foreach (f; parallel(SdFiles,1))
{ subdirTotal += f[0]; }
   ulong subdirTotalGB = (subdirTotal/1024);
   if (subdirTotalGB > SizeDir)
		{ Subdata ~= [d[0].replace("?\\", ""), 
to!string(subdirTotalGB)]; }

subdirTotal = 0;
}
return Subdata;
}
void main ()
{
 foreach (string Fs; parallel(Dirlst[0 .. $],1))
{
auto SizeDirListTask = task(, Fs);
SizeDirListTask.executeInNewThread();
auto SizeDirListTaskData = SizeDirListTask.yieldForce;
		auto sortedresult = SizeDirListTaskData.sort!((a,b) => a[0] < 
b[0]);

foreach(i; sortedresult[0 .. $])
writefln("%-(%-63s %)", i);
}

}

Output :The sequence is not correct and there are duplicates.

C:\Users\admin\Desktop\Script\D>rdmd Ftest.d
C:\Temp\TEAM2\TEAM\DIR1   40
C:\Temp\TEAM2\TEAM\DIR2   2228
C:\Temp\TEAM2\TEAM\DIR2   2228
C:\Temp\TEAM2\PROD_TEAM\dir1  
35772

C:\Temp\TEAM2\TEAM\DIR2   2228
C:\Temp\TEAM2\PROD_TEAM\dir1  
35772
C:\Temp\TEAM3\BACKUP\dir1 
71465

C:\Temp\TEAM3\EXPORT\dir2 61

C:\Users\admin\Desktop\Script\D>rdmd Ftest.d
C:\Temp\TEAM2\TEAM\DIR1   40
C:\Temp\TEAM2\TEAM\DIR2   2228
C:\Temp\TEAM2\PROD_TEAM\dir1  
35772
C:\Temp\TEAM3\BACKUP\dir1 
71465

C:\Temp\TEAM3\EXPORT\dir2 61

C:\Users\admin\Desktop\Script\D>rdmd Ftest.d
C:\Temp\TEAM2\TEAM\DIR1   40
C:\Temp\TEAM2\TEAM\DIR2   2228
C:\Temp\TEAM3\BACKUP\dir1 
71465

C:\Temp\TEAM3\EXPORT\dir2 61
C:\Temp\TEAM2\PROD_TEAM\dir1  
35772


Required Output :C:\Temp\TEAM2\..., C:\Temp\TEAM3...

C:\Temp\TEAM2\TEAM\DIR1   40
C:\Temp\TEAM2\TEAM\DIR2   2228
C:\Temp\TEAM2\PROD_TEAM\dir1  
35772
C:\Temp\TEAM3\BACKUP\dir1 
71465

C:\Temp\TEAM3\EXPORT\dir2 61

From,
Vino.B



Building (and including libraries) without dub

2017-08-26 Thread Hasen Judy via Digitalmars-d-learn
Building simple programs without dub is easy, just pass a list of 
.d source files to `dmd` or `ldc2`.


What if I want to include a 3rd party library? Surely before dub 
existed, people were incorporating other libraries in their 
projects.


I want to learn how this works from first principles. I've been 
working with dynamic/interpreted languages for too long, I forgot 
what it's like to build native programs without a dependency 
manager.


Any help would be appreciated!


Re: spawnProcess: Exit parent process without terminating child process

2017-08-26 Thread FreeSlave via Digitalmars-d-learn

On Friday, 25 August 2017 at 19:55:09 UTC, timvol wrote:

Hi guys,

I want execute a process. I know, I can execute a process using 
"spawnProcess" or "executeShell". But I want exit the parent.


My code for testing purposes is the following:

int main(string[] asArgs_p)
{
if ( (asArgs_p.length >= 2) && asArgs_p[1].isDir() )
{
while(1) {}
}
else
{
import std.process;
spawnProcess([asArgs_p[0], "test"]);
}
return 0;
}

So, starting the application without any parameter, it calls 
"spawnProcess" with an parameter. Now, I want that the parent 
process (the process started without parameter) terminates, 
while the created process remains running.


At the moment, the parent process creates the child and remains 
open (because of the while(1)-loop).


Any ideas how I can exit the parent and keep the child process 
running?


Note that in your particular case the spawnProcess as used now 
should work too. It should run in parallel with its parent. 
Parent will exit and child process will remain. I'm not sure why 
the parent does not exit in your case. When starting this program 
without parameters it will not run into while(1) branch at all.


Re: spawnProcess: Exit parent process without terminating child process

2017-08-26 Thread FreeSlave via Digitalmars-d-learn

On Friday, 25 August 2017 at 19:55:09 UTC, timvol wrote:

Hi guys,

I want execute a process. I know, I can execute a process using 
"spawnProcess" or "executeShell". But I want exit the parent.


My code for testing purposes is the following:

int main(string[] asArgs_p)
{
if ( (asArgs_p.length >= 2) && asArgs_p[1].isDir() )
{
while(1) {}
}
else
{
import std.process;
spawnProcess([asArgs_p[0], "test"]);
}
return 0;
}

So, starting the application without any parameter, it calls 
"spawnProcess" with an parameter. Now, I want that the parent 
process (the process started without parameter) terminates, 
while the created process remains running.


At the moment, the parent process creates the child and remains 
open (because of the while(1)-loop).


Any ideas how I can exit the parent and keep the child process 
running?


Running process in detached state will be available in the future 
versions of Phobos. This functionality has been already merged in 
master https://github.com/dlang/phobos/pull/5483


Until then you may consider to use a third-party library 
https://github.com/FreeSlave/detached


Re: pipeProcess not returning immediately

2017-08-26 Thread FoxyBrown via Digitalmars-d-learn

On Saturday, 26 August 2017 at 06:24:26 UTC, user1234 wrote:
On Saturday, 26 August 2017 at 01:13:35 UTC, Johnson Jones 
wrote:
I am running ffplay.exe and my application does not return 
immediately from pipeProcess. I have to close ffplay for my 
program to continue execution.


No process is asynchronous in std.process.

If you don't want to block your program then wrap it in a 
thread that checks periodically for termination.


Either you are wrong or the docks are wrong:

https://dlang.org/phobos/std_process.html

pipeProcess also spawns a child process which runs in 
**parallel** with its parent. However, instead of taking 
arbitrary streams, it automatically creates a set of pipes that 
allow the parent to communicate with the child through the 
child's standard input, output, and/or error streams. This 
function corresponds roughly to C's popen function.





Re: testing for deprecation

2017-08-26 Thread user1234 via Digitalmars-d-learn

On Friday, 25 August 2017 at 20:35:52 UTC, jmh530 wrote:
On Thursday, 1 September 2016 at 11:13:42 UTC, rikki cattermole 
wrote:


That is a first that somebody wanted it.
Bug report please!


I just ran across this with

deprecated {
void foo();
}
void main() {
pragma(msg, __traits(getAttributes, foo));
}

producing just tuple().


getAttributes is made for UDAs only.


How do I send a message to a struct member function?

2017-08-26 Thread Enjoys Math via Digitalmars-d-learn


I have a series of structs each of which needs to spawn a worker 
thread on initialization.  There seems to be no way to send a 
message back to the struct for instance to cause a member 
function call on /that/ structs data.


Please advise me.


Re: Compile Imported Modules

2017-08-26 Thread user1234 via Digitalmars-d

On Friday, 25 August 2017 at 19:20:15 UTC, Jonathan Marler wrote:

On Friday, 25 August 2017 at 13:15:35 UTC, Daniel N wrote:
On Friday, 25 August 2017 at 13:03:11 UTC, Jonathan Marler 
wrote:

I can do:

dmd -ci prog.d -Isomelib -Ianotherlib


I love it, thanks for doing this!


Thanks, I think this is a really nice feature.  I've uploaded 
my build so that people can try it out here 
(https://github.com/marler8997/dmd/releases/tag/preview-compileimports).


Just download and unzip dmd2.zip, then run the addtopath.bat 
script in any shell you want to use this compiler in.  Thanks 
in advance to anyone who gives it a try and shares their 
thoughts.


How does that mix with implicit imports (public imports located 
in an explicit import) ?


Re: Best syntax for a diagonal and vertical slice

2017-08-26 Thread Ilya Yaroshenko via Digitalmars-d-learn

On Saturday, 22 July 2017 at 20:55:06 UTC, kerdemdemir wrote:

We have awesome way for creating slices like:

a = new int[5];
int[] b = a[0..2];

But what about if I have 2D array and I don't want to go 
vertical. Something like :


int[3][3] matrix = [
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ]
];

I believe I can use std.range function "RoundRobin"(or maybe it 
won't work with 2D array directly) for having a good looking 
vertical slice which will have 1,4,7 or 2,5,8 or 3,6,9 in my 
example above.


And what if I want to go diagonal like 1,5,9 or 3,5,7 in the 
example above. Is there a good solution in std without using 
for loops?


I have one more requirement for fulfilling the task that I 
working on. This slices do not have to be the same size as the 
array. For example in the example above slice size could have 2 
instead of 3. In this case I need to have slices like 
1,5;2,6;4,8;5,9 ... and so on for diagonal case.


Erdem

Ps: Converting the 2D array to 1D array is possible in my case.


Hello Erdem,

You may want to use mir-algorithm DUB package. It is a D tensor 
library.

https://github.com/libmir/mir-algorithm

import mir.ndslice;

auto slice = matrix[0].ptr.sliced(3, 3);
auto row = matrix[0];
auto col = matrix[0 .. $, 0];

A lot of examples with diagonal and sub-diagonals can be found 
here

http://docs.algorithm.dlang.io/latest/mir_ndslice_topology.html#.diagonal

Best,
Ilya


Re: pipeProcess not returning immediately

2017-08-26 Thread user1234 via Digitalmars-d-learn

On Saturday, 26 August 2017 at 01:13:35 UTC, Johnson Jones wrote:
I am running ffplay.exe and my application does not return 
immediately from pipeProcess. I have to close ffplay for my 
program to continue execution.


No process is asynchronous in std.process.

If you don't want to block your program then wrap it in a thread 
that checks periodically for termination.


Re: 2 Dimensional Array Sorting

2017-08-26 Thread user1234 via Digitalmars-d-learn

On Saturday, 26 August 2017 at 06:11:37 UTC, user1234 wrote:

On Saturday, 26 August 2017 at 06:01:15 UTC, Vino.B wrote:

Hi,

 Can someone provide me a example of sorting 2 Dimensional 
Array containing Filename and Size, and should be sorted by 
Size.


From,
Vino.B


void main(string[] args)
{
import std.stdio;
import std.algorithm.sorting;

string[2][] nameAndSize = [["b", "2"], ["a", "1"]];
auto s = nameAndSize.sort!((a,b) => a[0] < b[0] && a[1] < 
b[1]);

writeln(s);
}


I missed the "by Size" directive. So it's just:

void main(string[] args)
{
import std.stdio;
import std.algorithm.sorting;

string[2][] nameAndSize = [["b", "2"], ["a", "1"]];
auto s = nameAndSize.sort!((a,b) => a[1] < b[1]);
writeln(s);
}


Re: 2 Dimensional Array Sorting

2017-08-26 Thread user1234 via Digitalmars-d-learn

On Saturday, 26 August 2017 at 06:01:15 UTC, Vino.B wrote:

Hi,

 Can someone provide me a example of sorting 2 Dimensional 
Array containing Filename and Size, and should be sorted by 
Size.


From,
Vino.B


void main(string[] args)
{
import std.stdio;
import std.algorithm.sorting;

string[2][] nameAndSize = [["b", "2"], ["a", "1"]];
auto s = nameAndSize.sort!((a,b) => a[0] < b[0] && a[1] < 
b[1]);

writeln(s);
}


2 Dimensional Array Sorting

2017-08-26 Thread Vino.B via Digitalmars-d-learn

Hi,

 Can someone provide me a example of sorting 2 Dimensional Array 
containing Filename and Size, and should be sorted by Size.


From,
Vino.B