Passing directory as compiler argument not finding file

2018-04-11 Thread Jamie via Digitalmars-d-learn

With a directory structure as follows:

run/
A/
a.d

Where a.d is:
===
module A.d;


I'm attempting to compile from the run/ directory. If I run with
dmd ../A/a.d

it compiles successfully, however if I pass it the directory
dmd -I=../A a.d

it doesn't compile. Also, if I pass the exact directory
dmd -I=/../A a.d

it doesn't compile.

Both times I get the error
Error: module `a` is in the file 'a.d' which cannot be read

However it then shows the import path as being
import path[0] = ../A

for the first way and
import path[0] = /../A
for the second way.

Am I using the -I compiler option incorrectly?


Re: Escaping address of

2018-04-11 Thread Uknown via Digitalmars-d-learn
On Wednesday, 11 April 2018 at 16:25:20 UTC, Jonathan M Davis 
wrote:

[...]


Adding a destructor makes the compiler return an error about 
lifetimes, with or without -dip1000


https://run.dlang.io/is/ddXqNu


Re: Is using function() in templates possible at all?

2018-04-11 Thread Nicholas Wilson via Digitalmars-d-learn

On Wednesday, 11 April 2018 at 22:13:33 UTC, Sjoerd Nijboer wrote:

On Wednesday, 11 April 2018 at 21:29:27 UTC, Alex wrote:

I would say, alias template parameter is your friend.
https://dlang.org/spec/template.html#TemplateAliasParameter

class SortedList(T, alias comparer)


It works, thank you!
But just to be shure, there's no way to have this more strongly 
typed in D so I can enforce that `comparer`is a funciton or 
delegate with a specific definition?



There is, with template constraints:

class SortedList(T, alias comparer) if(is(typeof(comparer(T.init) 
: int))

{
//...
}


Re: Parse .eml files

2018-04-11 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 11 April 2018 at 15:20:08 UTC, Martin Tschierschke 
wrote:


My question in the moment is, how do I invoke Thunderbird to 
display a certain single mail (or maildir) file?
How do I use Thunderbird as the client, to show, to answer or 
to forward these mails.
An alternative would be to use a browser based mailer? Handling 
all attachments is an other purpose.


Can you use executeShell and call Thunderbird from the command 
line? Something like


executeShell("thunderbird -compose \"subject='My Christmas 
Gift',body='Please send me a new car',to='sa...@claus.net'")


http://kb.mozillazine.org/Command_line_arguments_%28Thunderbird%29


Re: Is using function() in templates possible at all?

2018-04-11 Thread Sjoerd Nijboer via Digitalmars-d-learn

On Wednesday, 11 April 2018 at 21:29:27 UTC, Alex wrote:

I would say, alias template parameter is your friend.
https://dlang.org/spec/template.html#TemplateAliasParameter

class SortedList(T, alias comparer)


It works, thank you!
But just to be shure, there's no way to have this more strongly 
typed in D so I can enforce that `comparer`is a funciton or 
delegate with a specific defenition?
Right now i'm relying on the template to error on some different 
place which might not give such a readable error message to the 
user.


Re: Is using function() in templates possible at all?

2018-04-11 Thread Alex via Digitalmars-d-learn

On Wednesday, 11 April 2018 at 21:07:03 UTC, Sjoerd Nijboer wrote:


class SortedList(T, int function(T) comparer)


I would say, alias template parameter is your friend.
https://dlang.org/spec/template.html#TemplateAliasParameter

´´´
import std.stdio;
import std.range;

void main()
{
auto list = new SortedList!(Vector3, v => v.y)();

assert(list.array.empty);
list.foo(Vector3.init);
}

struct Vector3 { float x, y, z; }

class SortedList(T, alias comparer)
{
T[] array;

auto foo(T t)
{
for(int i = 0; i < array.length; i++)
{
if(comparer(this.array[i]) <=  comparer(t))
{
//do stuff
array[i] = t;
}
}
}
}
´´´


Re: Strange Thread Causing Duplicating `writeln`

2018-04-11 Thread Jonathan via Digitalmars-d-learn
On Tuesday, 10 April 2018 at 23:59:08 UTC, Steven Schveighoffer 
wrote:

On 4/9/18 6:56 PM, Jonathan wrote:

On Monday, 9 April 2018 at 22:53:31 UTC, Jonathan wrote:

On Monday, 9 April 2018 at 22:49:07 UTC, Cym13 wrote:
I don't know, but I can't reproduce either with dmd or ldc. 
What was your compilation line?


dmd -run file.d


I am on Window 10 btw.


It's a windows 32-bit issue (specifically, DMC's FILE *, upon 
which std.stdio.File is based, is thread unsafe).


Try -m64.

https://issues.dlang.org/show_bug.cgi?id=18483
http://bugzilla.digitalmars.com/issues/show_bug.cgi?id=327

-Steve


Hum, thank you.


Is using function() in templates possible at all?

2018-04-11 Thread Sjoerd Nijboer via Digitalmars-d-learn

I am trying to do a binary insert into my sorted array.
To sort classes and structs I would like to give a delegate `(t) 
=> t.myValue` to sort on that value whitout having to implement 
an interface or specifically declare opCmp for every class I want 
to have sorted.
After all, I might want one group of objects of a given class 
sorted in one way and another group of objects sorted on another 
way depending on the usecase.
In C# this is done by passing on a lambda in for instance a LinQ 
expression to sort such list after insertion, and is also usefull 
in other circumstances.


But is it possible in D to do something simular but then pass on 
this Function() during compile time?


something like
`
void main() { SortedList!(Vector3, (v) => v.y) list; }

struct Vector3 { float x, y, z; }

class SortedList(T, int function(T) comparer)
{
T[] array;

int foo(T t)
{
for(int i = 0; i < array.lenght; i++)
{
if(comparer(this.otherT) <=  comparer(t))
{
//do stuff
array[i] = t;
}
}
}
}
`



Hospitals Depending On Telephone Interpretation Services to Communicate With Patients Speaking Different Languages

2018-04-11 Thread markmst via Digitalmars-d-learn
A healthcare facility called River's Edge Hospital and Clinic in 
Minnesota is using a special video interpretation service that 
can connect an interpreter with a patient through a video 
conference to offer necessary interpretation services.If the 
patient feels that there is an inadequacy in the interpretation 
services provided to them, they may complain about the hospital 
to the state Department of Human Rights.


It is a special video conference service that offers a convenient 
and affordable means to get in touch with an interpreter whose 
services could be needed only on certain occasions. Stephanie 
Holden, the CMO of the hospital said that the service was started 
at the hospital about a year ago.


She shared that her hospital has just migrated from phone to 
video. It has been a good change for them to have this special 
video service available. Both the patient and the healthcare 
providers can see the interpreter simultaneously. Holden feels 
that there is a greater value when the faces of the interpreters 
can be seen rather than just hearing their voices. She also added 
that the step taken by the hospital has fetched them positive 
reviews on the satisfaction surveys conducted on their patients.


On an average, the hospital uses this service about 5 to 10 times 
every month. Mostly, the patients in the emergency and urgent 
care department use this interpretation service. The hospital 
only uses those interpreters who are certified in healthcare 
interpretation services.


www.language-school.hk


Re: Escaping address of

2018-04-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, April 11, 2018 16:08:06 Nick Treleaven via Digitalmars-d-learn 
wrote:
> Is this a known bug? With v2.079.0, with or without -dip1000:
>
> @safe unittest
> {
>  struct S
>  {
>  int i;
>  }
>  auto p = ().i;
> }
>
> The address of field `i` should not escape, right? It's also
> incorrectly allowed when using an lvalue of S (when -dip1000 is
> not present).

Without -dip1000, @safe code specifically disallows & on local variables.
Beyond that, I'm not sure. Arguably, it should disallow it entirely, though
if the compiler can guarantee that the address is on the heap, then it's
probably fine. However, IMHO, regardless of @safe or DIP 1000, your example
should not be legal period. It's taking the address of the field of a
temporary, which is _never_ a valid thing to do, @safe or not. I guess that
the compiler isn't smart enough to figure out that that's what's going on,
since it's i itself that it's getting the address for and not the temporary
directly, but even if it can't be smart enough for some reason to figure out
that what's going on here is never okay, that & should still be @system,
since it's not taking the address of something on the heap.

- Jonathan M Davis



Escaping address of

2018-04-11 Thread Nick Treleaven via Digitalmars-d-learn

Is this a known bug? With v2.079.0, with or without -dip1000:

@safe unittest
{
struct S
{
int i;
}
auto p = ().i;
}

The address of field `i` should not escape, right? It's also 
incorrectly allowed when using an lvalue of S (when -dip1000 is 
not present).


Re: Parse .eml files

2018-04-11 Thread Martin Tschierschke via Digitalmars-d-learn

On Wednesday, 11 April 2018 at 02:37:39 UTC, bachmeier wrote:

On Monday, 9 April 2018 at 19:17:20 UTC, Adam D. Ruppe wrote:

[...]

I had a chance to try this out and it worked without a problem. 
I did have to download color.d in addition to the other 
dependencies you listed. In the event that Google brings 
someone here, this is a complete working program:


import std.file, std.stdio, std.string;
import arsd.email;

void main(string[] args) {
  string[] f = std.file.readText(args[1]).splitLines();
  auto em = new IncomingEmailMessage(f);
  writeln("From: ", em.from);
  writeln("To: ", em.to);
  writeln("Subject: ", em.subject);
  writeln(em.textMessageBody);
}

Compile with

dmd *.d -ofreademail

And run

./reademail 'email message.eml'


Very cool, I was looking for something similar, thank you both 
for sharing!


My goal is to store mails in a mysql table with fulltext index, 
connected to a existing old crm solution via the email address as 
a foreign key.


My question in the moment is, how do I invoke Thunderbird to 
display a certain single mail (or maildir) file?
How do I use Thunderbird as the client, to show, to answer or to 
forward these mails.
An alternative would be to use a browser based mailer? Handling 
all attachments is an other purpose.





Re: Infer return type from assignment

2018-04-11 Thread ixid via Digitalmars-d-learn

On Wednesday, 11 April 2018 at 14:33:06 UTC, Adam D. Ruppe wrote:

On Wednesday, 11 April 2018 at 14:26:53 UTC, ixid wrote:
Is it possible to infer a template's return type from what 
it's assigned to? If not is this a difficult or worthless 
feature to add?


Not really. The function call needs to make sense by itself:

fun(a)

needs to be a complete thing for a lot of things in the 
language to work. Type checking assumes it is there, inference 
assumes it is there, overloading assumes it s there, etc.


void foo(int);
void foo(float);

foo(fun(a)); // what happens?


So I don't say anything is impossible that isn't a paradox... 
but the effort level to solve all these problems would be 
really high for D.


I am sure there are all sorts of thorns involved but for your 
example a somewhat arbitrarily defined fallback hierarchy of 
types from most complex to most simple, with it matching the most 
'simple' that it can.


Re: Infer return type from assignment

2018-04-11 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 11 April 2018 at 14:26:53 UTC, ixid wrote:
Is it possible to infer a template's return type from what it's 
assigned to? If not is this a difficult or worthless feature to 
add?


Not really. The function call needs to make sense by itself:

fun(a)

needs to be a complete thing for a lot of things in the language 
to work. Type checking assumes it is there, inference assumes it 
is there, overloading assumes it s there, etc.


void foo(int);
void foo(float);

foo(fun(a)); // what happens?


So I don't say anything is impossible that isn't a paradox... but 
the effort level to solve all these problems would be really high 
for D.


Infer return type from assignment

2018-04-11 Thread ixid via Digitalmars-d-learn
Is it possible to infer a template's return type from what it's 
assigned to? If not is this a difficult or worthless feature to 
add?


OUT fun(IN, OUT)(IN value) {
return value.to!OUT;
}

void main() {
float a = 5.0;
int b = fun(a);
}