Re: DUB git master hang

2014-07-17 Thread Nordlöw

On Wednesday, 16 July 2014 at 08:03:40 UTC, Sönke Ludwig wrote:
and to extract them in the second iteration. Maybe some kind of 
Phobos regression? Which DMD version do you use?


I'm testing using DMD and Phobos git master.


teething troubles

2014-07-17 Thread Dean via Digitalmars-d-learn

Hi all,

  I need a little helping hand with dmd on a 32 bit Debian box. I
installed dmd from http://d-apt.sourceforge.net/

i) First trial:


$cat test.d

import std.stdio;
void main() {
   writeln(hello);
}

$ time dmd test.d

real0m2.355s
user0m1.652s
sys 0m0.364s

$./test
hello

$ dmd -v test.d | wc -l
84


Seems to be working. My only concern is whether 2.35s for
compiling such a trivial file is normal.

ii) 2nd trial

==
I installed gdc. Now I get
$ time gdc test.d

real0m6.286s
user0m3.856s
sys 0m0.884s
==

Given the dmd and gdc timings, it seems I am doing something
wrong.

iii) 3rd trial

I installed tango from http://d-apt.sourceforge.net/ I know this
can ruffle feathers. Please assume good faith. I am just trying
to learn from the tango book.

===

$ls /usr/include/dmd/tango

core  io  math  net  stdc  sys  text  time  util

$cat test.d

import tango.io.Stdout;

void main() {
   Stdout (hello).newline;
}

$dmd -I/usr/include/dmd/tango  -v test.d


binarydmd
version   v2.065
config/etc/dmd.conf
parse test
importall test
importobject
(/usr/include/dmd/druntime/import/object.di)
importtango.io.Stdout   (tango/io/Stdout.d)
test.d(1): Error: module Stdout is in file 'tango/io/Stdout.d'
which cannot be read
import path[0] = /usr/include/dmd/tango
import path[1] = /usr/include/dmd/phobos
import path[2] = /usr/include/dmd/druntime/import


It seems inspite of specifying usr/include/dmd/tango it cannot
import tango.io.Stdout.

Here is my /etc/dmd.conf

[Environment32]
DFLAGS=-I/usr/include/dmd/phobos
-I/usr/include/dmd/druntime/import -L-L/usr/lib/i386-linux-gnu
-L--export-dynamics

What am I doing wrong.

Thanks for the help.

-- Dean


Re: teething troubles

2014-07-17 Thread bearophile via Digitalmars-d-learn

Dean:

  I need a little helping hand with dmd on a 32 bit Debian box. 
I

installed dmd from http://d-apt.sourceforge.net/

i) First trial:


$cat test.d

import std.stdio;
void main() {
   writeln(hello);
}

$ time dmd test.d

real0m2.355s
user0m1.652s
sys 0m0.364s

$./test
hello

$ dmd -v test.d | wc -l
84


Seems to be working. My only concern is whether 2.35s for
compiling such a trivial file is normal.


On a Windows 32 bit that little program compiles in 0.74 seconds 
(warmed up time) using and old CPU. Modern CPUs should take about 
0.5 seconds.


Keep in mind that writeln and std.stdio are lot of stuff. If you 
use C io functions:


void main() {
import core.stdc.stdio;

puts(hello);
}


This compiles in 0.18 seconds (warmed up time) on the same 
computer with dmd. The difference between 0.74 and 0.18 is more 
or less a constant if you use std.stdio.



I have also tried this C++ version:

#include iostream

int main() {
std::cout  hello  std::endl;
return 0;
}


With gcc 4.8.0 it takes me 0.48 seconds to compile (warmed up 
time).


Writeln manages unicode, and is quite more refined than iostream.

Bye,
bearophile


Re: teething troubles

2014-07-17 Thread Dean via Digitalmars-d-learn
On a Windows 32 bit that little program compiles in 0.74 
seconds (warmed up time) using and old CPU. Modern CPUs should 
take about 0.5 seconds.


Thanks for checking the timings wait I am not alone in using a
32 bit box !

Mine is an Athlon 1045.456 MHz. The minimum of 3 consecutive
compilation runs that I get is 2.3 seconds.


Keep in mind that writeln and std.stdio are lot of stuff.


Just to be clear I am not complaining dmd is slow. I am just
concerned that I am doing something wrong.


I have also tried this C++ version:

#include iostream
int main() {
std::cout  hello  std::endl;
return 0;
}
With gcc 4.8.0 it takes me 0.48 seconds to compile (warmed up 
time).


On my box this compiles in 1.2 seconds. So it seems somewhat
consistent (as in 3 times slower for both). I got worried because
I expected dmd to compile hello world substantially faster than
g++. I have heard that dmd is instantaneous.


I am still at a loss about tango for D2 problem. Shouldnt
providing the -I option with the path to tango work. Does any
other magic need to happen. I dont know the internal mechanics of
importing modules.


Re: teething troubles

2014-07-17 Thread bearophile via Digitalmars-d-learn

Dean:


Mine is an Athlon 1045.456 MHz. The minimum of 3 consecutive
compilation runs that I get is 2.3 seconds.


Then I think your timings could be OK, I am using an old 2.3 GHz 
CPU.




On my box this compiles in 1.2 seconds. So it seems somewhat
consistent (as in 3 times slower for both).


OK.



I got worried because I expected dmd to compile hello world
substantially faster than g++. I have heard that dmd is 
instantaneous.


dmd compiles very quickly, but to compile writeln D has to digest 
a good amount of Phobos code. So you will not see a much larger 
compilation time if you compile small D programs.




I am still at a loss about tango for D2 problem.


I think I've never used Tango with dmd.

Bye,
bearophile


Re: teething troubles

2014-07-17 Thread Dean via Digitalmars-d-learn

On Thursday, 17 July 2014 at 09:32:24 UTC, bearophile wrote:

Dean:


Mine is an Athlon 1045.456 MHz.

   
Didn't notice that before hitting send.


compilation runs that I get is 2.3 seconds.
Then I think your timings could be OK, I am using an old 2.3 
GHz CPU.


Glad to know that I am not doing something stupid, yet.

dmd compiles very quickly, but to compile writeln D has to 
digest a good amount of Phobos code.


Are the reasons for this similar to why C++ STL is not an object
code library ?


I am still at a loss about tango for D2 problem.

I think I've never used Tango with dmd.


Not even sure if its a tango problem. Dmd doesn't seem to be
picking up the path that I specify with -I. Perhaps the mechanics
of module loading is not as simple as I imagine. I initially
thought its a permission problem, but that is not the case.


Re: teething troubles

2014-07-17 Thread bearophile via Digitalmars-d-learn

Dean:

dmd compiles very quickly, but to compile writeln D has to 
digest a good amount of Phobos code.


Are the reasons for this similar to why C++ STL is not an object
code library ?


The reasons for the large amount of code compiled for a writeln 
are that: writeln is more powerful, Phobos modules import each 
other a lot. And several parts of Phobos are not compiled because 
there are templates everywhere. Take a look at Phobos sources and 
you will see.


Bye,
bearophile


Re: Generating Strings with Random Contents

2014-07-17 Thread Nordlöw
On Wednesday, 16 July 2014 at 23:24:24 UTC, Joseph Rushton 
Wakeling via Digitalmars-d-learn wrote:
Are you interested in having each character in the sequence 
randomly chosen independently of all the others, or do you want 
a random subset of all available characters (i.e. no character 
appears more than once), or something else again?


Just a random dchar (ciode point) sample like this:

/** Generate Random Contents of $(D x).
See also: 
http://forum.dlang.org/thread/emlgflxpgecxsqwea...@forum.dlang.org

 */
auto ref randInPlace(ref dchar x) @trusted
{
auto ui = uniform(0,
  0xD800 +
  (0x11 - 0xE000) - 2 // minus two for 
U+FFFE and U+

);
if (ui  0xD800)
{
return x = ui;
}
else
{
ui -= 0xD800;
ui += 0xE000;

// skip undefined
if (ui  0xFFFE)
return x = ui;
else
ui += 2;

assert(ui  0x11);
return x = ui;
}
}

I don't know how well this plays with

unittest
{
import dbg;
dln(randomized!dchar);
dstring d = 
alphaalphaalphaalphaalphaalphaalphaalphaalphaalpha;

dln(d.randomize);
}

though.

See complete logic at

https://github.com/nordlow/justd/blob/master/random_ex.d


Re: teething troubles

2014-07-17 Thread Dean via Digitalmars-d-learn

On Thursday, 17 July 2014 at 10:13:46 UTC, bearophile wrote:

Dean:

dmd compiles very quickly, but to compile writeln D has to 
digest a good amount of Phobos code.


Are the reasons for this similar to why C++ STL is not an 
object

code library ?


The reasons for the large amount of code compiled for a writeln 
are that: writeln is more powerful, Phobos modules import each 
other a lot. And several parts of Phobos are not compiled 
because there are templates everywhere. Take a look at Phobos 
sources and you will see.


Bye,
bearophile


Apologies, I wasnt clear. I was talking about the reason behind
compiling the code from source as opposed to linking precompiled
objects. I was speculating wether the reasons are similar to that 
of STL, i.e. specializing to the type as late as possible.


Re: md5 hashing acting strangly?

2014-07-17 Thread Kagamin via Digitalmars-d-learn

On Wednesday, 16 July 2014 at 18:17:25 UTC, Ali Çehreli wrote:

On 07/16/2014 06:31 AM, Kagamin wrote:

I have a more pragmatic view. Do you know the issue number?


  https://issues.dlang.org/show_bug.cgi?id=8838


This is not about temporary. Well, looks like it's not there.


LuaD: How to load modules

2014-07-17 Thread Chris via Digitalmars-d-learn
I'm using / testing LuaD atm. It works very well, however, I've 
encountered a problem. When I load the module lualsp (for lua 
server pages) the app crashes. If I run the lua script on its own


$ lua5.1 test.lua

it works perfectly fine. The lua server page is executed 
correctly. If I run the same script from within LuaD, the app 
crashes, same goes for


lua.doString(require \lualsp\);

I haven't been able to figure out how to load the module into lua 
correctly, obviously there is something going wrong. I hope there 
is a way.


The script test.lua:

-- test.lua
require lualsp

-- function from lualsp module written in C++
dofile_lsp(../examples/example1.html)
-- end test.lua

The lsp file:

html
  body

? name = Chris?

? print(name) ?

  /body
/html


Re: teething troubles

2014-07-17 Thread Mike Parker via Digitalmars-d-learn

On 7/17/2014 7:01 PM, Dean wrote:



Not even sure if its a tango problem. Dmd doesn't seem to be
picking up the path that I specify with -I. Perhaps the mechanics
of module loading is not as simple as I imagine. I initially
thought its a permission problem, but that is not the case.


What does your tango source tree look like? Is it a) or b)?

a) /usr/include/dmd/tango/io/Stdout.d
b) /usr/include/dmd/tango/tango/io/Stdout.d

When you pass -I/usr/include/dmd/tango, then it needs to look like b). 
If it's a), then you should pass -I/usr/include/dmd. The reason is that 
'tango' is the top-level package directory. Its *parent* directory needs 
to be on the import path.


---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com



Re: Extended math library

2014-07-17 Thread John Colvin via Digitalmars-d-learn

On Thursday, 17 July 2014 at 00:28:19 UTC, ponce wrote:

On Wednesday, 16 July 2014 at 21:12:00 UTC, bachmeier wrote:
Have you tried them? Do they work? I couldn't get scid to work 
last year. I've never heard of dstats before, but it hasn't 
seen any activity in two years. I'd be surprised if it worked 
with the latest release of DMD.


Can't speak for scid, but dstats shouldn't be hard to bring 
up-to-date.


I've just brought dstats up to date and got it passing the 
unittests. I'm not sure how comprehensive they are.Also, there's 
a certain amount of printout from the tests that I don't know 
enough to judge.).


I'm getting a segfault on dmd git HEAD* but the latest releases 
of gdc and ldc are working fine.


Re: LuaD: How to load modules

2014-07-17 Thread Chris via Digitalmars-d-learn

On Thursday, 17 July 2014 at 10:53:56 UTC, Chris wrote:
I'm using / testing LuaD atm. It works very well, however, I've 
encountered a problem. When I load the module lualsp (for lua 
server pages) the app crashes. If I run the lua script on its 
own


$ lua5.1 test.lua

it works perfectly fine. The lua server page is executed 
correctly. If I run the same script from within LuaD, the app 
crashes, same goes for


lua.doString(require \lualsp\);

I haven't been able to figure out how to load the module into 
lua correctly, obviously there is something going wrong. I hope 
there is a way.


The script test.lua:

-- test.lua
require lualsp

-- function from lualsp module written in C++
dofile_lsp(../examples/example1.html)
-- end test.lua

The lsp file:

html
  body

? name = Chris?

? print(name) ?

  /body
/html


What works is when I compile lualsp into a static library and 
then link my program against it. Then I can do:


lua_State* L = luaL_newstate();
auto lua = new LuaState(L);
lua.openLibs();
int lib = luaopen_lualsp(L);  // defined in llsplib.cpp (i.e. the 
module)


if (lib == 0) {
  auto lsp = lua.get!LuaFunction(dofile_lsp);
  lua.doString(dofile_lsp('path/to/example1.html'));
}

But I want to be able to load an external library dynamically.


range foreach lambda

2014-07-17 Thread ddos via Digitalmars-d-learn

for example i have an array

int[] a = [1,2,3,4,5];

and a function

auto twice  = function (int x) = x * 2;

how can i apply the function to each element in a without using a 
forloop? - is there a function to do this?


a.foreach(x = x * 2);
a == [2,4,6,8,10]



Re: range foreach lambda

2014-07-17 Thread bearophile via Digitalmars-d-learn

ddos:


auto twice  = function (int x) = x * 2;


function is not necessary. And generally it's better to assign 
to immutables, unless you need to mutate the variable twice 
later.



how can i apply the function to each element in a without using 
a forloop? - is there a function to do this?


Generally such range based functions are designed for a 
functional style of coding, so a map is meant to produce a new 
(lazy) range.


If you really want to mutate in-place, you can use a copy:


void main() {
import std.algorithm;
auto a = [1, 2, 3, 4, 5];

immutable twice = (int x) = x * 2;

a.map!(x = x * 2).copy(a);
assert(a == [2, 4, 6, 8, 10]);
}


But this could introduce bugs, so better to limit the number of 
times you use similar code.


So this is more idiomatic and safer:

void main() {
import std.algorithm;

immutable data = [1, 2, 3, 4, 5];
auto result = data.map!(x = x * 2);
assert(result.equal([2, 4, 6, 8, 10]));
}

Bye,
bearophile


Re: range foreach lambda

2014-07-17 Thread ddos via Digitalmars-d-learn
thx alot! its not important to me that the function is not 
evaluated in place
since you gave me such a straight answer i'd like to bother you 
with another question :)


for example i have now two ranges:

immutable a = [1,2,3,4];
immutable b = [2,3,4,5];

how do i add the elements in a and b elementwise in a functional 
style?


a+b == [3,5,7,9]

usually i'd do something like this:

int[4] o;
for(int i=0;i4;i++)
{
  o[i] = a[i] + b[i];
}


Re: range foreach lambda

2014-07-17 Thread bearophile via Digitalmars-d-learn

ddos:


how do i add the elements in a and b elementwise


Several ways to do it:

void main() {
import std.range, std.algorithm, std.array;

immutable a = [1, 2, 3, 4];
immutable b = [2, 3, 4, 5];

int[] c1;
c1.reserve(a.length); // Optional.
foreach (immutable x, immutable y; a.zip(b))
c1 ~= x + y;
assert(c1 == [3, 5, 7, 9]);

auto c2a = a.zip(b).map!(ab = ab[0] + ab[1]); // Lazy.
assert(c2a.equal([3, 5, 7, 9]));
const c2b = c2a.array;
assert(c2b == [3, 5, 7, 9]);

auto c3 = new int[a.length];
c3[] = a[] + b[];
assert(c3 == [3, 5, 7, 9]);

int[4] c4 = a[] + b[];
assert(c4 == [3, 5, 7, 9]);
}

Bye,
bearophile


Re: SImple C++ code to D

2014-07-17 Thread Meta via Digitalmars-d-learn

On Tuesday, 15 July 2014 at 16:04:26 UTC, bearophile wrote:

Alexandre:


mapstring, Address syms;


If you don't need the key ordering then use a built-in 
associative array:


Address[string] syms;

Otherwise use a RedBlackTree from std.container.



vectorpairDWORD, Address values;
vectorpairDWORD, shared_ptrDWORD addrs;


Tuple!(DWORD, Address)[] values;
Tuple!(DWORD, DWORD*)[] addrs;

Tuple and tuple are in std.typecons.

Bye,
bearophile


For `Tuple!(DWORD, DWORD*)[] addrs;`, DWORD* is not same as 
shared_ptrDWORD. It's important to keep that in mind.


Re: SImple C++ code to D

2014-07-17 Thread Meta via Digitalmars-d-learn

On Thursday, 17 July 2014 at 13:40:20 UTC, bearophile wrote:

Meta:

For `Tuple!(DWORD, DWORD*)[] addrs;`, DWORD* is not same as 
shared_ptrDWORD. It's important to keep that in mind.


OK. How do you suggest to translate it in D?

Bye,
bearophile


I don't know. I just wanted to make sure OP knew that raw 
pointers in D are not analogous to C++ shared_ptr.


Re: Extended math library

2014-07-17 Thread John Colvin via Digitalmars-d-learn

On Tuesday, 15 July 2014 at 20:46:32 UTC, Martijn Pot wrote:

To make a long story short:

Is there any math library with e.g. mean, std, polynomial 
fitting, ...?


http://forum.dlang.org/post/nscscdomihmvqplxf...@forum.dlang.org


Generating Phobos Doc

2014-07-17 Thread Nordlöw

How do I generate the Phobos docs?

My try

make -f posix.mak html

fails as

make: *** No rule to make target 
`../web/phobos-prerelease/index.html', needed by `html'.  Stop.




Re: Generating Phobos Doc

2014-07-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 17, 2014 at 05:54:21PM +, Nordlöw via Digitalmars-d-learn 
wrote:
 How do I generate the Phobos docs?
 
 My try
 
 make -f posix.mak html
 
 fails as
 
 make: *** No rule to make target `../web/phobos-prerelease/index.html',
 needed by `html'.  Stop.

You need to checkout the dlang.org repository as well.

One way to do it is to have this directory structure:

/usr/src/d
/usr/src/d/dmd
/usr/src/d/druntime
/usr/src/d/phobos
/usr/src/d/dlang.org

First, build dmd, druntime, phobos without 'html' to get a working
toolchain, then cd to dlang.org and run `make -f posix.mak html`. This
creates:

/usr/src/d/dlang.org/web

Symlink this to:

/usr/src/d/web

Then go back to phobos and run `make -f posix.mak html`. Now it should
work.

(Incidentally, it looks like the expected directory structure is:

/usr/src/d
/usr/src/d/dlang.org
/usr/src/d/dlang.org/dmd
/usr/src/d/dlang.org/druntime
/usr/src/d/dlang.org/phobos

But I don't really like that because it requires embedding copies of git
repositories inside each other, which may cause strange git behaviour if
you don't know what you're doing.)


T

-- 
A one-question geek test. If you get the joke, you're a geek: Seen on a 
California license plate on a VW Beetle: 'FEATURE'... -- Joshua D. Wachs - 
Natural Intelligence, Inc.


Re: Extended math library

2014-07-17 Thread Martijn Pot via Digitalmars-d-learn

On Thursday, 17 July 2014 at 15:21:40 UTC, John Colvin wrote:

On Tuesday, 15 July 2014 at 20:46:32 UTC, Martijn Pot wrote:

To make a long story short:

Is there any math library with e.g. mean, std, polynomial 
fitting, ...?


http://forum.dlang.org/post/nscscdomihmvqplxf...@forum.dlang.org


Thanks John! You saved me a lot of time. I have actually checked 
if it runs this time and it works like a charm.




Re: teething troubles

2014-07-17 Thread Dean via Digitalmars-d-learn

On Thursday, 17 July 2014 at 11:08:16 UTC, Mike Parker wrote:

On 7/17/2014 7:01 PM, Dean wrote:



Not even sure if its a tango problem. Dmd doesn't seem to be
picking up the path that I specify with -I. Perhaps the 
mechanics

of module loading is not as simple as I imagine. I initially
thought its a permission problem, but that is not the case.


What does your tango source tree look like? Is it a) or b)?

a) /usr/include/dmd/tango/io/Stdout.d
b) /usr/include/dmd/tango/tango/io/Stdout.d

When you pass -I/usr/include/dmd/tango, then it needs to look 
like b). If it's a), then you should pass -I/usr/include/dmd. 
The reason is that 'tango' is the top-level package directory. 
Its *parent* directory needs to be on the import path.


Hi Mike,

  that was it. Thanks a lot.


Binary IO

2014-07-17 Thread seany via Digitalmars-d-learn

Hello,

What are the methods of unformatted binary IO in d? File.write 
seems to use formatted ASCII . I would like to write a binary 
file that I cna read in fortan. Similarly, I would like to write 
a file in Fortan, unformatted IO, and read it using D.


templates

2014-07-17 Thread ddos via Digitalmars-d-learn
for example and learning purpose i want to create an arithmetic 
vector class.


for a vector of arbitrary size i defined my opBinary like this:

class TVector(T,int n)
{
  T[n] val;
  .

  TVector opBinary(string op)(TVector rhs)
  {
auto tmp = 
zip(val[],rhs.val[]).map!(a[0]~op~a[1])().array;

T[n] v = tmp[];
return new TVector!(T,n)(v);
  }
}

now assume i do often need TVector!(T,4) in my program, and i 
want to optimize this implementation, is it possible to write a 
specialized implementation for methods of TVectors with the 
specific template parameters?


e.g.: (not working)

class TVector!(T,4)
{
  TVector4!(T) opBinary(string op)(TVector4!(T) rhs)
  {
static if (op == +)
{
  return new TVector4!T( [val[0]+rhs.val[0],
  val[1]+rhs.val[1],
  val[2]+rhs.val[2],
  val[3]+rhs.val[3]]);
}
else static assert(0, Operator ~op~ not implemented);
  }
}

one possible solution would be a static if, like this:

TVector opBinary(string op)(TVector rhs)
{
  static if(n == 4)
  {
// fast impl for n==4
  }
  else
  {
// old impl
  }
}

but i'd like to avoid this since it makes the code very ugly to 
read


any suggestions :) ?

thx for your help, greetings from vienna, austria :)


Re: Binary IO

2014-07-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 17, 2014 at 08:35:24PM +, seany via Digitalmars-d-learn wrote:
 Hello,
 
 What are the methods of unformatted binary IO in d? File.write seems
 to use formatted ASCII . I would like to write a binary file that I
 cna read in fortan. Similarly, I would like to write a file in Fortan,
 unformatted IO, and read it using D.

Use File.rawWrite:

auto f = File(myfile, w);
Data[] data = ... /* put data here */;
f.rawWrite(data);

Similarly, to read binary data, use File.rawRead:

auto f = File(myfile, r);
Data[] buf; /* buffer to store the data */
buf.length = /* number of data items to read */;
auto data = f.rawRead(buf);
/* data will be a slice of buf, with .length containing the
 * actual number of items read */

You can use ubyte[] if you have byte-based data to read/write, but
rawRead / rawWrite are flexible enough to take arrays of any type.


T

-- 
You are only young once, but you can stay immature indefinitely. -- azephrahel


Re: Binary IO

2014-07-17 Thread Justin Whear via Digitalmars-d-learn
On Thu, 17 Jul 2014 20:35:24 +, seany wrote:

 Hello,
 
 What are the methods of unformatted binary IO in d? File.write seems to
 use formatted ASCII . I would like to write a binary file that I cna
 read in fortan. Similarly, I would like to write a file in Fortan,
 unformatted IO, and read it using D.

You have a few options:
 * The old std.stream -- this module is due for replacement, hopefully 
ASAP.
 * Use File.rawRead/rawWrite.  These are intended for arrays, though they 
can be used to read single values.
 * Work with chunks of ubyte data and use std.bitmanip's read and write 
functions.

The last option is probably your best option for producing good future-
proof, idiomatic D code.


Re: Binary IO

2014-07-17 Thread seany via Digitalmars-d-learn

Data is a built in type? what includefile do I need?


Re: Binary IO

2014-07-17 Thread Justin Whear via Digitalmars-d-learn
On Thu, 17 Jul 2014 21:01:35 +, seany wrote:

 Data is a built in type? what includefile do I need?

No, just used as an example.  What sort of data are reading from the 
binary file?


Re: Extended math library

2014-07-17 Thread John Colvin via Digitalmars-d-learn

On Thursday, 17 July 2014 at 18:21:12 UTC, Martijn Pot wrote:

On Thursday, 17 July 2014 at 15:21:40 UTC, John Colvin wrote:

On Tuesday, 15 July 2014 at 20:46:32 UTC, Martijn Pot wrote:

To make a long story short:

Is there any math library with e.g. mean, std, polynomial 
fitting, ...?


http://forum.dlang.org/post/nscscdomihmvqplxf...@forum.dlang.org


Thanks John! You saved me a lot of time. I have actually 
checked if it runs this time and it works like a charm.


No problem, It made for a more entertaining few hours than the 
work I was supposed to be doing :)


Compile-Time Interfaces (Concepts)

2014-07-17 Thread Nordlöw

AFAIK there is no compile-time variant of interfaces right?

Why is that?

Wouldn't it be nice to say something like

struct SomeRange realize InputRange
{
/* implement members of InputRange */
}

and then the compiler will statically check that that all members 
are implemented correctly.


I guess this requires some new syntax to describe what an 
InputRange is.


Kind of like C++ Concepts.


Re: Compile-Time Interfaces (Concepts)

2014-07-17 Thread Justin Whear via Digitalmars-d-learn
On Thu, 17 Jul 2014 22:49:30 +, Nordlöw wrote:

 AFAIK there is no compile-time variant of interfaces right?
 
 Why is that?
 
 Wouldn't it be nice to say something like
 
  struct SomeRange realize InputRange {
  /* implement members of InputRange */
  }
 
 and then the compiler will statically check that that all members are
 implemented correctly.
 
 I guess this requires some new syntax to describe what an InputRange is.
 
 Kind of like C++ Concepts.

What benefits would accrue from adding this?  Static verification that a 
structure implements the specified concepts?  If so, you can simply do 
this instead:

static assert(isInputRange!SomeRange);


Re: Binary IO

2014-07-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 17, 2014 at 09:01:35PM +, seany via Digitalmars-d-learn wrote:
 Data is a built in type? what includefile do I need?

It can be any type you want, it was just an example.


T

-- 
Chance favours the prepared mind. -- Louis Pasteur


Re: Compile-Time Interfaces (Concepts)

2014-07-17 Thread Justin Whear via Digitalmars-d-learn
On Thu, 17 Jul 2014 23:06:30 +, bearophile wrote:

 Justin Whear:
 
 What benefits would accrue from adding this?  Static verification that
 a structure implements the specified concepts?
 
 Not just that, but also the other way around: static verification that a
 Concept is strictly sufficient for any instantiation of a specific
 template. This is what Haskell/Rust do.
 
 Bye,
 bearophile

By this do mean replacing the template constraint `if (isInputRange!R)` 
syntax?  If so, we need concept definition syntax, but we do not 
necessarily need a struct realizes concept syntax.  And, in fact, I 
would argue against it as a static assert would continue to be sufficient.


Re: Compile-Time Interfaces (Concepts)

2014-07-17 Thread bearophile via Digitalmars-d-learn

Justin Whear:

By this do mean replacing the template constraint `if 
(isInputRange!R)`

syntax?  If so, we need concept definition syntax, but we do not
necessarily need a struct realizes concept syntax.  And, in 
fact, I
would argue against it as a static assert would continue to be 
sufficient.


I was not suggesting to put Concepts (or typeclasses) in D (and 
Andrei is against this idea), I was just trying to explain the 
basic difference between template constraints and concepts :-)


Bye,
bearophile


Re: Compile-Time Interfaces (Concepts)

2014-07-17 Thread Dicebot via Digitalmars-d-learn

..and call it mixin interface :P