Re: New to D

2016-10-21 Thread Mike Parker via Digitalmars-d-learn

On Saturday, 22 October 2016 at 05:41:34 UTC, Mark wrote:

Thanks for the fast reply.

That did work. But now the error is on the line:

 dictionary[word] = newId;

I changed the value to 10, still errors. ??


everything else is as before.

thanks.


For simple single file experiments like this, I strongly 
recommend you ditch Code::Blocks (or any IDE) and just use a text 
editor + the command line. All you need is the compiler on the 
path, then you can do this:


dmd foo.d

Any errors will be shown right in the console. Try that out then 
come back and post the error messages you see. Preferably 
something more informative than "the error is on the line" :)


Re: New to D

2016-10-21 Thread Mark via Digitalmars-d-learn

Thanks for the fast reply.

That did work. But now the error is on the line:

 dictionary[word] = newId;

I changed the value to 10, still errors. ??


everything else is as before.

thanks.


Re: New to D

2016-10-21 Thread rikki cattermole via Digitalmars-d-learn

On 22/10/2016 6:25 PM, Mark wrote:

Hello, Im a 3rd year Comp Sci student in Edmonton Alberta, Canada.

Ive learned how to use C, and dabbled in C++ in school. Im also in a Oop
course using Java.

I picked up the book The D Programming Language by Alexrei Alexandrescu
a few years ago.
Lately Im really wanting to get into D, as It seems like a better
version of C, and feels like java in a way.


Things have changed since TDPL was created but here is the errata which 
says what[0].



However;

Ive run into a bit of a problem while writing some code. Im not sure if
Im doing something wrong, or maybe the things Im using are depreciated??

Code Blocks does not give any messages as to what is going wrong. I
haven't configured anything, and am not familiar with messing around
with IDE settings.

Its directly based off of the example on page 8.

here is the code that does not compile:


import std.stdio, std.string;

void main() { ... }

void dict() {

uint[string] dictionary;

foreach(line; stdin.byLine()) {

//chunk = splitter(strip(line); ## errors because of splitter

foreach(word; splitter(strip(line))) { ## errors because of
splitter ??

if(word in dictionary) continue;

//writeln(dictionary.length);  ## gives 0 ??

auto newID = dictionary.length;
dictionary[word] = newId;


writeln(newID, ' ', word);

}
}

}




Im not sure what Im doing wrong here.

modifying the code to just print the result of splitLines results in the
entire line.
and just having splitter give a sting to print also errors.

Please help, thanks!


Oh splitter is in std.algorithm.iteration[1].
Import it and it should work.

[0] http://erdani.com/tdpl/errata/
[1] http://dlang.org/phobos/std_algorithm_iteration.html#.splitter



New to D

2016-10-21 Thread Mark via Digitalmars-d-learn

Hello, Im a 3rd year Comp Sci student in Edmonton Alberta, Canada.

Ive learned how to use C, and dabbled in C++ in school. Im also 
in a Oop course using Java.


I picked up the book The D Programming Language by Alexrei 
Alexandrescu a few years ago.
Lately Im really wanting to get into D, as It seems like a better 
version of C, and feels like java in a way.




However;

Ive run into a bit of a problem while writing some code. Im not 
sure if Im doing something wrong, or maybe the things Im using 
are depreciated??


Code Blocks does not give any messages as to what is going wrong. 
I haven't configured anything, and am not familiar with messing 
around with IDE settings.


Its directly based off of the example on page 8.

here is the code that does not compile:


import std.stdio, std.string;

void main() { ... }

void dict() {

uint[string] dictionary;

foreach(line; stdin.byLine()) {

//chunk = splitter(strip(line); ## errors because of 
splitter


foreach(word; splitter(strip(line))) { ## errors because 
of splitter ??


if(word in dictionary) continue;

//writeln(dictionary.length);  ## gives 0 ??

auto newID = dictionary.length;
dictionary[word] = newId;


writeln(newID, ' ', word);

}
}

}




Im not sure what Im doing wrong here.

modifying the code to just print the result of splitLines results 
in the entire line.

and just having splitter give a sting to print also errors.

Please help, thanks!



Re: Render SVG To Display And Update Periodically

2016-10-21 Thread Jason C. Wells via Digitalmars-d-learn
First, thank you for taking the time to help me with something 
that should be trivial.


I've done the above listing of file on the command line but I'm 
still stuck. I'm starting to think that I might actually be 
tripping over bugs, but I'm not confident enough to believe that 
without some confirmation.


I have the following directory structure from the zipfiles found 
in the repositories posted by ketmar.


nanovg_demo
- iv (was renamed from nanovg based on dmd error messages)
-- arsd (was renamed from arsd-master based on dmd error messages)

To proceed, I would attempt a compile. Then I would add the file 
that was producing an error to the command line and try again. I 
got this far.


Via cmd.exe:

  nanovg_demo>dmd example.d iv\arsd\color.d 
iv\arsd\simpledisplay.d iv\perf.d


  iv\perf.d(41): Error: module iv.nanovg.nanovg from file 
iv\nanovg.d must be

  imported with 'import iv.nanovg.nanovg;'

  demo.d(6): Error: module iv.nanovg.nanovg from file iv\nanovg.d 
must be

  imported with 'import iv.nanovg.nanovg;'

iv/nanovg/nanovg does not exist in the source code zip files. (I 
was reluctant to duplicate nanonvg into iv\nanovg because 
somewhere I learned that copy-pasting code is a bad idea.)


  demo.d(7): Error: module oui is in file 'iv\nanovg\oui.d' which 
cannot be read


oui.d does not exist anywhere. There is, however, a oui directory.

As a side note, I did have some success. I am able to compile 
nanovg.lib quite easily (from tips provided a few messages ago). 
It's when I try to compile the demo that I get stuck.


Regards,
Jason C. Wells


Re: libcurl

2016-10-21 Thread Suliman via Digitalmars-d
On Saturday, 22 October 2016 at 01:20:52 UTC, Andrei Alexandrescu 
wrote:
Guess we need to get ready! 
https://curl.haxx.se/mail/lib-2016-10/0076.html -- Andrei


I think that it much better to force 
https://github.com/ikod/dlang-requests developing its much easier 
than curl and its native




Re: Render SVG To Display And Update Periodically

2016-10-21 Thread Adam D. Ruppe via Digitalmars-d-learn

On Saturday, 22 October 2016 at 01:31:25 UTC, Mike Parker wrote:
* They can be passed directly to the compiler along with your 
own source. This will cause them to be compiled and ultimately 
linked into the resulting binary.



That's what I recommend. Just

dmd yourfile.d yourotherfiles.d color.d simpledisplay.d 
whatever_other_of_my_or_ketmars_files_you_use.d



That just works consistently.


Re: Render SVG To Display And Update Periodically

2016-10-21 Thread Mike Parker via Digitalmars-d-learn

On Friday, 21 October 2016 at 23:16:55 UTC, Jason C. Wells wrote:
I've tinkered with what you proposed. In the process I've 
worked through a variety of errors and ended up doing things I 
don't think are a good solution like duplication directories so 
that a library can be found.


Let me see if I understand how to piece together a build. Some 
combination of three things need to be in agreement:


1 - the import statements need to point to a matching directory 
structure
2 - the directory structure needs to be arranged such that the 
imports can be found
3 - the compiler can be told directly on the command line where 
imports are


I'm reading 
https://wiki.dlang.org/Compiling_and_linking_with_DMD_on_Windows which seems to be the document I need to sort through this.


I'll close out with this last question and then go study up. Am 
I barking up the right tree?


Yes. The compiler needs to know where to find the imports you use 
in the form of D source files or import modules (.di). 
Additionally, the linker needs to know which object files or 
libraries it needs to combine with your compiled source to create 
the executable, be they generated from D code or C or C++, and 
where to find them.


By default, the compiler knows where to find the Phobos and 
DRuntime modules and also that it needs to pass phobos.lib (which 
also includes the DRuntime objects) to the linker, so you never 
have to specify those. Any other modules you import besides your 
own need to be handled in one of the following ways:


* They can be passed directly to the compiler along with your own 
source. This will cause them to be compiled and ultimately linked 
into the resulting binary.


* The compiler can be told where to find the source to those 
modules with the -I command line switch. This *does not* cause 
them to be compiled. The compiler will only parse them when one 
is imported so that it can determine which symbols are available 
in the module it is currently compiling. You will still need to 
ensure those third-party modules are compiled separately and 
given to the linker.


Here's are a couple examples of the second approach, using the 
following directory structure:


- libraries
-- import
--- arsd
 color.d
 terminal.d
-- lib
- myprojects
-- foo
--- foo.d

Since Adam doesn't package the arsd stuff as a lib, you'll need 
to compile them yourself.


cd libraries
dmd -lib arsd/color.d arsd/terminal.d -odlib -ofarsd.lib

The -lib switch tells the compiler to create a library after it 
has compiled the files. The -od switch tells it to write the 
library in the lib directory and -od says the file name should be 
arsd.lib. This will result in the file libraries/lib/arsd.lib.


Alternatively, you could do this:

dmd arsd/color.d arsd/terminal.d -odlib

This will create lib/color.obj and lib/terminal.obj. It's easier 
to just create the library, which is an archive of both object 
files.


If you intend to use the Visual Studio linker, you will need to 
ensure you compile the library with the same flags you will use 
to compile the program (-m64 or -m32mscoff).


Now, assuming foo.d is the same code from my last post, cd into 
the myprojects/foo directory and do the following:


dmd -I../../import foo.d ../../lib/arsd.lib gdi32.lib user32.lib

The -I switch tells the compiler where it can find imports. It 
should always be the parent directory of the *package* you want 
to import. In this case, the package is arsd. A common mistake is 
to give import/arsd to the compiler.


In this case, I've passed the full path to the library because 
that's the easiest thing to do on Windows. It's possible to tell 
the linker which path to look in by using DMD's -L switch (which 
passes options directly to the linker), but OPTLINK and the MS 
linker use different switches for that. It's simpler just to pass 
the full path.


On Linux/Mac/*BSD, the extensions would be different: .obj -> .o, 
.lib -> .a. arsd.lib should be named libarsd.a. And the command 
line would look different as well:


dmd -I../../import foo.d -L-L../../lib -L-larsd

The -L switch is what you use to pass options to the linker. The 
first one, -L-L, gives the linker -L option, which on those 
systems tells the it append ../../lib to the library search path. 
The second one, -L-l (that's a lower-case 'L'), tells the linker 
to link with the library libarsd.a. You also need to link with 
any system dependencies the arsd modules have on those systems.










libcurl

2016-10-21 Thread Andrei Alexandrescu via Digitalmars-d
Guess we need to get ready! 
https://curl.haxx.se/mail/lib-2016-10/0076.html -- Andrei


Re: Binding temporaries to ref [WAS: I close BIP27. I won't be pursuing BIPs anymore]

2016-10-21 Thread Andrei Alexandrescu via Digitalmars-d

On 10/21/16 5:39 PM, Timon Gehr wrote:

On 21.10.2016 09:56, Ethan Watson wrote:

On Thursday, 20 October 2016 at 19:49:42 UTC, Andrei Alexandrescu wrote:

I think a solid DIP addressing the problem would have a good chance to
get traction.


I think all the information in this thread and the "Binding rvalues to
const ref in D" thread that Atilla started is enough for me to write up
a solid DIP.

I'll start doing that. Hopefully I'll get a draft up that I'll pass to
Manu for comment/input this weekend before posting it properly.


Nice! Make sure it is orthogonal to const. :)


It would be great if you participated. Such a DIP needs you. -- Andrei



Re: rt_init, rt_term and _initCount

2016-10-21 Thread Benjamin Thaut via Digitalmars-d

On Friday, 21 October 2016 at 19:40:52 UTC, Rainer Schuetze wrote:


The wrapper around main in the executable should work just as 
any DLLs' DllMain, i.e. it should register/unregister its own 
data segments with the GC and run its shared and TLS module 
constructors/decoontructors. Everything else should be handled 
by the druntime DLL.


Yes, I also considered that option. The problem with that is, 
that druntime deinit joins alls threads before running the shared 
module dtors. If the main executable behaves exactly like the 
dlls do this joining of threads would be lost and different from 
the behavior of a fully statical linked executable.


Re: Render SVG To Display And Update Periodically

2016-10-21 Thread Jason C. Wells via Digitalmars-d-learn
I've tinkered with what you proposed. In the process I've worked 
through a variety of errors and ended up doing things I don't 
think are a good solution like duplication directories so that a 
library can be found.


Let me see if I understand how to piece together a build. Some 
combination of three things need to be in agreement:


1 - the import statements need to point to a matching directory 
structure
2 - the directory structure needs to be arranged such that the 
imports can be found
3 - the compiler can be told directly on the command line where 
imports are


I'm reading 
https://wiki.dlang.org/Compiling_and_linking_with_DMD_on_Windows 
which seems to be the document I need to sort through this.


I'll close out with this last question and then go study up. Am I 
barking up the right tree?


Re: Why are homepage examples too complicated?

2016-10-21 Thread Benjiro via Digitalmars-d

On Thursday, 20 October 2016 at 09:10:10 UTC, Chris wrote:
I.e. "He agrees with me, therefore I like him!" One year of 
meetings to design a website does not necessarily mean the 
site's good or that it has to take at least a year until you 
have a presentable website.


Sorry, was too busy with some darn project to respond. Been 
rewriting from zero some custom webshop system that guys in 
Poland wrote ( horrible bugs, bloated and just nasty ). Ended up 
writing a metadata/json structure linked to a entry commit 
system. Yay ... 15 tables to 3, mysql queries down to 1/10 etc... 
Already 5 times as fast and its not even optimized. *sigh*


So tired seeing entry level PHP code. Guess why i am interested 
in learning D. I need a break and move to something better *lol*.


Designing a website for a company means that the marketing 
knobs feel they have to throw in their 2 cents and want them 
acted upon or they block the whole process - then at the end, 
all of a sudden the boss - who never cared for the website - 
wants to have a look too and here we go again...


We're talking about font-sizes, gradient colors, button 2px to 
the left, company logo bigger/smaller etc, not about the page 
logic. Of course, because they know nothing about programming 
they go by what they see and try to make a contribution there, 
just for the sake of it.


No kidding ... bosses need to keep there hands out of projects. 
They are in general more trouble then they are worth. *lol*


We just lost 2 months on a project, because the bosses had the 
brilliant idea to outsource and started pitching / pushing it. 
And the whole discussion dragged on preventing us from starting 
on a major project ( why start on something that may be done by 
somebody else? ).


O, that webshop that now needs a rewrite from zero, was a direct 
result of another outsource. Yay! And the client ends up paying ( 
again ) for that.



Some projects simply take time. That whole travel site was indeed 
slow but the end result is definitely not bad. But, like you 
said, sometimes too many cooks in the kitchen slows things down. 
My and my college have rewritten several disaster projects, 
mostly in 3 to 4 months time per project. The reason we are fast 
is because we are in sync and the bosses stayed mostly out of the 
rewrite projects. We do it our way ( finally ) and the end 
results speak for themselves.


Unfortunately, bosses are bosses. Two senior PHP developers cost 
money ( hell, we are cheap, under payed ). They can never stop 
looking for money, while they trow money out of the door in one 
after another foolish scheme. Technically we are keeping the 
company afloat. *sigh*


Unfortunately, it is often forgotten that each website needs a 
different, unique approach. Getting inspiration from other 
websites is good, trying to copy them is not a good idea, 
because it will never serve your purpose optimally.


Yep ...

The real craftsmanship behind a website is mastering the 
various technologies that don't work smoothly together (HTML, 
JS, PHP, forms, requests, server side stuff, browsers, data 
bases). Web design is 90% page logic, 10% inspiration.


On this i kind of disagree. I can handle all the web techs with 
ease but you need people who can see things more in graphical / 
marketing / ease of use sense. We developers see a lot of times 
too much from our perspective.


Its the same reason why i mentioned the whole examples on the 
front page. While i had more then one reason to skip D, the 
mentioned example was one of them. When people have choices, they 
make them very fast.


Ali for instance, did a great job on his book. Its easy to get 
into, maybe a bit redundant from a more experience developers 
point of view but you quickly see the small details. Things you 
will simply look over without realizing.


Stupid and simple example that will make every developer here 
think: "this Benjiro guy is stupid". *haha*


Most example's simply show something like:

writefln("The minimum of %s is %d", test, min);

But what if you simply want to join two lines together. In PHP 
you do:


print('Hello' . 'World');

Try that in D. Does not work with dot. You need to use comma's. 
Comma's in PHP is a instant parse error. While the dots are a 
compile error in D.


writeln('Hello', 'World').

Yea ... sounds stupid but its those details that get lost in the 
flood of data. Don't overthink the whole "why do you want to 
merge Hello World", its just a silly example.


How about ~ for merging? That is also very fast overlooked. I 
know it sounds ridiculous but frankly, i do not have a lot of 
time so i try to learn on the fly. But its annoying getting 
hampered by those small details when your trying some code, until 
you finally figure it out.


Yes, its great that D has pipelines, template, alias, fibers etc 
but those are already more advanced concepts. Something so simple 
as the whole comma or merge syntax, does not even get mentioned 
in the Learn 

Re: D Uniform initialization {}

2016-10-21 Thread Daniel Kozak via Digitalmars-d

Dne 21.10.2016 v 23:21 Patric Dexheimer via Digitalmars-d napsal(a):


On Friday, 21 October 2016 at 19:20:25 UTC, Daniel Kozak wrote:

Dne 21.10.2016 v 20:49 Patric Dexheimer via Digitalmars-d napsal(a):

Quite sure that this was already discussed, but.. any chance of this 
on D?

No (I hope so)


There are a lot of places where it should make the code clear.

Can you elaborate on this?
I always have to create shorter aliases for the most used structs. 
(which i think is awkward sometimes)

Why? (I do not see any relation to Uniform initialization)


egs:
//D
alias vec3 = Tuple!(float, "x", float, "y", float, "z");
vec3[] vectors = [
   vec3(1.0,0.0,1.0),
   vec3(2.0,1.0,1.0),
   vec3(3.0,2.0,1.0)
];
//C++ equivalent
vec3 vectors[] = {
   {1.0,0.0,1.0},
   {2.0,1.0,1.0},
   {3.0,2.0,1.0}
};


this works for D too:

import std.stdio;

struct S
{
int a;
int b;
}
void main()
{
S[] s = [{ 1, 2 }];
writeln(s[0]);
}



//D
auto return_value = get_struct(); //don´t need to write the return type
set_struct( StructName(value1, value2) );
//C++
set_struct( {value1, value2} ); //don´t need to write the argument type
OK this does not work but I do not think it is releated to Uniform 
initialization, but it is more something like cast to parametr type or 
something like that


Can you explain why you think is a bad idea?
Because there is no need. In c++ it is disaster because there is milion 
way how to initialize something, it is really hard to understand and 
inconsistent


Re: Binding temporaries to ref [WAS: I close BIP27. I won't be pursuing BIPs anymore]

2016-10-21 Thread Timon Gehr via Digitalmars-d

On 21.10.2016 09:56, Ethan Watson wrote:

On Thursday, 20 October 2016 at 19:49:42 UTC, Andrei Alexandrescu wrote:

I think a solid DIP addressing the problem would have a good chance to
get traction.


I think all the information in this thread and the "Binding rvalues to
const ref in D" thread that Atilla started is enough for me to write up
a solid DIP.

I'll start doing that. Hopefully I'll get a draft up that I'll pass to
Manu for comment/input this weekend before posting it properly.


Nice! Make sure it is orthogonal to const. :)


Re: D Uniform initialization {}

2016-10-21 Thread Patric Dexheimer via Digitalmars-d

On Friday, 21 October 2016 at 19:20:25 UTC, Daniel Kozak wrote:
Dne 21.10.2016 v 20:49 Patric Dexheimer via Digitalmars-d 
napsal(a):


Quite sure that this was already discussed, but.. any chance 
of this on D?

No (I hope so)


There are a lot of places where it should make the code clear.

Can you elaborate on this?
I always have to create shorter aliases for the most used 
structs. (which i think is awkward sometimes)

Why? (I do not see any relation to Uniform initialization)


egs:
//D
alias vec3 = Tuple!(float, "x", float, "y", float, "z");
vec3[] vectors = [
   vec3(1.0,0.0,1.0),
   vec3(2.0,1.0,1.0),
   vec3(3.0,2.0,1.0)
];
//C++ equivalent
vec3 vectors[] = {
   {1.0,0.0,1.0},
   {2.0,1.0,1.0},
   {3.0,2.0,1.0}
};

//D
auto return_value = get_struct(); //don´t need to write the 
return type

set_struct( StructName(value1, value2) );
//C++
set_struct( {value1, value2} ); //don´t need to write the 
argument type


//D in case of large struct names
alias v = VeryLargeStructName; //not cool
v[] vectors = [
   v(1.0,0.0,1.0),
   v(2.0,1.0,1.0),
   v(3.0,2.0,1.0)
];


I find myself falling with frequency on examples that will 
benefit from the c++ uniform initialization.


"No (I hope so)"

Can you explain why you think is a bad idea?


Please say hello to our third team member: Razvan Nitu

2016-10-21 Thread CRAIG DILLABAUGH via Digitalmars-d-announce

Welcome Razvan.




[Issue 16532] Add "namespace" Keyword?

2016-10-21 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16532

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

   What|Removed |Added

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

--- Comment #3 from b2.t...@gmx.com ---
(In reply to Jack from comment #2)
> Exactly, name spaces are supported but only through an extern. If I want to
> write D code with namespaces it isn't possible. Hence a lack of completeness.
> 
> You can't use a template without a parameter?
> 
> template Name()
> {
> enum a = 2;
> enum b = 3;
> }
> 
> writeln(Name.a, Name.b); // error Name has no property a or b

You must alias it to create an instance.

alias name = Name!();

and in the code use this alias.

But you know, namespaces will never be added. D has modules, end of story. Ask
on the news group and you'll see...You can even close this issue.

--


For those who cannot reach github today due to DNS DDOS attack

2016-10-21 Thread Walter Bright via Digitalmars-d-announce


Put these in your /etc/hosts file:

192.30.253.113  github.com
151.101.44.133  assets-cdn.github.com
54.236.140.90   collector.githubapp.com
192.30.253.116  api.github.com
192.30.253.122  ssh.github.com
151.101.44.133  avatars0.githubusercontent.com
151.101.44.133  avatars1.githubusercontent.com
151.101.44.133  avatars2.githubusercontent.com
151.101.44.133  avatars3.githubusercontent.com

Windows users:

Edit the file

C:\Windows\System32\drivers\etc\hosts

You will need to be an administrator to change it - find notepad in start menu
under accessories, right mouse click on it and "run as administrator",
then load the file using file open.

Copied from:

https://www.reddit.com/r/programming/comments/58o5p6/github_is_down/

This got gitub working again for me.


Re: gdc in Linux distros recommended?

2016-10-21 Thread ketmar via Digitalmars-d

On Friday, 21 October 2016 at 19:53:14 UTC, Johannes Pfau wrote:
GDC git is completely 2.068.2. There are no updated binary 
releases as there's still one remaining blocker regression 
(32bit only).


sorry for spreading false info then.


Re: gdc in Linux distros recommended?

2016-10-21 Thread Johannes Pfau via Digitalmars-d
Am Thu, 20 Oct 2016 12:21:34 +
schrieb ketmar :

> On Thursday, 20 October 2016 at 05:43:47 UTC, Nick Sabalausky 
> wrote:
> >> And GDC is using the 2.068 feature set, plus a lot of bug 
> >> fixes from
> >> later versions.  I guess you could call it 2.068.5.  :-)
> >>  
> >
> > Maybe there's a certain amount of truth to that, but not 
> > completely: In all my projects anyway, the latest available GDC 
> > on travis always broke at exactly the same time DMD 2.066 and 
> > below broke.  
> 
> i believe that Iain talked about frontend features. phobos is 
> still at 2.066, i think.

GDC git is completely 2.068.2. There are no updated binary releases as
there's still one remaining blocker regression (32bit only).


Re: rt_init, rt_term and _initCount

2016-10-21 Thread Rainer Schuetze via Digitalmars-d



On 20.10.2016 09:17, Benjamin Thaut wrote:

This is a topic really specific to druntime, I don't know a better place
to put it though.

rt_init increases the _initCount and rt_term decreases it and only
terminates the runtime in case the _initCount reaches zero (see dmain2.d)


[...]


The problem is step 5) in the above list. When the main executable
leaves dmain the runtime should be deinitialized no matter if any dll is
still loaded or not. If this would be the case the module Dtors would be
calle din the correct order. I can't remove the rt_init calls from the
dll loading code however because that would mean when loading a d-dll
into a C process druntime would never be initialized. So I'm thinking of
adding a force parameter to rt_term which will always deinitialize
druntime disregarding the _initCount. This feels like a hack though.

Any suggestions how to solve this problem? Who are other platforms doing
it?


I don't think the current rt_init/rt_exit function are suitable for DLLs 
or executables that are using a shared druntime library.


The wrapper around main in the executable should work just as any DLLs' 
DllMain, i.e. it should register/unregister its own data segments with 
the GC and run its shared and TLS module constructors/decoontructors. 
Everything else should be handled by the druntime DLL.


Phobos lacks a particular family of range functions...

2016-10-21 Thread Basile B. via Digitalmars-d-learn

They would have for constraint

  `if (isInputRange!Range && isInputRange!(ElementType!Range))`

In case you wouldn't see directly what would they be used for, 
it's for tree-like structures. Each element in a Range is also an 
input range.


I see 3 obvious functions/templates

- the most important, make an input range from a tree-like range, 
e.g `auto treeRange(Range, DepthMode mode)(Range range) `


- a second version for bidir ranges, e.g `reverseTreeRange`

- a functional iteration algorithm: auto `deepIterate(alias Fun, 
DepthMode mode, Range, A...)(Range range, auto ref A a)`, which 
applies Fun to each element with the ability for Fun to act as a 
predicates to stop the iteration. Actually I have this one in my 
user library (this is also the reason why I post this today).


Unless I'm blind I cannot see anything that handles trees with a 
range interface in phobos.


Re: DLang/Wiki/'Hello World'/Run Code/Disassembly

2016-10-21 Thread cym13 via Digitalmars-d-learn

On Friday, 21 October 2016 at 19:27:59 UTC, cym13 wrote:

On Friday, 21 October 2016 at 19:03:30 UTC, DLearner wrote:

[...]


That's a problem about the debugger/disassembler that you use, 
not about D.


We can't do anything else to help as you give no information. 
See my post:

- I gave the exact source code
- I gave the compiler that I used with all its flags
- I explained what tool I used to analyse it, what I was 
analysing exactly and how
- At each step I gave the exact output of the tools with 
potential errors


This means this is reproducible. Anybody can try it at home and 
check for himself that it works.


There is *no way* to fix a bug that we can't reproduce, and 
there is *no way* to reproduce it unless we have all the 
informations stated above.


Apologies, I didn't understand that you put all that in the title.


[Issue 16633] Case where an alias this is tried before the object itself

2016-10-21 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16633

Steven Schveighoffer  changed:

   What|Removed |Added

Summary|Case where an alias this is |Case where an alias this is
   |tried before the right  |tried before the object
   |member  |itself

--- Comment #1 from Steven Schveighoffer  ---
I think the summary was incorrect, please revert if I was wrong.

--


Re: DLang/Wiki/'Hello World'/Run Code/Disassembly

2016-10-21 Thread cym13 via Digitalmars-d-learn

On Friday, 21 October 2016 at 19:03:30 UTC, DLearner wrote:

On Friday, 21 October 2016 at 09:07:35 UTC, cym13 wrote:

On Friday, 21 October 2016 at 08:58:50 UTC, DLearner wrote:

[...]


What makes you think that? It's hard to tell if you don't give 
any information.



I pressed the 'Run' button and got the 'Hello World'.
I pressed the 'Disassembly' button and got...nothing.


That's a problem about the debugger/disassembler that you use, 
not about D.


We can't do anything else to help as you give no information. See 
my post:

- I gave the exact source code
- I gave the compiler that I used with all its flags
- I explained what tool I used to analyse it, what I was 
analysing exactly and how
- At each step I gave the exact output of the tools with 
potential errors


This means this is reproducible. Anybody can try it at home and 
check for himself that it works.


There is *no way* to fix a bug that we can't reproduce, and there 
is *no way* to reproduce it unless we have all the informations 
stated above.


Re: DLang/Wiki/'Hello World'/Run Code/Disassembly

2016-10-21 Thread Daniel Kozak via Digitalmars-d-learn

Dne 21.10.2016 v 21:03 DLearner via Digitalmars-d-learn napsal(a):


On Friday, 21 October 2016 at 09:07:35 UTC, cym13 wrote:

On Friday, 21 October 2016 at 08:58:50 UTC, DLearner wrote:

[...]


What makes you think that? It's hard to tell if you don't give any 
information.



I pressed the 'Run' button and got the 'Hello World'.
I pressed the 'Disassembly' button and got...nothing.


Okey so some page does not work correctly, and you think this? Wow :D
you should try one of these this pages
http://asm.dlang.org
http://d.godbolt.org


Re: D Uniform initialization {}

2016-10-21 Thread Daniel Kozak via Digitalmars-d

Dne 21.10.2016 v 20:49 Patric Dexheimer via Digitalmars-d napsal(a):

Quite sure that this was already discussed, but.. any chance of this 
on D?

No (I hope so)


There are a lot of places where it should make the code clear.

Can you elaborate on this?
I always have to create shorter aliases for the most used structs. 
(which i think is awkward sometimes)

Why? (I do not see any relation to Uniform initialization)



Re: Pattern matching in D?

2016-10-21 Thread Nick Sabalausky via Digitalmars-d

On 10/20/2016 10:16 PM, Chris M. wrote:

So I know you can do some pattern matching with templates in D, but has
there been any discussion about implementing it as a language feature,
maybe something similar to Rust's match keyword
(https://doc.rust-lang.org/stable/book/patterns.html)? What would your
guys' thoughts be?



What I've been really wanting for a long time is the one-two combo of 
Nemerle's variants and pattern matching:


https://github.com/rsdn/nemerle/wiki/Grok-Variants-and-matching



Re: DLang/Wiki/'Hello World'/Run Code/Disassembly

2016-10-21 Thread DLearner via Digitalmars-d-learn

On Friday, 21 October 2016 at 09:07:35 UTC, cym13 wrote:

On Friday, 21 October 2016 at 08:58:50 UTC, DLearner wrote:

[...]


What makes you think that? It's hard to tell if you don't give 
any information.



I pressed the 'Run' button and got the 'Hello World'.
I pressed the 'Disassembly' button and got...nothing.



D Uniform initialization {}

2016-10-21 Thread Patric Dexheimer via Digitalmars-d
Quite sure that this was already discussed, but.. any chance of 
this on D?

(one of the few things that i miss from c++)

There are a lot of places where it should make the code clear.
I always have to create shorter aliases for the most used 
structs. (which i think is awkward sometimes)


I know there is the case of being ambiguous with lambdas, but 
after reading this thread 
https://forum.dlang.org/thread/nud21i$o29$1...@digitalmars.com

uniform initialization comes to my mind again :)









Re: AA ignores disabling of postblit for key types

2016-10-21 Thread Jonathan M Davis via Digitalmars-d
On Friday, October 21, 2016 12:18:28 Nordlöw via Digitalmars-d wrote:
> It seems AA's doesn't respect disabling of postblit for its
> Key-type even when it's sent as an r-value.
>
> This is a serious bug.

Well, I wouldn't expect it to work to use a non-copyable type as a key, but
that should just result in a compilation error, not the mess that you're
seeing. It wouldn't surprise me at all if the problem relates to the fact
that the AA implementation uses void* internally (at least, from what I
recall, that's what it does, which historically has meant a number of fun
type-related bugs).

- Jonathan M Davis




[Issue 16633] Case where an alias this is tried before the right member

2016-10-21 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16633

ag0ae...@gmail.com changed:

   What|Removed |Added

   Keywords||wrong-code
 CC||ag0ae...@gmail.com

--


[Issue 16633] New: Case where an alias this is tried before the right member

2016-10-21 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16633

  Issue ID: 16633
   Summary: Case where an alias this is tried before the right
member
   Product: D
   Version: D2
  Hardware: All
OS: All
Status: NEW
  Severity: normal
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: b2.t...@gmx.com

class Item
{
alias children this;
Item[] children;
void populate()
{
children ~= new Item; // Item is seen as []
assert(children.length == 1);
}
}

void main()
{
Item root = new Item;
root.populate;
}

https://forum.dlang.org/thread/wcxdarfpfassnjaak...@forum.dlang.org

--


Re: Is this a bug ?

2016-10-21 Thread ag0aep6g via Digitalmars-d-learn

On 10/21/2016 06:55 PM, Basile B. wrote:

This very simple stuff:

class Item
{
alias children this;
Item[] children;
void populate()
{
children ~= new Item;
assert(children.length == 1);
}
}

void main()
{
Item root = new Item;
root.populate;
}

leads to an assertion failure. Am I too tired to see the error or do you
think it's a bug ?


Bug. `alias this` is tried too eagerly.

What happens: The alias this of `new Item` is evaluated, leading to 
`children ~= [];`.


Re: dmd 2.072.0 beta 2 no size because of forward reference

2016-10-21 Thread Kagamin via Digitalmars-d-learn

https://github.com/dlang/dmd/pull/5500 maybe this


Is this a bug ?

2016-10-21 Thread Basile B. via Digitalmars-d-learn

This very simple stuff:

class Item
{
alias children this;
Item[] children;
void populate()
{
children ~= new Item;
assert(children.length == 1);
}
}

void main()
{
Item root = new Item;
root.populate;
}

leads to an assertion failure. Am I too tired to see the error or 
do you think it's a bug ?


Re: "for" statement issue

2016-10-21 Thread Vladimir Panteleev via Digitalmars-d
On Friday, 21 October 2016 at 16:46:08 UTC, Andrei Alexandrescu 
wrote:
Read the example again, the lambda is not evaluated as a bool. 
-- Andrei


My bad.

In that case, what Steven said.


Re: "for" statement issue

2016-10-21 Thread Andrei Alexandrescu via Digitalmars-d

On 10/21/2016 12:39 PM, Vladimir Panteleev wrote:

On Friday, 21 October 2016 at 12:34:58 UTC, Andrei Alexandrescu wrote:

What would be a good solution to forbid certain constructs in the
increment part of a for statement?


For this specific case, a clear solution would be to forbid evaluating
lambdas as a boolean expression, because they will always be true, and
thus almost always an error.


Read the example again, the lambda is not evaluated as a bool. -- Andrei




[Issue 11119] Alias declaration cannot see forward-referenced symbol in mixed-in template

2016-10-21 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=9

anonymous4  changed:

   What|Removed |Added

   See Also||https://issues.dlang.org/sh
   ||ow_bug.cgi?id=1170

--


[Issue 1170] Cannot forward reference a type defined in a MixinStatement

2016-10-21 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=1170

anonymous4  changed:

   What|Removed |Added

   See Also||https://issues.dlang.org/sh
   ||ow_bug.cgi?id=9

--


Re: "for" statement issue

2016-10-21 Thread Vladimir Panteleev via Digitalmars-d
On Friday, 21 October 2016 at 12:34:58 UTC, Andrei Alexandrescu 
wrote:
What would be a good solution to forbid certain constructs in 
the increment part of a for statement?


For this specific case, a clear solution would be to forbid 
evaluating lambdas as a boolean expression, because they will 
always be true, and thus almost always an error. Same as with 
assignments in if statements. If intended, it can be worked 
around with "!is null".




Re: "for" statement issue

2016-10-21 Thread mogu via Digitalmars-d

Allow new syntax makes codes simpler in some cases:

writeln({
int a = 5;
return a + 5;
}());

=>

writeln{
int a = 5;
return a + 5;
}();

[1,2,3].fold!((a, b) => a + b).writeln;

=>

[1,2,3].fold!{a, b => a + b}.writeln;


[Issue 16632] "for" statement treats scoped block in increment section as lambda

2016-10-21 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16632

Steven Schveighoffer  changed:

   What|Removed |Added

   Hardware|x86_64  |All
Summary|"for" statement issue   |"for" statement treats
   ||scoped block in increment
   ||section as lambda
 OS|Windows |All
   Severity|enhancement |minor

--


[Issue 16632] "for" statement issue

2016-10-21 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16632

Steven Schveighoffer  changed:

   What|Removed |Added

Summary|"for" statemenet issue  |"for" statement issue

--


Re: "for" statement issue

2016-10-21 Thread Steven Schveighoffer via Digitalmars-d

On 10/21/16 10:38 AM, mogu wrote:

On Friday, 21 October 2016 at 14:22:27 UTC, Steven Schveighoffer wrote:

On 10/21/16 10:12 AM, Temtaime wrote:

On Friday, 21 October 2016 at 13:42:49 UTC, Adam D. Ruppe wrote:

On Friday, 21 October 2016 at 13:33:26 UTC, Stefan Koch wrote:

[...]


Eh, that's exactly what the language rules say should happen, and it
actually does make sense to me... you might even want to use an
immediately-called lambda to group several statements together into
one expression.

[...]


Please, no.
It's fully clear that { stmts } createa a lambda, just () is ommited.


No, it's not.

{ int x; x = 2; }

Is not a lambda. It's a scope.

So the meaning changes based on where it's used. I totally agree that
we should remove that feature.



{} in swift is a lambda too.


Swift doesn't have arbitrary scopes. So there is no ambiguity.


I think swift has better lambda syntax.
Maybe could help for a better syntax in d.


We likely are not going to change the lambda syntax. However, it's 
possible we could remove the ambiguous cases.



reversedNames = names.sorted(by: { (s1: String, s2: String) -> Bool in
return s1 > s2
})
reversedNames = names.sorted(by: { (s1: String, s2: String) -> Bool in
return s1 > s2 } )
reversedNames = names.sorted(by: { s1, s2 in return s1 > s2 } )
reversedNames = names.sorted(by: { s1, s2 in s1 > s2 } )


(s1, s2) => s1 > s2

Seems pretty good to me


reversedNames = names.sorted(by: { $0 > $1 } )


With the original string lambdas, this was possible as "a > b". I'm not 
sure this case is worth much effort to add.



reversedNames = names.sorted(by: >)


Not sure if we'll ever get this in D :)



someFunctionThatTakesAClosure(closure: {
// closure's body goes here
})
someFunctionThatTakesAClosure() {
// trailing closure's body goes here
}


Yes, I've seen and used this. I think this is actually a little confusing.

-Steve


dmd 2.072.0 beta 2 no size because of forward reference

2016-10-21 Thread Eugene Wissner via Digitalmars-d-learn

Hey,

the code bellow compiles with dmd 2.071.2, but doesn't compile 
with the same command with dmd 2.072.0 beta2. Maybe someone knows 
what's going wrong or whether it is a bug in 2.071.2/2.072.0 (it 
is a reduced part from memutils):


app.d:
import memutils.utils;

struct HashMap(Key, Value)
{
int[] m_table; // NOTE: capacity is always POT

~this()
{
freeArray!(int)(m_table);
}
}

--
module memutils.allocators;

final class FreeListAlloc()
{
import memutils.utils : MallocAllocator;
}

--
module memutils.utils;

import memutils.allocators;

final class MallocAllocator
{
}

final class AutoFreeListAllocator()
{
FreeListAlloc!()[12] m_freeLists;
}

alias LocklessAllocator = AutoFreeListAllocator!();

R getAllocator(R)() {
return new R;
}

void freeArray(T)(auto ref T[] array)
{
	auto allocator = getAllocator!(LocklessAllocator); // freeing. 
Avoid allocating in a dtor

}



The command to compile:
dmd -c -Imemutils/ app.d -of/dev/null


Builds with the latest stable. Fails with the beta:

memutils/utils.d(9): Error: class 
memutils.utils.AutoFreeListAllocator!().AutoFreeListAllocator no 
size because of forward reference
memutils/utils.d(14): Error: template instance 
memutils.utils.AutoFreeListAllocator!() error instantiating
memutils/utils.d(11): Error: template instance 
memutils.allocators.FreeListAlloc!() error instantiating
memutils/utils.d(14):instantiated from here: 
AutoFreeListAllocator!()
app.d(9): Error: template instance memutils.utils.freeArray!int 
error instantiating

app.d(13):instantiated from here: HashMap!(int, uint)



Compiles with the lates beta if:
dmd -c -Imemutils/ memutils/* app.d -of/dev/null


[Issue 16532] Add "namespace" Keyword?

2016-10-21 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16532

--- Comment #2 from Jack  ---
Exactly, name spaces are supported but only through an extern. If I want to
write D code with namespaces it isn't possible. Hence a lack of completeness.

You can't use a template without a parameter?

template Name()
{
enum a = 2;
enum b = 3;
}

writeln(Name.a, Name.b); // error Name has no property a or b

--


[Issue 16632] New: "for" statemenet issue

2016-10-21 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16632

  Issue ID: 16632
   Summary: "for" statemenet issue
   Product: D
   Version: D2
  Hardware: x86_64
OS: Windows
Status: NEW
  Severity: enhancement
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: razvan.nitu1...@gmail.com

How should the compiler treat this code?

int j;
for({j=2; int d = 3; } j+d<7; {j++; d++;}) {
}

A discussion regarding this code can be found at: 

http://forum.dlang.org/post/nud21i$o29$1...@digitalmars.com

--


Re: "for" statement issue

2016-10-21 Thread Steven Schveighoffer via Digitalmars-d

On 10/21/16 10:28 AM, Kagamin wrote:

On Friday, 21 October 2016 at 14:16:26 UTC, Steven Schveighoffer wrote:

How about in general forbidding lambda statements that aren't called
or used anywhere?


How?

int main()
{
int a;
auto b = ()=>{a++;};
b();
assert(a==1);
return 0;
}


Oh, I see. This error that I didn't see right away wouldn't be 
prevented, but that's not what I was talking about. I just meant that 
the original problem shouldn't have happened, since the lambda is never 
used.


I totally agree that the above sucks and should be fixed.

-Steve




Re: "for" statement issue

2016-10-21 Thread Andrei Alexandrescu via Digitalmars-d

On 10/21/2016 09:42 AM, Adam D. Ruppe wrote:

I think deprecating `{ lambda }` is really the way to go.


Another possibility is to disallow an ExpressionStatement that consists 
solely of a lambda. There is precedent for that, e.g. the statement "1 + 
1;" is disallowed. -- Andrei




Re: I can't use nodejs anymore. Please vibe.d, don't follow that path

2016-10-21 Thread Kagamin via Digitalmars-d

On Thursday, 20 October 2016 at 20:25:40 UTC, Karabuta wrote:
Dependencies upon dependencies. Each package comes along with 
its own dependencies. I give up nodejs, you win. Now I am 
investing my time in Vibe.d which I hope ...


Maybe it will be enough to declare some "batteries 2.0" package 
and depend on it?


Re: "for" statement issue

2016-10-21 Thread Steven Schveighoffer via Digitalmars-d

On 10/21/16 10:28 AM, Kagamin wrote:

On Friday, 21 October 2016 at 14:16:26 UTC, Steven Schveighoffer wrote:

How about in general forbidding lambda statements that aren't called
or used anywhere?


How?

int main()
{
int a;
auto b = ()=>{a++;};
b();
assert(a==1);
return 0;
}


This lambda is both used in an assignment, and called.

If I do this:

10;

It's flagged as not having any effect. Similarly if I do:

() => 5;

Then it's not used/called. What is the point?

-Steve


Re: "for" statement issue

2016-10-21 Thread mogu via Digitalmars-d
On Friday, 21 October 2016 at 14:22:27 UTC, Steven Schveighoffer 
wrote:

On 10/21/16 10:12 AM, Temtaime wrote:
On Friday, 21 October 2016 at 13:42:49 UTC, Adam D. Ruppe 
wrote:

On Friday, 21 October 2016 at 13:33:26 UTC, Stefan Koch wrote:

[...]


Eh, that's exactly what the language rules say should happen, 
and it
actually does make sense to me... you might even want to use 
an
immediately-called lambda to group several statements 
together into

one expression.

[...]


Please, no.
It's fully clear that { stmts } createa a lambda, just () is 
ommited.


No, it's not.

{ int x; x = 2; }

Is not a lambda. It's a scope.

So the meaning changes based on where it's used. I totally 
agree that we should remove that feature.


-Steve


{} in swift is a lambda too. I think swift has better lambda 
syntax. Maybe could help for a better syntax in d.



reversedNames = names.sorted(by: { (s1: String, s2: String) -> 
Bool in

return s1 > s2
})
reversedNames = names.sorted(by: { (s1: String, s2: String) -> 
Bool in return s1 > s2 } )

reversedNames = names.sorted(by: { s1, s2 in return s1 > s2 } )
reversedNames = names.sorted(by: { s1, s2 in s1 > s2 } )
reversedNames = names.sorted(by: { $0 > $1 } )
reversedNames = names.sorted(by: >)

someFunctionThatTakesAClosure(closure: {
// closure's body goes here
})
someFunctionThatTakesAClosure() {
// trailing closure's body goes here
}
let strings = numbers.map {
(number) -> String in
var number = number
var output = ""
repeat {
output = digitNames[number % 10]! + output
number /= 10
} while number > 0
return output
}


Re: "for" statement issue

2016-10-21 Thread Kagamin via Digitalmars-d

http://ideone.com/KBf8k9


Re: "for" statement issue

2016-10-21 Thread Kagamin via Digitalmars-d
On Friday, 21 October 2016 at 14:16:26 UTC, Steven Schveighoffer 
wrote:
How about in general forbidding lambda statements that aren't 
called or used anywhere?


How?

int main()
{
int a;
auto b = ()=>{a++;};
b();
assert(a==1);
return 0;
}


Re: "for" statement issue

2016-10-21 Thread Steven Schveighoffer via Digitalmars-d

On 10/21/16 10:12 AM, Temtaime wrote:

On Friday, 21 October 2016 at 13:42:49 UTC, Adam D. Ruppe wrote:

On Friday, 21 October 2016 at 13:33:26 UTC, Stefan Koch wrote:

[...]


Eh, that's exactly what the language rules say should happen, and it
actually does make sense to me... you might even want to use an
immediately-called lambda to group several statements together into
one expression.

[...]


Please, no.
It's fully clear that { stmts } createa a lambda, just () is ommited.


No, it's not.

{ int x; x = 2; }

Is not a lambda. It's a scope.

So the meaning changes based on where it's used. I totally agree that we 
should remove that feature.


-Steve


Re: "for" statement issue

2016-10-21 Thread Steven Schveighoffer via Digitalmars-d

On 10/21/16 8:34 AM, Andrei Alexandrescu wrote:

I got a question about what happens with this code:

int j;
for({j=2; int d = 3; } j+d<7; {j++; d++;}) {
}

My first instinct was that that won't compile but it surprisingly does.
And it loops forever.

So the grammar according to
https://dlang.org/spec/grammar.html#ForStatement is:

ForStatement:
for ( Initialize Testopt ; Incrementopt ) ScopeStatement

Initialize:
;
NoScopeNonEmptyStatement

NoScopeNonEmptyStatement:
NonEmptyStatement
BlockStatement

NonEmptyStatement goes over a bunch of odd places such as case statement
and default statement. And then BlockStatement is the matched case:

BlockStatement:
{ }
{ StatementList }

So it seems we have another case in which "{" "}" do not introduce a
scope. Fine. The real problem is with the increment part, which is an
expression. The code { j++; d++; } is... a lambda expression that never
gets used, which completes a very confusing sample.

What would be a good solution to forbid certain constructs in the
increment part of a for statement?


How about in general forbidding lambda statements that aren't called or 
used anywhere?


-Steve


Re: "for" statement issue

2016-10-21 Thread Temtaime via Digitalmars-d

On Friday, 21 October 2016 at 13:42:49 UTC, Adam D. Ruppe wrote:

On Friday, 21 October 2016 at 13:33:26 UTC, Stefan Koch wrote:

[...]


Eh, that's exactly what the language rules say should happen, 
and it actually does make sense to me... you might even want to 
use an immediately-called lambda to group several statements 
together into one expression.


[...]


Please, no.
It's fully clear that { stmts } createa a lambda, just () is 
ommited.


foo({ code; }); is always OK and we shouldn't deprecate it.


Re: "for" statement issue

2016-10-21 Thread Stefan Koch via Digitalmars-d

On Friday, 21 October 2016 at 13:42:49 UTC, Adam D. Ruppe wrote:

On Friday, 21 October 2016 at 13:33:26 UTC, Stefan Koch wrote:

It does create a lambda?
Hmm that should not happen.


I think deprecating `{ lambda }` is really the way to go. It'd 
fix this as well at that other FAQ at pretty low cost.


Yes lets make it happen!
{ } has too many meanings.
Lets deprecate this one.




Re: Binding temporaries to ref [WAS: I close BIP27. I won't be pursuing BIPs anymore]

2016-10-21 Thread Andrei Alexandrescu via Digitalmars-d

On 10/21/2016 04:47 AM, Walter Bright wrote:

On 10/21/2016 12:56 AM, Ethan Watson wrote:

I'll start doing that. Hopefully I'll get a draft up that I'll pass to
Manu for
comment/input this weekend before posting it properly.


Great!


I, too, will look forward to that. If we get it right, we'll have a 
prototype of a good DIP to serve as an example for future submissions.


By the way, the deadline for looking at 
https://github.com/dlang/DIPs/blob/master/DIPs/DIP1001.md and 
https://github.com/dlang/DIPs/blob/master/DIPs/DIP1002.md is October 30, 
please make sure it is as good as it can be before that.



Thanks,

Andrei


Re: Pattern matching in D?

2016-10-21 Thread Dennis Ritchie via Digitalmars-d

On Friday, 21 October 2016 at 12:17:30 UTC, default0 wrote:
Unless you find a way to convince Walter and Andrei that its 
not gonna result in everyone defining their own sub-language 
within D, making D code harder to read for others and/or have 
good reasons for things they enable that currently cannot be 
done (read: have rather ugly and laborious/error-prone 
workarounds or simply no workarounds at all while being 
desirable things to want to do).


IMHO, the best option to do so to create an experimental 
D-compiler, which will support macros. And, of course, working 
examples, which will show all the positive benefits of D with 
macros. Dreams... :D)


Re: "for" statement issue

2016-10-21 Thread Adam D. Ruppe via Digitalmars-d

On Friday, 21 October 2016 at 13:33:26 UTC, Stefan Koch wrote:

It does create a lambda?
Hmm that should not happen.


Eh, that's exactly what the language rules say should happen, and 
it actually does make sense to me... you might even want to use 
an immediately-called lambda to group several statements together 
into one expression.


Though I have become convinced recently that we should deprecate 
the `{ lambdas }` in favor of `() { lambdas }`. This is the same 
mistake as `() => {xxx}` that we see a bunch of newbies make. If 
the syntax was changed to require the empty parens for the args, 
`() {}`, people would be a lot less likely to mess this up... and 
the rest of us don't seriously lose anything, adding `()` is easy 
enough if they aren't already there.


I think deprecating `{ lambda }` is really the way to go. It'd 
fix this as well at that other FAQ at pretty low cost.


Project Highlight: libasync

2016-10-21 Thread Mike Parker via Digitalmars-d-announce
A big thanks to Etienne Cimon for helping me out this week by 
sending some info on libasync my way, almost as soon as I asked 
for it, so I could do another Project Highlight. As usual, the 
relevant links follow.


The D Blog:
http://dlang.org/blog/2016/10/21/project-highlight-libasync/


Reddit:
https://www.reddit.com/r/programming/comments/58n80h/from_the_d_blog_libasync_an_event_loop_library/


Re: "for" statement issue

2016-10-21 Thread Stefan Koch via Digitalmars-d

On Friday, 21 October 2016 at 13:18:19 UTC, RazvanN wrote:
On Friday, 21 October 2016 at 12:34:58 UTC, Andrei Alexandrescu 
wrote:

[...]


I am the one who raised the question. I am n00b when it comes 
to D language (I just started reading about it a couple of days 
ago) and I tried the above mentioned code expecting that either 
the variables j and d get incremented accordingly or at least
I would get a compilation error. Instead, the program compiles 
and when run it sticks
into an infinite loop. I haven't read anything about lambda 
functions in D, but the

current outcome is very confusing for a beginner like myself.

Thanks,
RazvanN

Ah.
It does create a lambda?
Hmm that should not happen.

I agree this is confusing and unwanted.
Please feel free to post this to bugzilla.

I will take a look next month. If nobody resolves it before then.




Re: "for" statement issue

2016-10-21 Thread RazvanN via Digitalmars-d
On Friday, 21 October 2016 at 12:34:58 UTC, Andrei Alexandrescu 
wrote:

I got a question about what happens with this code:

int j;
for({j=2; int d = 3; } j+d<7; {j++; d++;}) {
}

My first instinct was that that won't compile but it 
surprisingly does. And it loops forever.


So the grammar according to 
https://dlang.org/spec/grammar.html#ForStatement is:


ForStatement:
for ( Initialize Testopt ; Incrementopt ) ScopeStatement

Initialize:
;
NoScopeNonEmptyStatement

NoScopeNonEmptyStatement:
NonEmptyStatement
BlockStatement

NonEmptyStatement goes over a bunch of odd places such as case 
statement and default statement. And then BlockStatement is the 
matched case:


BlockStatement:
{ }
{ StatementList }

So it seems we have another case in which "{" "}" do not 
introduce a scope. Fine. The real problem is with the increment 
part, which is an expression. The code { j++; d++; } is... a 
lambda expression that never gets used, which completes a very 
confusing sample.


What would be a good solution to forbid certain constructs in 
the increment part of a for statement?



Thanks,

Andrei


I am the one who raised the question. I am n00b when it comes to 
D language (I just started reading about it a couple of days ago) 
and I tried the above mentioned code expecting that either the 
variables j and d get incremented accordingly or at least
I would get a compilation error. Instead, the program compiles 
and when run it sticks
into an infinite loop. I haven't read anything about lambda 
functions in D, but the

current outcome is very confusing for a beginner like myself.

Thanks,
RazvanN


Re: Why are homepage examples too complicated?

2016-10-21 Thread Chris via Digitalmars-d

On Friday, 21 October 2016 at 12:31:00 UTC, Mark wrote:


I second that.

Also, it may be a good idea to simply use classical algorithms 
(binary search, quicksort, etc.), written in "D style", as 
examples. The typical visitor is probably familiar with these 
algorithms and thus the foreign syntax won't be as scary. It 
also puts the syntax in a context that the visitor is already 
familiar with, so there is a good chance that he'll deduce its 
meaning even without supplementary comments.


For instance, TDPL has the following implementation of binary 
search in its introductory chapter:


bool binarySearch(T)(T[] input, T value) {
   while (!input.empty) {
  auto i = input.length / 2;
  auto mid = input[i];
  if (mid > value) input = input[0 .. i];
  else if (mid < value) input = input[i + 1 .. $];
  else return true;
   }
   return false;
}

Nothing too fancy, but it's a good example of how array slicing 
in D helps make the code cleaner, shorter and easier to 
understand.


Yeah, I agree. Use common tasks everybody is familiar with. 
Sorting, searching, string handling.


Re: "for" statement issue

2016-10-21 Thread Stefan Koch via Digitalmars-d
On Friday, 21 October 2016 at 12:34:58 UTC, Andrei Alexandrescu 
wrote:

I got a question about what happens with this code:

int j;
for({j=2; int d = 3; } j+d<7; {j++; d++;}) {
}

[...]
We could restrict the initialze part to assignments only. But I 
am unsure of the implications.

How did you find this case?


"for" statement issue

2016-10-21 Thread Andrei Alexandrescu via Digitalmars-d

I got a question about what happens with this code:

int j;
for({j=2; int d = 3; } j+d<7; {j++; d++;}) {
}

My first instinct was that that won't compile but it surprisingly does. 
And it loops forever.


So the grammar according to 
https://dlang.org/spec/grammar.html#ForStatement is:


ForStatement:
for ( Initialize Testopt ; Incrementopt ) ScopeStatement

Initialize:
;
NoScopeNonEmptyStatement

NoScopeNonEmptyStatement:
NonEmptyStatement
BlockStatement

NonEmptyStatement goes over a bunch of odd places such as case statement 
and default statement. And then BlockStatement is the matched case:


BlockStatement:
{ }
{ StatementList }

So it seems we have another case in which "{" "}" do not introduce a 
scope. Fine. The real problem is with the increment part, which is an 
expression. The code { j++; d++; } is... a lambda expression that never 
gets used, which completes a very confusing sample.


What would be a good solution to forbid certain constructs in the 
increment part of a for statement?



Thanks,

Andrei


Re: Why are homepage examples too complicated?

2016-10-21 Thread Mark via Digitalmars-d

On Friday, 21 October 2016 at 10:24:40 UTC, Chris wrote:
On Thursday, 20 October 2016 at 21:52:09 UTC, Andrei 
Alexandrescu wrote:

On 10/20/2016 04:16 PM, Karabuta wrote:




We can't assume all beginners come from imperative languages. 
D beginners may come from languages where the idiomatic way of 
doing things is by means of pipelines. Generally it's not 
worth debating this because there's so little evidence to 
dwell on - please let's keep both and move with our lives. 
Thanks! -- Andrei


Today many people don't even want to see a for-loop. What we 
could do, though, is to give an example of each common or 
"expected" feature (OOP, functional, concurrency, memory model 
etc.), so that people see immediately that they can do A, B 
_and_ C in D :-)


I second that.

Also, it may be a good idea to simply use classical algorithms 
(binary search, quicksort, etc.), written in "D style", as 
examples. The typical visitor is probably familiar with these 
algorithms and thus the foreign syntax won't be as scary. It also 
puts the syntax in a context that the visitor is already familiar 
with, so there is a good chance that he'll deduce its meaning 
even without supplementary comments.


For instance, TDPL has the following implementation of binary 
search in its introductory chapter:


bool binarySearch(T)(T[] input, T value) {
   while (!input.empty) {
  auto i = input.length / 2;
  auto mid = input[i];
  if (mid > value) input = input[0 .. i];
  else if (mid < value) input = input[i + 1 .. $];
  else return true;
   }
   return false;
}

Nothing too fancy, but it's a good example of how array slicing 
in D helps make the code cleaner, shorter and easier to 
understand.


Re: mysql-native v0.1.7

2016-10-21 Thread Nick Sabalausky via Digitalmars-d-announce

On 10/21/2016 05:35 AM, Martin Tschierschke wrote:

On Thursday, 20 October 2016 at 21:25:50 UTC, Nick Sabalausky wrote:

Minor update to mysql-native: A client driver for MySQL/MariaDB
written natively in D from scratch via the published protocol specs,
with no dependency on the C MySQL client library. Supports either
Phobos or Vide.d sockets (works with or without Vibe.d).

https://github.com/mysql-d/mysql-native
DUB: http://code.dlang.org/packages/mysql-native

In v0.1.7:
- New: Test suite automatically tests with both Vibe and Phobos
sockets, not just Phobos. (@Abscissa)
- Change: Drop support for DMDFE 2.066.1 and below. Compiles on DMDFE
2.067.1 through 2.072.0.
- Fixed: Fix an import deprecation message for DMD 2.071. (@Abscissa)
- Fixed: #57: Added support for passing null parameters in prepared
statements by using Variant(null) (@machindertech)
- Fixed: #63/#69: Add escape module to package import (@Marenz)
- Fixed: #68: Update alias syntax (@Marenz)

Full changelog:
https://github.com/mysql-d/mysql-native/blob/master/CHANGELOG.md

I know I've said docs and examples are a top priority for
mysql-native, but it's become clear that the API is in serious need of
a refresh, so for the most part, I've held off on the docs this time
to avoid wasted effort documenting to-be-deprecated interfaces.

Unless any pressing issues appear, expect the next release to be an
experimental branch showcasing a beta of a new API. If possible, I'd
like to have at least one release where the old API is still
functional, but deprecated.


Please consider to look at the APIs of the other mysql libs, maybe there
is one
which you can use. I found it easier to use the APIs of  mysql-d
(https://github.com/paxa/mysql.d) but mysql-lited
(https://github.com/eBookingServices/mysql-lited) looks more enhanced.


Hmm, actually, there appears to be a lot of similarity with part of what 
I had in mind:


https://github.com/mysql-d/mysql-native/issues/83

In particular, I *really* want to pretty much get rid of the Command 
struct. Minimizing heap activity is also a goal, albeit separate from 
this API refresh.



But here too:


Documentation is not ready yet


I would be very happy, if in the end there would be only one superior
mysql-lib for D, so
all can work together to improve this one.



mysql-native gets very few PRs. :(




Re: AA ignores disabling of postblit for key types

2016-10-21 Thread Nordlöw via Digitalmars-d

On Friday, 21 October 2016 at 12:18:28 UTC, Nordlöw wrote:

this(this) { assert(false); }


If this is changed to


  @disable this(this);


I instead get a segfault because of a double free:


before
freeing:591490
after
freeing:591490
*** Error in ...

Pretty serious bug.


AA ignores disabling of postblit for key types

2016-10-21 Thread Nordlöw via Digitalmars-d

The following code


import std.stdio;

struct S(E)
{
static typeof(this) withElement(E x)
{
typeof(return) that;
that._ptr = cast(E*)malloc(1*E.sizeof);
*(that._ptr) = x;
return that;
}

// @disable this(this);
this(this) { assert(false); }

~this()
{
writeln("freeing:", _ptr);
free(_ptr);
}

E* _ptr;
}

unittest
{
alias Key = S!int;
int[Key] x;
writeln("before");
x[Key.withElement(11)] = 42;
writeln("after");
}

extern (C):
void* malloc(size_t);
void free(void*);


assert as


before
freeing:706490
core.exception.AssertError@aaNoMoveCrash.d(18): Assertion failure

??:? [0x411a3f]
??:? [0x41028f]
aaNoMoveCrash.d:18 [0x402b73]
??:? [0x413be5]
??:? [0x4126a8]
aaNoMoveCrash.d:34 [0x402a46]
??:? [0x410230]
??:? [0x41c8a0]
??:? [0x4113cb]
??:? [0x4162e6]
??:? [0x416374]
??:? [0x416277]
??:? [0x4113a7]
??:? [0x41c792]
??:? [0x412dfa]
??:? [0x412d98]
??:? [0x412d12]
??:? [0x4103bf]
??:? __libc_start_main [0x8452a82f]
freeing:706490


It seems AA's doesn't respect disabling of postblit for its 
Key-type even when it's sent as an r-value.


This is a serious bug.

Is this know?

Can somebody give hints to where I can start digging in DMD for 
fixing this?


Re: Pattern matching in D?

2016-10-21 Thread default0 via Digitalmars-d

On Friday, 21 October 2016 at 11:49:42 UTC, Mark wrote:
On Friday, 21 October 2016 at 06:50:26 UTC, Dennis Ritchie 
wrote:
Previously, there were ideas on the implementation of macros 
in D, but now they are no longer relevant:

http://s3.amazonaws.com/dconf2007/WalterAndrei.pdf


AST macros are permanently off the table?


Unless you find a way to convince Walter and Andrei that its not 
gonna result in everyone defining their own sub-language within 
D, making D code harder to read for others and/or have good 
reasons for things they enable that currently cannot be done 
(read: have rather ugly and laborious/error-prone workarounds or 
simply no workarounds at all while being desirable things to want 
to do).


At least as far as I remember those were the main points they 
were on about :o)


Re: Pattern matching in D?

2016-10-21 Thread Mark via Digitalmars-d

On Friday, 21 October 2016 at 06:50:26 UTC, Dennis Ritchie wrote:
Previously, there were ideas on the implementation of macros in 
D, but now they are no longer relevant:

http://s3.amazonaws.com/dconf2007/WalterAndrei.pdf


AST macros are permanently off the table?


Re: why std.stdio.File is a struct?

2016-10-21 Thread Chris via Digitalmars-d

On Thursday, 20 October 2016 at 12:24:14 UTC, ketmar wrote:
On Thursday, 20 October 2016 at 07:40:05 UTC, Jonathan M Davis 
wrote:
In general, in D, if you don't need inheritance and 
polymorphism, you probably shouldn't be using a class.


and even if you need, most of the time it is better to write 
templated free functions with constraints instead. ;-)


I use a few classes, but mainly to structure the program (some 
are singletons). The rest are all structs and functions/templated 
functions. On hindsight, I would probably not go down that path 
again. Better avoid the class system altogether, ask the British 
;)


Re: I can't use nodejs anymore. Please vibe.d, don't follow that path

2016-10-21 Thread Sönke Ludwig via Digitalmars-d

Am 20.10.2016 um 22:25 schrieb Karabuta:

This is actually a nodejs project's dependencies for a small code-base.

(...)

Dependencies upon dependencies. Each package comes along with its own
dependencies. I give up nodejs, you win. Now I am investing my time in
Vibe.d which I hope ...


I personally always try to minimize external dependencies, because at 
some point they always cause problems. Sometimes it's possible to 
resolve those quickly, but even then, it usually leaves a bad taste if 
they are required for the whole system to function reliably.


On the other hand, my plan is definitely to split vibe.d itself up into 
separate libraries, so that they can be maintained and versioned 
according to their individual development pace. But that means just that 
they are in separate repositories instead of submodules within the same 
one, not finer granularity.


Re: dmd or phobos were broken in ubuntu 16.10 d-apt

2016-10-21 Thread Daniel Kozak via Digitalmars-d

Dne 21.10.2016 v 12:59 Daniel Kozak napsal(a):




Dne 21.10.2016 v 12:53 mogu via Digitalmars-d napsal(a):

On Friday, 21 October 2016 at 10:05:40 UTC, Daniel Kozak wrote:
Or you can build your own version of dmd with PIC enabled and add 
-fPIC to /etc/dmd.conf


I rebuilded phobos and druntime with -fPIC and replaced the static 
libphobos2.a. Now it works well. But I have to specified -fPIC to dmd 
each time to build. Should dmd make -fPIC the default?


read my message again:

add -fPIC to /etc/dmd.conf

this should help


or maybe there is another one dmd.conf somewhere in dmd source (in place 
where your new dmd binary is)




Re: dmd or phobos were broken in ubuntu 16.10 d-apt

2016-10-21 Thread Daniel Kozak via Digitalmars-d



Dne 21.10.2016 v 12:53 mogu via Digitalmars-d napsal(a):

On Friday, 21 October 2016 at 10:05:40 UTC, Daniel Kozak wrote:
Or you can build your own version of dmd with PIC enabled and add 
-fPIC to /etc/dmd.conf


I rebuilded phobos and druntime with -fPIC and replaced the static 
libphobos2.a. Now it works well. But I have to specified -fPIC to dmd 
each time to build. Should dmd make -fPIC the default?


read my message again:

add -fPIC to /etc/dmd.conf

this should help


Re: SQLite

2016-10-21 Thread Vadim Lopatin via Digitalmars-d-learn
On Wednesday, 19 October 2016 at 16:01:37 UTC, Alfred Newman 
wrote:

Hello,

I am trying to handle a SQLite3 table with D. During my 
researchs, I discovered the lib 
https://dlang.org/phobos/etc_c_sqlite3.html.


However, for any reason, there is no code snippets or sample 
codes available there. So, I am stucked.


I have the following sample structure table:
   sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) "  \
 "VALUES (1, 'Paul', 32, 'California', 2.00 ); " \
 "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) "  \
 "VALUES (2, 'Allen', 25, 'Texas', 15000.00 ); " \
 "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \
 "VALUES (3, 'Teddy', 23, 'Norway', 2.00 );" \
 "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \
 "VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 );";

Can you pls provide a code snippet or some hints to the 
following job:

- Create a table with the layout above
- Iterate through the records given a basic SELECT WHERE Query

Thanks in advance, AN


Snippet how to do it using DDBC library 
https://github.com/buggins/ddbc


import ddbc;

string url = "sqlite:testdb.sqlite";
// creating Connection
auto conn = createConnection(url);
scope(exit) conn.close();
// creating Statement
auto stmt = conn.createStatement();
scope(exit) stmt.close();
// execute simple queries to create and fill table
stmt.executeUpdate("CREATE TABLE COMPANY (ID int, NAME 
varchar, AGE int,ADDRESS varchar, SALARY double)");

string[] statements = [
"INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES 
(1, 'Paul', 32, 'California', 2.00 )",
"INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES 
(2, 'Allen', 25, 'Texas', 15000.00 )",
"INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES 
(3, 'Teddy', 23, 'Norway', 2.00 )"

];
foreach(sql; statements)
stmt.executeUpdate(sql);



Re: dmd or phobos were broken in ubuntu 16.10 d-apt

2016-10-21 Thread mogu via Digitalmars-d

On Friday, 21 October 2016 at 10:05:40 UTC, Daniel Kozak wrote:
Or you can build your own version of dmd with PIC enabled and 
add -fPIC to /etc/dmd.conf


I rebuilded phobos and druntime with -fPIC and replaced the 
static libphobos2.a. Now it works well. But I have to specified 
-fPIC to dmd each time to build. Should dmd make -fPIC the 
default?


Re: Why are homepage examples too complicated?

2016-10-21 Thread Chris via Digitalmars-d
On Thursday, 20 October 2016 at 21:52:09 UTC, Andrei Alexandrescu 
wrote:

On 10/20/2016 04:16 PM, Karabuta wrote:




We can't assume all beginners come from imperative languages. D 
beginners may come from languages where the idiomatic way of 
doing things is by means of pipelines. Generally it's not worth 
debating this because there's so little evidence to dwell on - 
please let's keep both and move with our lives. Thanks! -- 
Andrei


Today many people don't even want to see a for-loop. What we 
could do, though, is to give an example of each common or 
"expected" feature (OOP, functional, concurrency, memory model 
etc.), so that people see immediately that they can do A, B _and_ 
C in D :-)


Re: Dustmite can't handle my memory segfault

2016-10-21 Thread Nordlöw via Digitalmars-d-learn

On Friday, 21 October 2016 at 06:44:54 UTC, Nordlöw wrote:
On Thursday, 20 October 2016 at 22:18:20 UTC, Vladimir 
Panteleev wrote:

On Thursday, 20 October 2016 at 21:33:59 UTC, Nordlöw wrote:

I need your help here, I'm complete stuck. Vladimir?


The exit status of the `./array_ex` call (as seen from bash) is 
134. How do I, in Bash, map that exit status to zero, and all 
other exit statuses to non-zero?


Solution construct a Bash script named, say show-segfault:


#!/usr/bin/env python3

import sys
import pty

stat = pty.spawn(sys.argv[1:])
if stat == 256:
exit(42)# remap to 42
else:
exit(stat)


and wrap call to rdmd as


show-segfault rdmd ...


Re: Binding rvalues to ref [WAS: I close BIP27. I won't be pursuing BIPs anymore]

2016-10-21 Thread Jonathan M Davis via Digitalmars-d
On Thursday, October 20, 2016 23:18:14 Nicholas Wilson via Digitalmars-d 
wrote:
> On Thursday, 20 October 2016 at 01:04:35 UTC, Jonathan M Davis
>
> wrote:
> > The transitivity of const shoot stuff in the foot pretty
> > thoroughly in a number of cases. A prime example would be
> > ranges, because they have to be mutated to be iterated over. If
> > the function actually took a range directly, you wouldn't
> > bother with const ref, but it could be an object that contains
> > a range, and because you can't normally get a tail-const range
> > from a const range (aside from dynamic arrays), it can become
> > quite difficult to actually iterate over the range. e.g.
> >
> > auto foo(ref const(Bar) bar)
> > {
> >
> > auto range = bar.getSomeRange();
> > ...
> >
> > }
>
> Is it legal to `.save` a const range, and then use it (provided
> it does not mutate any object reachable from bar)?

Not really. isForwardRange requires that save return _exactly_ the same type
as the range. So, it really can't work as a const function (and
const(MyRangeType) will never pass isInputRange or isFowardRange, because
popFront won't compile). You _can_ declare an overload of save that's const
and returns something different, but then it's not actually part of the
range API, and you can't rely on it working. At that point, you might as
well make up your own function, since what you're doing is non-standand
anyway.

Regardless of all that though, it's not always even possible for a range to
have a function that returns a tail-const version of the range because of
how the internals of the range work. So, even if we had a standard way to
deal with that, it couldn't work in all cases, and really, it would have to
be dealt with separately from traits like isForwardRange. Arguably, to match
arrays, we should be defining an opSlice for ranges which returns a
tail-const version of the range (and then we could have a trait like
hasTailConstSlicing), but that's not currently part of the range API, and
it's actually pretty hard to define even for simple ranges (e.g. you have to
use static if carefully to avoid recursive template instantiations).

So, the best way to handle this is very much an open question. For now, the
reality of the matter is that there is no standard way for const ranges to
work.

- Jonathan M Davis



Re: dmd or phobos were broken in ubuntu 16.10 d-apt

2016-10-21 Thread Daniel Kozak via Digitalmars-d

Dne 21.10.2016 v 10:02 tcak via Digitalmars-d napsal(a):


On Friday, 21 October 2016 at 04:16:38 UTC, mogu wrote:

[...]


Yes, we (I and one another person on this forum) have the same problem.

As a temporary solution, while compiling your program, add

-defaultlib=libphobos2.so -fPIC

This solved my problem on Ubuntu 16.10. But with one problem. Now, while
you are copying your executable to another computer, you need to copy
libphobos2.so (in my case libphobos2.so.17) to that computer's /usr/lib
as well.
Or you can build your own version of dmd with PIC enabled and add -fPIC 
to /etc/dmd.conf


Re: Pattern matching in D?

2016-10-21 Thread ArturG via Digitalmars-d

On Friday, 21 October 2016 at 02:40:45 UTC, Stefan Koch wrote:

On Friday, 21 October 2016 at 02:16:44 UTC, Chris M. wrote:
So I know you can do some pattern matching with templates in 
D, but has there been any discussion about implementing it as 
a language feature, maybe something similar to Rust's match 
keyword (https://doc.rust-lang.org/stable/book/patterns.html)? 
What would your guys' thoughts be?


How is this diffrent from "switch-case" ?


switch is a statement, rusts match is an expression and can 
return a value.



i posted this[1] templates a while ago with which you can 
probably do most of what rust can do with the match expressing 
(not tested havent looked into rust much and pattern matching 
isnt the main purpose of them), by combining existing D features.


e.g.

5.call!(a => a == 3? "three" :
 a == 5? "five"  : "nomatch").writeln;
prints:
five

5.call!((a){ a == 3? "three".writeln :
 a == 5? "five".writeln  : null;}).writeln;
prints:
five
5


[1] http://melpon.org/wandbox/permlink/ngUYhp7SS6uY283b


Re: mysql-native v0.1.7

2016-10-21 Thread Martin Tschierschke via Digitalmars-d-announce
On Thursday, 20 October 2016 at 21:25:50 UTC, Nick Sabalausky 
wrote:
Minor update to mysql-native: A client driver for MySQL/MariaDB 
written natively in D from scratch via the published protocol 
specs, with no dependency on the C MySQL client library. 
Supports either Phobos or Vide.d sockets (works with or without 
Vibe.d).


https://github.com/mysql-d/mysql-native
DUB: http://code.dlang.org/packages/mysql-native

In v0.1.7:
- New: Test suite automatically tests with both Vibe and Phobos 
sockets, not just Phobos. (@Abscissa)
- Change: Drop support for DMDFE 2.066.1 and below. Compiles on 
DMDFE 2.067.1 through 2.072.0.
- Fixed: Fix an import deprecation message for DMD 2.071. 
(@Abscissa)
- Fixed: #57: Added support for passing null parameters in 
prepared statements by using Variant(null) (@machindertech)

- Fixed: #63/#69: Add escape module to package import (@Marenz)
- Fixed: #68: Update alias syntax (@Marenz)

Full changelog:
https://github.com/mysql-d/mysql-native/blob/master/CHANGELOG.md

I know I've said docs and examples are a top priority for 
mysql-native, but it's become clear that the API is in serious 
need of a refresh, so for the most part, I've held off on the 
docs this time to avoid wasted effort documenting 
to-be-deprecated interfaces.


Unless any pressing issues appear, expect the next release to 
be an experimental branch showcasing a beta of a new API. If 
possible, I'd like to have at least one release where the old 
API is still functional, but deprecated.


Please consider to look at the APIs of the other mysql libs, 
maybe there is one
which you can use. I found it easier to use the APIs of  mysql-d 
(https://github.com/paxa/mysql.d) but mysql-lited 
(https://github.com/eBookingServices/mysql-lited) looks more 
enhanced. But here too:



Documentation is not ready yet


I would be very happy, if in the end there would be only one 
superior mysql-lib for D, so

all can work together to improve this one.

Regards mt.





Re: DLang/Wiki/'Hello World'/Run Code/Disassembly

2016-10-21 Thread cym13 via Digitalmars-d-learn

On Friday, 21 October 2016 at 08:58:50 UTC, DLearner wrote:
Code ran with expected output, but Disassembly seemed to go in 
a loop?


What makes you think that? It's hard to tell if you don't give 
any information.


Let's do that! I'll use only naive flags and all and use radare2 
to
disassemble the main D function which is _Dmain (the entry point 
has to

launch the runtime etc... we aren't very interested in that):

$ cat >test.d <│   0x08077e73  b9d02b0a08 mov ecx, 
str.Hello_World_;

"Hello World!" @ 0x80a2bd0
│   0x08077e78  b80c00 mov eax, 0xc
│   0x08077e7d  51 push ecx
│   0x08077e7e  50 push eax
│   0x08077e7f  e80400 call
sym._D3std5stdio16__T7writelnTAyaZ7writelnFNfAyaZv
│   0x08077e84  31c0   xor eax, eax
│   0x08077e86  5d pop ebp
└   0x08077e87  c3 ret

No loop. Not even a jump. I'm in x86 so arguments are simply 
pushed on the

stack. No brainer.


DLang/Wiki/'Hello World'/Run Code/Disassembly

2016-10-21 Thread DLearner via Digitalmars-d-learn
Code ran with expected output, but Disassembly seemed to go in a 
loop?




Re: Binding temporaries to ref [WAS: I close BIP27. I won't be pursuing BIPs anymore]

2016-10-21 Thread Manu via Digitalmars-d
On 21 October 2016 at 06:57, Walter Bright via Digitalmars-d <
digitalmars-d@puremagic.com> wrote:

> On 10/20/2016 12:49 PM, Andrei Alexandrescu wrote:
>
>> On 10/20/2016 06:23 AM, Ethan Watson wrote:
>>
>>> Suitable enough for simple functions. But beyond that becomes
>>> maintenance hell.
>>>
>>
>> I agree this workaround has a combinatorial problem.
>>
>
> Yes, Ethan made a good point I hadn't thought of.


Shoot me! ;)


Re: Binding temporaries to ref [WAS: I close BIP27. I won't be pursuing BIPs anymore]

2016-10-21 Thread Walter Bright via Digitalmars-d

On 10/21/2016 12:56 AM, Ethan Watson wrote:

I'll start doing that. Hopefully I'll get a draft up that I'll pass to Manu for
comment/input this weekend before posting it properly.


Great!


Re: Meta-programming detecting anonymous unions inside structs.

2016-10-21 Thread TheFlyingFiddle via Digitalmars-d-learn
On Friday, 21 October 2016 at 08:18:58 UTC, rikki cattermole 
wrote:

On 21/10/2016 9:13 PM, TheFlyingFiddle wrote:
On Friday, 21 October 2016 at 07:56:27 UTC, rikki cattermole 
wrote:

You're gonna have to use UDA's for that.


Yes, to do the serialization you're right.

But my usecase for this is for error reporting. Basically any 
struct
that contains unions without serialization instructions cannot 
be

serialized and I want to make such structures errors.

So when I try to serialize the example struct Foo. It should 
assert with

something along the lines of:

"Don't know how to serialize overlapping fields: "Foo.integer",
"Foo.floating" and "Foo.array".


I suppose you could use .offsetof to determine this.


This is what I was looking for. Thanks!


Re: Meta-programming detecting anonymous unions inside structs.

2016-10-21 Thread rikki cattermole via Digitalmars-d-learn

On 21/10/2016 9:13 PM, TheFlyingFiddle wrote:

On Friday, 21 October 2016 at 07:56:27 UTC, rikki cattermole wrote:

You're gonna have to use UDA's for that.


Yes, to do the serialization you're right.

But my usecase for this is for error reporting. Basically any struct
that contains unions without serialization instructions cannot be
serialized and I want to make such structures errors.

So when I try to serialize the example struct Foo. It should assert with
something along the lines of:

"Don't know how to serialize overlapping fields: "Foo.integer",
"Foo.floating" and "Foo.array".


I suppose you could use .offsetof to determine this.



Re: dmd or phobos were broken in ubuntu 16.10 d-apt

2016-10-21 Thread tcak via Digitalmars-d

On Friday, 21 October 2016 at 04:16:38 UTC, mogu wrote:

[...]


Yes, we (I and one another person on this forum) have the same 
problem.


As a temporary solution, while compiling your program, add

-defaultlib=libphobos2.so -fPIC

This solved my problem on Ubuntu 16.10. But with one problem. 
Now, while
you are copying your executable to another computer, you need to 
copy
libphobos2.so (in my case libphobos2.so.17) to that computer's 
/usr/lib

as well.


Re: Binding temporaries to ref [WAS: I close BIP27. I won't be pursuing BIPs anymore]

2016-10-21 Thread Ethan Watson via Digitalmars-d
On Thursday, 20 October 2016 at 19:49:42 UTC, Andrei Alexandrescu 
wrote:
I think a solid DIP addressing the problem would have a good 
chance to get traction.


I think all the information in this thread and the "Binding 
rvalues to const ref in D" thread that Atilla started is enough 
for me to write up a solid DIP.


I'll start doing that. Hopefully I'll get a draft up that I'll 
pass to Manu for comment/input this weekend before posting it 
properly.


Meta-programming detecting anonymous unions inside structs.

2016-10-21 Thread TheFlyingFiddle via Digitalmars-d-learn
I am trying to port a serialization library I wrote in Lua some 
time ago. I've ran into a problem relating to types with 
anonymous unions inside.


Given this code:
enum Kind
{
   none = 0,
   array,
   integer,
   floating,
}

struct Foo
{
   Kind type;
   union
   {
   ulong  integer;
   double floating;
   void[] array;
   }
   int nonUnionField;
   //...
}

How can I tell that "integer", "floating" and "array" are part 
the union while "nonUnionField" is not?


Thanks in advance.


Re: Meta-programming detecting anonymous unions inside structs.

2016-10-21 Thread rikki cattermole via Digitalmars-d-learn

On 21/10/2016 8:55 PM, TheFlyingFiddle wrote:

I am trying to port a serialization library I wrote in Lua some time
ago. I've ran into a problem relating to types with anonymous unions
inside.

Given this code:
enum Kind
{
   none = 0,
   array,
   integer,
   floating,
}

struct Foo
{
   Kind type;
   union
   {
   ulong  integer;
   double floating;
   void[] array;
   }
   int nonUnionField;
   //...
}

How can I tell that "integer", "floating" and "array" are part the union
while "nonUnionField" is not?

Thanks in advance.


You're gonna have to use UDA's for that.


Re: Pattern matching in D?

2016-10-21 Thread mogu via Digitalmars-d

On Friday, 21 October 2016 at 06:50:26 UTC, Dennis Ritchie wrote:


The problem is that D is not macros, and the implementation of 
pattern matching without macros will not be very good. In turn, 
the implementation of macros in D - this is also not a good 
idea.


Agreed. D has not macro, this makes argly syntax while using 
mixin instead. Event C/C++ has c-macro to fix the syntax issues.


Re: Pattern matching in D?

2016-10-21 Thread Stefan Koch via Digitalmars-d

On Friday, 21 October 2016 at 02:16:44 UTC, Chris M. wrote:
So I know you can do some pattern matching with templates in D, 
but has there been any discussion about implementing it as a 
language feature, maybe something similar to Rust's match 
keyword (https://doc.rust-lang.org/stable/book/patterns.html)? 
What would your guys' thoughts be?


How is this diffrent from "switch-case" ?


Pattern matching in D?

2016-10-21 Thread Chris M. via Digitalmars-d
So I know you can do some pattern matching with templates in D, 
but has there been any discussion about implementing it as a 
language feature, maybe something similar to Rust's match keyword 
(https://doc.rust-lang.org/stable/book/patterns.html)? What would 
your guys' thoughts be?





  1   2   >