Re: Auto keyword with const variable

2013-07-25 Thread Dicebot

On Wednesday, 24 July 2013 at 11:26:32 UTC, Mike Parker wrote:
This is the exact behavior I would expect. I think of auto as 
this variable is going to be the same type as that variable. 
Since in is const int, then j also is going to be const int. If 
you want to copy n into a nonconst variable, you have to cast 
away the const.


int j = cast( int )n;
auto j = cast( int )n;


Casting is always an extreme measure, one that should be avoided 
in mundane code as much as possible. Despite the fact `auto` 
behaves as it should, this really highlights lack of `mutable` 
attribute in language.


Re: Build / Package system

2013-07-25 Thread Elie Morisse

On Wednesday, 30 May 2012 at 08:13:34 UTC, Sputnik wrote:

There is a build and/or package managment system for D2 that is
working?
I googled, and I only can find things like dsss or cmaked that
don't get updated from a long time ago.

I really need to manage to get a project to compile in Windows
and Linux. Actually the code not have any OS dependence, so the
real diferences in each OS are the linking to gtkd and how and
where install the project. Actually I'm using a makfile in Linux
that works well, but I can't use it in windows for thing like
pkg-config.


CMakeD is actually just a bunch of CMake modules and very 
lightweight, it wouldn't be surprising if it still worked or 
required more than a few minor changes.


I've decided today to migrate my project from C++ to D after 
being annoyed by the lack of conditional evaluation of code in 
C++ and the opposition of the core designers of C++ to static if, 
so I will report later if CMakeD is still useable.


Interesting line in the recent Dr Dobbs article about profiling?

2013-07-25 Thread Gary Willoughby

I've just read the article over at Dr Dobbs by Walter

http://www.drdobbs.com/cpp/increasing-compiler-speed-by-over-75/240158941

and this line caught my eye:


Even if you know your code well, you're likely wrong about where
the performance bottlenecks are. Use a profiler. If you haven't
used one on your codebase in a while, it's highly likely there's
a bottleneck in there that's fixable with just a few lines of 
code.


What profilers do you use with D especially for Linux and Mac? 
I've been compiling with -profile and trying to grok the output.


Re: Interesting line in the recent Dr Dobbs article about profiling?

2013-07-25 Thread H. S. Teoh
On Thu, Jul 25, 2013 at 08:15:42PM +0200, Gary Willoughby wrote:
 I've just read the article over at Dr Dobbs by Walter
 
 http://www.drdobbs.com/cpp/increasing-compiler-speed-by-over-75/240158941
 
 and this line caught my eye:
 
 Even if you know your code well, you're likely wrong about where
 the performance bottlenecks are. Use a profiler. If you haven't
 used one on your codebase in a while, it's highly likely there's
 a bottleneck in there that's fixable with just a few lines of
 code.

I can personally testify to the truth of this statement. All too often,
too much time is spent optimizing parts of code that are actually
irrelevant to the performance of the program, because the bottleneck
lies elsewhere, often in an unexpected place. (Not to mention that such
premature optimization makes your code harder to write, harder to read,
harder to maintain, and therefore more prone to bugs.)

I remember at least one instance in which a profiler immediately
revealed an fprintf (this was C/C++ code, back in the day) where it
shouldn't be, the removal of which instantly improved performance by at
least 30%, probably more.


 What profilers do you use with D especially for Linux and Mac? I've
 been compiling with -profile and trying to grok the output.

I use gdc with gprof, usually. I've only tried dmd -profile a few times.


T

-- 
I think Debian's doing something wrong, `apt-get install pesticide',
doesn't seem to remove the bugs on my system! -- Mike Dresser


Re: A little of coordination for Rosettacode

2013-07-25 Thread bearophile
This D entry uses Tango, but it should also show a version for 
Phobos:


http://rosettacode.org/wiki/Rosetta_Code/Count_examples#D

Bye,
bearophile


Re: A little of coordination for Rosettacode

2013-07-25 Thread bearophile
This D entry uses Tango, but it should also show a version for 
Phobos:


http://rosettacode.org/wiki/Rosetta_Code/Count_examples#D


Two versions


The Mathematica solution is short:

TaskList = Flatten[
   
Import[http://rosettacode.org/wiki/Category:Programming_Tasks;, 
Data][[1, 1]]];

Print[Task \, StringReplace[#, _ -  ], \ has ,
  Length@Select[Import[http://rosettacode.org/wiki/;  #, 
Data][[1,2]],
  StringFreeQ[#, __ ~~ Programming Task | __ ~~ Omit] ],  
example(s)]

  ~Map~ StringReplace[TaskList,   - _]


This Perl solution is compact:

use v5.10;
use Mojo::UserAgent;

my $site = http://rosettacode.org;;
my $list_url = 
/mw/api.php?action=querylist=categorymemberscmtitle=Category:Programming_Taskscmlimit=500format=xml;


my $ua = Mojo::UserAgent-new;
$ua-get($site$list_url)-res-dom-find('cm')-each(sub {
(my $slug = $_-{title}) =~ tr/ /_/;
my $count = 
$ua-get($site/wiki/$slug)-res-dom-find(#toc 
.toclevel-1)-size;

say $_-{title}: $count examples;
});



The F# solution performs downloads concurrently and it's said to 
be fast:


#r System.Xml.Linq.dll

let uri1 = 
http://www.rosettacode.org/w/api.php?action=querylist=categorymemberscmtitle=Category:Programming_Taskscmlimit=500format=xml;
let uri2 task = sprintf 
http://www.rosettacode.org/w/index.php?title=%saction=raw; task


[|for xml in (System.Xml.Linq.XDocument.Load 
uri1).Root.Descendants() do

for attrib in xml.Attributes() do
  if attrib.Name.LocalName = title then
yield async {
  let uri = uri2 (attrib.Value.Replace( , _) | 
System.Web.HttpUtility.UrlEncode)

  use client = new System.Net.WebClient()
  let! html = client.AsyncDownloadString(System.Uri uri)
  let sols' = html.Split([|{{header||], 
System.StringSplitOptions.None).Length - 1
  lock stdout (fun () - printfn %s: %d examples 
attrib.Value sols')

  return sols' }|]
| Async.Parallel
| Async.RunSynchronously
| fun xs - printfn Total: %d examples (Seq.sum xs)


Bye,
bearophile


Copying copy?

2013-07-25 Thread bearophile
Range-based functions see strings and char[] to arrays of dchar, 
but is that behavour good for std.algorithm.copy too?


I find this a bit silly:


import std.algorithm: copy;
void main() {
char[5] arr1 = hello, arr2;
arr1[].copy(arr2[]); // Error.
dchar[arr1.length] arr3;
arr1[].copy(arr3[]); // OK.
}


What do you think?

Bye,
bearophile


Should I Use std.ascii.isWhite or std.uni.isWhite?

2013-07-25 Thread Meta
I'm confused about which isWhite function I should use. Aren't 
all chars in D (char, wchar, dchar) unicode characters? Should I 
always use std.uni.isWhite, unless I'm working with bytes and 
byte arrays? The documentation doesn't give me much to go on, 
beside All of the functions in std.ascii accept unicode 
characters but effectively ignore them. All isX functions return 
false for unicode characters, and all toX functions do nothing to 
unicode characters.


Re: Should I Use std.ascii.isWhite or std.uni.isWhite?

2013-07-25 Thread Jonathan M Davis
On Friday, July 26, 2013 06:09:39 Meta wrote:
 I'm confused about which isWhite function I should use. Aren't
 all chars in D (char, wchar, dchar) unicode characters? Should I
 always use std.uni.isWhite, unless I'm working with bytes and
 byte arrays? The documentation doesn't give me much to go on,
 beside All of the functions in std.ascii accept unicode
 characters but effectively ignore them. All isX functions return
 false for unicode characters, and all toX functions do nothing to
 unicode characters.

Unicode contains ASCII, but very few Unicode characters are ASCII, because 
there just aren't very many ASCII characters and there and a _ton_ of Unicode 
characters. The std.ascii functions return true for certain sets of ASCII 
characters and false for everything else. The std.uni functions return true 
for many Unicode characters as well. You wouldn't normally use std.ascii if 
you're operating on non-ASCII Unicode characters, but it ignores them if it 
does run into them.

std.ascii.isWhite only cares about ASCII whitespace, which the documentation 
explicitly lists as the space, tab, vertical tab, form feed, carriage return, 
and linefeed characters. Those characters will return true. All other 
characters will return false.

std.uni.isWhite returns true for all of the characters that std.ascii.isWhite 
does plus a whole bunch of other non-ASCII characters that the Unicode 
standard considers to be whitespace.

Which function you use depends on what you're trying to do.

- Jonathan M Davis


Re: Copying copy?

2013-07-25 Thread Ali Çehreli

On 07/25/2013 04:55 PM, bearophile wrote:

Range-based functions see strings and char[] to arrays of dchar, but is
that behavour good for std.algorithm.copy too?

I find this a bit silly:


import std.algorithm: copy;
void main() {
 char[5] arr1 = hello, arr2;
 arr1[].copy(arr2[]); // Error.
 dchar[arr1.length] arr3;
 arr1[].copy(arr3[]); // OK.
}


What do you think?

Bye,
bearophile


I agree. I would expect copy to maintain the same type.

Ali



Re: Should I Use std.ascii.isWhite or std.uni.isWhite?

2013-07-25 Thread anonymous

On Friday, 26 July 2013 at 04:09:46 UTC, Meta wrote:
I'm confused about which isWhite function I should use. Aren't 
all chars in D (char, wchar, dchar) unicode characters?


They are.

Should I always use std.uni.isWhite, unless I'm working with 
bytes and byte arrays?


No, char vs byte isn't necessarily a thing here.

The documentation doesn't give me much to go on, beside All of 
the functions in std.ascii accept unicode characters but 
effectively ignore them. All isX functions return false for 
unicode characters, and all toX functions do nothing to unicode 
characters.


You should use std.uni.isWhite unless you want to match only 
ASCII white space.


That could be the case when ...
* You have data that is not in Unicode, but some other superset 
of ASCII. Then you shouldn't use std.uni.isWhite, of course. 
std.ascii.isWhite might be fine. In this case, you'd actually use 
u{byte,short,int} instead of {,w,d}char.
* You're dealing with a grammar where ASCII white space is a 
thing, while Unicode white space is not.
* There's really only ASCII white space in your data, and you 
want every bit of speed, and you've verified that 
std.ascii.isWhite is indeed faster than std.uni.isWhite.