Re: cannot sort an array of char

2014-11-06 Thread Ivan Kazmenko via Digitalmars-d-learn

On Wednesday, 5 November 2014 at 13:34:05 UTC, Marc Schütz wrote:
On Wednesday, 5 November 2014 at 12:54:03 UTC, Ivan Kazmenko 
wrote:

Hi!

This gives an error (cannot deduce template function from 
argument types):


-
import std.algorithm;
void main () {
char [] c;
sort (c);
}
-

Why is char [] so special that it can't be sorted?

For example, if I know the array contains only ASCII 
characters, sorting it sounds no different to sorting an int 
[].


Hmm... this doesn't work either:

import std.algorithm;
import std.utf;
void main () {
char [] c;
sort (c.byCodeUnit);
}

But IMO it should.


So, you imply that to use a char array as a RandomAccessRange, I 
have to use byCodeUnit? (and it should work, but doesn't?)


Fine, but how does one learn that except by asking here?  
Googling did not produce meaningful results for me.


For example, isRandomAccessRange[0] states the problem:
-
Although char[] and wchar[] (as well as their qualified versions 
including string and wstring) are arrays, isRandomAccessRange 
yields false for them because they use variable-length encodings 
(UTF-8 and UTF-16 respectively). These types are bidirectional 
ranges only.

-
but does not offer a solution.  If (when) byCodeUnit does really 
provide a random-access range, it would be desirable to have it 
linked where the problem is stated.


[0] http://dlang.org/phobos/std_range.html#.isRandomAccessRange


Re: How to turn this C++ into D?

2014-11-06 Thread thedeemon via Digitalmars-d-learn

On Wednesday, 5 November 2014 at 17:45:00 UTC, luminousone wrote:

abstract class foo {
static DList!foo foo_list;
~this(){ foo_list.remove(this); }


One note: when your program exits the runtime does a final GC 
cycle and collects those things calling destructors/finalizers, 
however the static data can easily be already 
collected/destructed at this moment, so attempting to access it 
from object's finalizer will crash. One should not ever access 
any reference types and data outside the object itself from a 
destructor/finalizer.


Re: Share array element between threads

2014-11-06 Thread bearophile via Digitalmars-d-learn

Misu:


void main(string[] args)
{
class Account
{
public this(int id) { this.id = id; }
int id;
}
...


This is not an answer to your question, but note:

void main() {
class Foo {}
static class Bar {}
pragma(msg, __traits(classInstanceSize, Foo));
pragma(msg, __traits(classInstanceSize, Bar));
}

Output:

12u
8u

Bye,
bearophile


Re: Pragma mangle and D shared objects

2014-11-06 Thread Etienne Cimon via Digitalmars-d-learn

On 2014-10-26 14:25, Etienne Cimon wrote:

On 2014-10-25 23:31, H. S. Teoh via Digitalmars-d-learn wrote:

Hmm. You can probably use __traits(getAllMembers...) to introspect a
library module at compile-time and build a hash based on that, so that
it's completely automated. If you have this available as a mixin, you
could just mixin(exportLibrarySymbols()) in your module to produce the
hash.


Exactly, or I could also make it export specific functions into the
hashmap, a little like a router. It seems like a very decent option.




I found an elegant solution for dealing with dynamic libraries:

https://github.com/bitwise-github/D-Reflection



Re: Share array element between threads

2014-11-06 Thread via Digitalmars-d-learn

On Thursday, 6 November 2014 at 10:53:32 UTC, Misu wrote:

Hi,

when I execute this code I have 7 7 7 as result, I think I 
understand why.


How can I execute a special task for one element ?

import std.stdio;
import std.parallelism;

void main(string[] args)
{
class Account
{
public this(int id) { this.id = id; }
int id;
}

	Account[] accounts = [new Account(5), new Account(6), new 
Account(7)];


foreach(acc; accounts)
{
task(() { writeln(acc.id); }).executeInNewThread();
}

readln();
}


It's a bug: https://issues.dlang.org/show_bug.cgi?id=2043

As a workaround, you can nest the call in another lambda:

foreach(acc; accounts)
{
(Account acc) {
task(() { writeln(acc.id); }).executeInNewThread();
} (acc);
}


Network scanner

2014-11-06 Thread RuZzz via Digitalmars-d-learn
Hi ppl! I want to scan the local network to find nodes with open 
80 port.

code:
import core.thread, core.atomic;
import std.stdio, std.system, std.file, std.conv, std.datetime, 
std.socket, std.socketstream, std.stream;

import vibe.core.log;
import vibe.d;

void main()
{
ushort port = 80;
auto stIP =192.168.110.;
ushort startIP = 1;
uint size_buf;
for (ushort i = 1; i  150; i += size_buf)
{
auto socksGlobal = new SocketSet;
auto socks = new SocketSet;
size_buf = socksGlobal.max;
		writeln(start cycle , stIP, i, \t size socks max , 
size_buf);

ushort byteIP = i;
Socket [] ar_sock;
ar_sock.length = size_buf;
foreach (ref msa; ar_sock)
{
msa = new TcpSocket();
msa.blocking = false;
socksGlobal.add(msa);
auto addrr = stIP~to!string(byteIP);
byteIP++;

auto objAddr = new InternetAddress(addrr, port);
try
{
msa.connect(objAddr);
}
catch (SocketException e)
{
writeln(e.msg);
}
}
auto ipC = 0;
while(ipC  5)
{
ipC++;
int re = 0;
foreach (ref msa; ar_sock)
{
if (socksGlobal.isSet(msa))
socks.add(msa);
}
try
{
re = Socket.select(null, socks, null 
,dur!seconds(3));
}
catch (SocketException e)
{
writeln(e.msg);
}
st = Clock.currTime(UTC());
			writeln(st.toSimpleString~\t\t: select res : , re,  sock 
seln, socksGlobal.selectn);


foreach (ref msa; ar_sock)
{
if (socks.isSet(msa))
{
st = Clock.currTime(UTC());
auto addrr = 
to!string(msa.remoteAddress);
writeln(st.toSimpleString~\t\t: 
~addrr~ online);
socksGlobal.remove(msa);
}
//msa.close();
}
socks.reset();
}
foreach (ref msa; ar_sock)
{
msa.shutdown(SocketShutdown.BOTH);
msa.close();
}
socksGlobal.reset();
}
}

output:
start cycle 192.168.110.1size socks max 64
2014-Nov-06 12:51:59.46875Z : select res : 22 sock seln64
2014-Nov-06 12:51:59.46875Z : 192.168.110.6:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.9:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.10:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.11:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.12:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.14:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.15:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.16:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.17:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.18:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.19:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.20:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.21:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.22:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.23:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.24:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.26:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.27:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.28:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.29:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.30:80 online
2014-Nov-06 12:51:59.484375Z: 192.168.110.32:80 online
2014-Nov-06 12:52:00.0625Z  : select res : 1 sock seln42
2014-Nov-06 12:52:00.0625Z  : 192.168.110.35:80 online
2014-Nov-06 12:52:00.0625Z  : select res : 

Re: Network scanner

2014-11-06 Thread RuZzz via Digitalmars-d-learn

Or the program doesn't find the address after IP 192.168.110.34...


Re: cannot sort an array of char

2014-11-06 Thread via Digitalmars-d-learn

On Thursday, 6 November 2014 at 10:52:32 UTC, Ivan Kazmenko wrote:
On Wednesday, 5 November 2014 at 13:34:05 UTC, Marc Schütz 
wrote:
On Wednesday, 5 November 2014 at 12:54:03 UTC, Ivan Kazmenko 
wrote:

Hi!

This gives an error (cannot deduce template function from 
argument types):


-
import std.algorithm;
void main () {
char [] c;
sort (c);
}
-

Why is char [] so special that it can't be sorted?

For example, if I know the array contains only ASCII 
characters, sorting it sounds no different to sorting an int 
[].


Hmm... this doesn't work either:

   import std.algorithm;
   import std.utf;
   void main () {
   char [] c;
   sort (c.byCodeUnit);
   }

But IMO it should.


So, you imply that to use a char array as a RandomAccessRange, 
I have to use byCodeUnit? (and it should work, but doesn't?)




Yes. H.S. Teoh has already submitted a PR to fix it.

Fine, but how does one learn that except by asking here?  
Googling did not produce meaningful results for me.


For example, isRandomAccessRange[0] states the problem:
-
Although char[] and wchar[] (as well as their qualified 
versions including string and wstring) are arrays, 
isRandomAccessRange yields false for them because they use 
variable-length encodings (UTF-8 and UTF-16 respectively). 
These types are bidirectional ranges only.

-
but does not offer a solution.  If (when) byCodeUnit does 
really provide a random-access range, it would be desirable to 
have it linked where the problem is stated.


[0] http://dlang.org/phobos/std_range.html#.isRandomAccessRange


I agree. But how should it be implemented? We would have to 
modify algorithms that require an RA range to also accept char[], 
but then print an error message with the suggestion to use 
byCodeUnit. I think that's not practicable. Any better ideas?


Re: Complexity guaranties of array append operator

2014-11-06 Thread Steven Schveighoffer via Digitalmars-d-learn

On 11/5/14 10:48 PM, Dmitriy wrote:

Hello, I'm in the middle of learning D. I can't find any definitive
information about what is the complexity of operator ~= when used for
adding an element to an array. Is it amortized O(1) or is it
implementation defined? (I hope it at worst O(n) though I haven't seen
any information about that either).


It's amortized O(1).



Also documentation to std.array.Appender says that it is more
efficient to use Appender when appending many elements. Does it imply
that Appender.put has amortized O(1)?


As Jonathan said, it's because array append needs to look up information 
in the GC, which can be costly (we have mechanisms to mitigate this 
somewhat, but it can't be inlined). The Appender has all the information 
it needs handy, and can be inlined. The disadvantage is that the 
Appender may have higher up-front costs, and does not have some of the 
same properties as a builtin array.


You may find this article helpful: http://dlang.org/d-array-article.html

-Steve


Re: How to turn this C++ into D?

2014-11-06 Thread Steven Schveighoffer via Digitalmars-d-learn

On 11/5/14 2:05 PM, Patrick Jeeves wrote:

On Wednesday, 5 November 2014 at 18:56:08 UTC, luminousone wrote:

unless delete is explicitly called, I don't believe the destructor
would ever be called, it would still have a reference in the static
foo_list object that would stop it from being collected by the gc.


Allocate the list with stdc.malloc. It won't be tracked by the GC.

However, note that such accesses need to be synchronized, because the GC 
can run in any thread, and be sure that list is shared or __gshared.


Now, another problem with making it untracked by the GC, you need a list 
object with a custom allocator. Which I don't think we have yet, you'd 
likely have to invent this too.



This is exactly why I asked about it, and even if delete is explicitly
called-- which i believe is deprecated, wouldn't the runtime fill the
space with the default construtor until the GC decides to remove it?
meaning it would be immediatly added back into the list?


This was never the case. The runtime is guaranteed to call the 
destructor only once. In order to do this, when the object is finalized, 
it's vtable pointer is nulled. So it effectively becomes unusable. This 
is the same thing for destroy.


BTW, be very very careful with destructors. They should ONLY be used to 
manage NON-GC resources. In this example, if you C malloc the list, you 
can access it in the dtor.


-Steve


Re: cannot sort an array of char

2014-11-06 Thread Steven Schveighoffer via Digitalmars-d-learn

On 11/5/14 7:54 AM, Ivan Kazmenko wrote:

Hi!

This gives an error (cannot deduce template function from argument types):

-
import std.algorithm;
void main () {
 char [] c;
 sort (c);
}
-

Why is char [] so special that it can't be sorted?


Because sort works on ranges, and std.range has the view that char[] is 
a range of dchar without random access. Nevermind what the compiler 
thinks :)


I believe you can get what you want with std.string.representation:

import std.string;

sort(c.representation);

-Steve


Re: scope exception do not rise

2014-11-06 Thread Ali Çehreli via Digitalmars-d-learn

On 11/05/2014 11:02 PM, Suliman wrote:

Replace that with something like writeln(caught) and you will see
that it is indeed caught. :) Printing the exception mimicks the
default behavior and you (and I) think that the exception is not
caught. :)


that's work, but I can not understand where I can to look at exception
level. If I right understand every function have own exceptions. For
example std.file.
Where I could look at what e will get? I mean catch(Exception e).



We have to look at the documentation of the function. In this case the 
possibilities are FileException and UTFException.


  http://dlang.org/phobos/std_file.html#.readText

However, judging by their names, they are both descendants of Exception, 
so what you are doing will catch either of them.


Ali



transversal sum

2014-11-06 Thread Jack Applegame via Digitalmars-d-learn

I have rectangular forward range of forward ranges (not arrays):
[
  [a11, a12, ... a1N],
  [a21, a22, ... a2N],
  ...
  [aM1, aM2, ... aMN]
]

I need lazy forward range:
[
 a11 + a21 + ... aM1,
 a12 + a22 + ... aM2,
 ...
 a1N + a2N + ... aMN
]
Range of sum elements of every columns;

M, N - runtime values;

Is there a way to do this using only Phobos algorithms and range 
functions?


Re: scope exception do not rise

2014-11-06 Thread Suliman via Digitalmars-d-learn
We have to look at the documentation of the function. In this 
case the possibilities are FileException and UTFException.


  http://dlang.org/phobos/std_file.html#.readText

However, judging by their names, they are both descendants of 
Exception, so what you are doing will catch either of them.




Where I can look at hierarchy of exceptions?


Re: transversal sum

2014-11-06 Thread via Digitalmars-d-learn
On Thursday, 6 November 2014 at 15:53:27 UTC, Jack Applegame 
wrote:

I have rectangular forward range of forward ranges (not arrays):
[
  [a11, a12, ... a1N],
  [a21, a22, ... a2N],
  ...
  [aM1, aM2, ... aMN]
]

I need lazy forward range:
[
 a11 + a21 + ... aM1,
 a12 + a22 + ... aM2,
 ...
 a1N + a2N + ... aMN
]
Range of sum elements of every columns;

M, N - runtime values;

Is there a way to do this using only Phobos algorithms and 
range functions?


Untested:

import std.algorithm: map, sum;
auto rangeOfSums = rectangularRange.map!(r = r.sum);


Re: transversal sum

2014-11-06 Thread Justin Whear via Digitalmars-d-learn
On Thu, 06 Nov 2014 16:57:48 +, Marc Schütz wrote:

 On Thursday, 6 November 2014 at 15:53:27 UTC, Jack Applegame wrote:
 I have rectangular forward range of forward ranges (not arrays):
 [
   [a11, a12, ... a1N],
   [a21, a22, ... a2N],
   ...
   [aM1, aM2, ... aMN]
 ]

 I need lazy forward range:
 [
  a11 + a21 + ... aM1,
  a12 + a22 + ... aM2,
  ...
  a1N + a2N + ... aMN
 ]
 Range of sum elements of every columns;

 M, N - runtime values;

 Is there a way to do this using only Phobos algorithms and range
 functions?
 
 Untested:
 
  import std.algorithm: map, sum;
  auto rangeOfSums = rectangularRange.map!(r = r.sum);

This would sum along the wrong dimension.  I think the correct solution 
will
make use of std.range.frontTraversal, but it will be a bit more complex 
due to
needing to sum every column.  std.range.traversal would make it easy, but 
it
requires random access.


Re: transversal sum

2014-11-06 Thread Justin Whear via Digitalmars-d-learn
On Thu, 06 Nov 2014 17:08:23 +, Justin Whear wrote:

 I think the correct solution
 will make use of std.range.frontTraversal, but it will be a bit more
 complex due to needing to sum every column.  std.range.traversal would
 make it easy, but it requires random access.

That should be std.range.frontTransversal and transversal.


Re: transversal sum

2014-11-06 Thread via Digitalmars-d-learn

On Thursday, 6 November 2014 at 16:57:50 UTC, Marc Schütz wrote:
On Thursday, 6 November 2014 at 15:53:27 UTC, Jack Applegame 
wrote:
I have rectangular forward range of forward ranges (not 
arrays):

[
 [a11, a12, ... a1N],
 [a21, a22, ... a2N],
 ...
 [aM1, aM2, ... aMN]
]

I need lazy forward range:
[
a11 + a21 + ... aM1,
a12 + a22 + ... aM2,
...
a1N + a2N + ... aMN
]
Range of sum elements of every columns;

M, N - runtime values;

Is there a way to do this using only Phobos algorithms and 
range functions?


Untested:

import std.algorithm: map, sum;
auto rangeOfSums = rectangularRange.map!(r = r.sum);


Sorry, I see you want columns...

I thought about std.range.frontTransversal, but it only returns a 
range of values, not a range of ranges. That's... unhelpful :-(


Re: transversal sum

2014-11-06 Thread via Digitalmars-d-learn

On Thursday, 6 November 2014 at 17:08:23 UTC, Justin Whear wrote:
This would sum along the wrong dimension.  I think the correct 
solution

will
make use of std.range.frontTraversal, but it will be a bit more 
complex

due to
needing to sum every column.  std.range.traversal would make it 
easy, but

it
requires random access.


Yeah, I posted to soon. Was surprised that the solution would be 
so easy :-P


We'd need something taking and returning a RoR that mirrors 
them diagonally. Then we could simply apply `map!(r = r.sum)` on 
the result.


Re: Access Violation Tracking

2014-11-06 Thread Andrej Mitrovic via Digitalmars-d-learn
On Nov 5, 2014 12:10 PM, Bauss via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com wrote:

 Is there any way to track down access violations, instead of me having to
look through my source code manually.

Whenever you don't get a stack trace on Windows, it's 99% guaranteed you're
calling a null function pointer.


 I have a pretty big source code and an access violation happens at
runtime, but it's going to be a nightmare looking through it all to find
the access violation. Not to mention all the tests I have to run.

 So if there is a way to catch an access violation and find out where it
occured it would be appreciated!


Re: transversal sum

2014-11-06 Thread Artur Skawina via Digitalmars-d-learn
On 11/06/14 18:32, bearophile via Digitalmars-d-learn wrote:
 Marc Schütz:
 
 We'd need something taking and returning a RoR that mirrors them 
 diagonally. Then we could simply apply `map!(r = r.sum)` on the result.
 
 A simple solution is to create a row of values, and then sum them correctly 
 while you scan the rows.

The simplest solution is probably something like:

   auto transversal_sum(FR)(FR rr) {
  static struct TS {
 FR rr;
 bool empty() @property const { return rr.front.empty; }
 auto front() @property {
import std.algorithm;
return reduce!((a, b)=a+b.front)(rr.front.front.init, rr);
 }
 void popFront() { foreach (ref r; rr) r.popFront(); }
  }
  return TS(rr);
   }

but I think OP wanted a ready-made phobos solution, w/o all the
range boilerplate...

artur


Why does this declaration exist inside std.range.put?

2014-11-06 Thread Meta via Digitalmars-d-learn

This is the code for std.range.put:

void put(R, E)(ref R r, E e)
{
//Why?
@property ref E[] EArrayInit(); //@@@9186@@@: Can't use 
(E[]).init


//First level: simply straight up put.
static if (is(typeof(doPut(r, e
{
doPut(r, e);
}
//Optional optimization block for straight up array to array 
copy.
else static if (isDynamicArray!R  !isNarrowString!R  
isDynamicArray!E  is(typeof(r[] = e[])))

{
immutable len = e.length;
r[0 .. len] = e[];
r = r[len .. $];
}
//Accepts E[] ?
else static if (is(typeof(doPut(r, [e])))  
!isDynamicArray!R)

{
if (__ctfe)
doPut(r, [e]);
else
doPut(r, (e)[0..1]);
}
//special case for char to string.
else static if (isSomeChar!E  is(typeof(putChar(r, e
{
putChar(r, e);
}
//Extract each element from the range
//We can use put here, so we can recursively test a RoR of 
E.

else static if (isInputRange!E  is(typeof(put(r, e.front
{
//Special optimization: If E is a narrow string, and r 
accepts characters no-wider than the string's

//Then simply feed the characters 1 by 1.
static if (isNarrowString!E  (
(is(E : const  char[])  is(typeof(doPut(r,  
char.max)))  !is(typeof(doPut(r, dchar.max)))  
!is(typeof(doPut(r, wchar.max ||
(is(E : const wchar[])  is(typeof(doPut(r, 
wchar.max)))  !is(typeof(doPut(r, dchar.max ) )

{
foreach(c; e)
doPut(r, c);
}
else
{
for (; !e.empty; e.popFront())
put(r, e.front);
}
}
else
{
import std.string;
static assert (false, format(Cannot put a %s into a 
%s., E.stringof, R.stringof));

}
}

What is the reason for that first function declaration, 
EArrayInit? It's not referenced anywhere else in the function, 
and it doesn't even have a body.


Re: transversal sum

2014-11-06 Thread Jack Applegame via Digitalmars-d-learn

void popFront() { foreach (ref r; rr) r.popFront(); }

I think it should be
void popFront() { foreach (ref r; rr.save) r.popFront(); }


but I think OP wanted a ready-made phobos solution, w/o all the
range boilerplate...

exactly.


Re: Why does this declaration exist inside std.range.put?

2014-11-06 Thread Steven Schveighoffer via Digitalmars-d-learn

On 11/6/14 4:19 PM, Meta wrote:

This is the code for std.range.put:

void put(R, E)(ref R r, E e)
{
 //Why?
 @property ref E[] EArrayInit(); //@@@9186@@@: Can't use (E[]).init

 //First level: simply straight up put.
 static if (is(typeof(doPut(r, e
 {
 doPut(r, e);
 }
 //Optional optimization block for straight up array to array copy.
 else static if (isDynamicArray!R  !isNarrowString!R 
isDynamicArray!E  is(typeof(r[] = e[])))
 {
 immutable len = e.length;
 r[0 .. len] = e[];
 r = r[len .. $];
 }
 //Accepts E[] ?
 else static if (is(typeof(doPut(r, [e])))  !isDynamicArray!R)
 {
 if (__ctfe)
 doPut(r, [e]);
 else
 doPut(r, (e)[0..1]);
 }
 //special case for char to string.
 else static if (isSomeChar!E  is(typeof(putChar(r, e
 {
 putChar(r, e);
 }
 //Extract each element from the range
 //We can use put here, so we can recursively test a RoR of E.
 else static if (isInputRange!E  is(typeof(put(r, e.front
 {
 //Special optimization: If E is a narrow string, and r accepts
characters no-wider than the string's
 //Then simply feed the characters 1 by 1.
 static if (isNarrowString!E  (
 (is(E : const  char[])  is(typeof(doPut(r, char.max))) 
!is(typeof(doPut(r, dchar.max)))  !is(typeof(doPut(r, wchar.max ||
 (is(E : const wchar[])  is(typeof(doPut(r, wchar.max)))
 !is(typeof(doPut(r, dchar.max ) )
 {
 foreach(c; e)
 doPut(r, c);
 }
 else
 {
 for (; !e.empty; e.popFront())
 put(r, e.front);
 }
 }
 else
 {
 import std.string;
 static assert (false, format(Cannot put a %s into a %s.,
E.stringof, R.stringof));
 }
}

What is the reason for that first function declaration, EArrayInit? It's
not referenced anywhere else in the function, and it doesn't even have a
body.


github blame is quite useful: 
https://github.com/D-Programming-Language/phobos/blame/master/std/range.d#L668


The commit: 
https://github.com/D-Programming-Language/phobos/commit/c717b503e7305a92410c23ca2bc2ea14b40f8aa2


It apparently was used when it was added, but is no longer used. Here is 
the commit that removed the use:


https://github.com/D-Programming-Language/phobos/commit/87c71e6e14c3e9365a2cbf10105d7e6854824275

I think it can be safely removed.

-Steve


Re: transversal sum

2014-11-06 Thread John Colvin via Digitalmars-d-learn
On Thursday, 6 November 2014 at 15:53:27 UTC, Jack Applegame 
wrote:

I have rectangular forward range of forward ranges (not arrays):
[
  [a11, a12, ... a1N],
  [a21, a22, ... a2N],
  ...
  [aM1, aM2, ... aMN]
]

I need lazy forward range:
[
 a11 + a21 + ... aM1,
 a12 + a22 + ... aM2,
 ...
 a1N + a2N + ... aMN
]
Range of sum elements of every columns;

M, N - runtime values;

Is there a way to do this using only Phobos algorithms and 
range functions?


Can I get random access in one or both dimensions?


Re: Why does this declaration exist inside std.range.put?

2014-11-06 Thread Meta via Digitalmars-d-learn
On Thursday, 6 November 2014 at 21:57:36 UTC, Steven 
Schveighoffer wrote:
github blame is quite useful: 
https://github.com/D-Programming-Language/phobos/blame/master/std/range.d#L668


The commit: 
https://github.com/D-Programming-Language/phobos/commit/c717b503e7305a92410c23ca2bc2ea14b40f8aa2


It apparently was used when it was added, but is no longer 
used. Here is the commit that removed the use:


https://github.com/D-Programming-Language/phobos/commit/87c71e6e14c3e9365a2cbf10105d7e6854824275

I think it can be safely removed.

-Steve


Great, thanks for the info.


Re: transversal sum

2014-11-06 Thread John Colvin via Digitalmars-d-learn
On Thursday, 6 November 2014 at 15:53:27 UTC, Jack Applegame 
wrote:

I have rectangular forward range of forward ranges (not arrays):
[
  [a11, a12, ... a1N],
  [a21, a22, ... a2N],
  ...
  [aM1, aM2, ... aMN]
]

I need lazy forward range:
[
 a11 + a21 + ... aM1,
 a12 + a22 + ... aM2,
 ...
 a1N + a2N + ... aMN
]
Range of sum elements of every columns;

M, N - runtime values;

Is there a way to do this using only Phobos algorithms and 
range functions?


nasty inefficient solution, but might be ok if your ranges have 
cheap popFront:



import std.algorithm, std.range, std.stdio, std.array;

void main()
{
auto M = 3;
auto N = 10;

//generate a RangeOfRanges for testing
auto ror = iota(1, M+1)
   .map!(l = iota(N)
  .map!(e = e * l^^2));

auto rorFlat = ror.joiner;
iota(N)
.map!(i = rorFlat.save.drop(i).stride(N))
.map!sum.writeln;
}


Re: transversal sum

2014-11-06 Thread John Colvin via Digitalmars-d-learn

On Thursday, 6 November 2014 at 22:02:09 UTC, John Colvin wrote:
On Thursday, 6 November 2014 at 15:53:27 UTC, Jack Applegame 
wrote:
I have rectangular forward range of forward ranges (not 
arrays):

[
 [a11, a12, ... a1N],
 [a21, a22, ... a2N],
 ...
 [aM1, aM2, ... aMN]
]

I need lazy forward range:
[
a11 + a21 + ... aM1,
a12 + a22 + ... aM2,
...
a1N + a2N + ... aMN
]
Range of sum elements of every columns;

M, N - runtime values;

Is there a way to do this using only Phobos algorithms and 
range functions?


Can I get random access in one or both dimensions?


with random access along N:

iota(N).map!((i) = ror.transversal(i).sum())


Re: transversal sum

2014-11-06 Thread John Colvin via Digitalmars-d-learn
On Thursday, 6 November 2014 at 15:53:27 UTC, Jack Applegame 
wrote:

I have rectangular forward range of forward ranges (not arrays):
[
  [a11, a12, ... a1N],
  [a21, a22, ... a2N],
  ...
  [aM1, aM2, ... aMN]
]

I need lazy forward range:
[
 a11 + a21 + ... aM1,
 a12 + a22 + ... aM2,
 ...
 a1N + a2N + ... aMN
]
Range of sum elements of every columns;

M, N - runtime values;

Is there a way to do this using only Phobos algorithms and 
range functions?


this should be a textbook case for std.range.transposed, but I 
can't seem to get it to work.


How to tell how an object/class is declared

2014-11-06 Thread Meta via Digitalmars-d-learn

Say I have the following struct and object definitions:

struct Test1(T)
{
static if (???)
{
void doSomething()
{
writeln(typeof(this).stringof);
}
}

T t;
}

class Test2(T)
{
static if (???)
{
void doSomething()
{
writeln(typeof(this).stringof);
}
}

T t;
}

const(Test1!int) t1i;
shared(Test2!int) t2s;

How can I tell at the points marked in the above code if the 
class or struct instance was declared as const, shared, etc.? Is 
this possible?


Re: How to tell how an object/class is declared

2014-11-06 Thread Adam D. Ruppe via Digitalmars-d-learn

On Thursday, 6 November 2014 at 23:43:19 UTC, Meta wrote:
How can I tell at the points marked in the above code if the 
class or struct instance was declared as const, shared, etc.? 
Is this possible?


You can't do that, but you can overload on const

void doSomething() const { called on const instance }
void doSomething() { called on mutable }


Re: How to tell how an object/class is declared

2014-11-06 Thread Meta via Digitalmars-d-learn
One other thing. I know about `template this`, but I'm not sure 
if that's a tenable solution or not in my case. In addition to 
templating the struct or class, would I not also have to template 
the constructor so it could pick up the type of `this` at the 
declaration site?




Audio file read/write?

2014-11-06 Thread Daren Scot Wilson via Digitalmars-d-learn

What's the current recommended way to read and write audio files?

I don't need to play it on the speakers or deal with anything 
real time - just read a file's data into an array, fiddle with 
it, and write it out to a file.


I found some other threads about audio files, but none recent, 
mentioning SDL and OpenAL.  Are these still the way to go?I'm 
thinking I should avoid SDL since it does far more than audio, 
none of which I care about.  OpenAL also does way more than I 
care about, but at least is just audio.


For my application, I need to read a few of the common formats, 
such as .wav, .au, .mp3, .ogg and whatever else is popular.  I 
only need to write .wav but other audio tinkerers may want to 
write other formats.


Re: Access Violation Tracking

2014-11-06 Thread ketmar via Digitalmars-d-learn
On Thu, 06 Nov 2014 20:13:02 +
Nordlöw via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

 On Wednesday, 5 November 2014 at 11:39:21 UTC, Marc Schütz wrote:
  If you're on Linux, you can turn SEGVs into Errors:
 
  import etc.linux.memoryerror;
  registerMemoryErrorHandler();
 
 Why isn't such a useful feature activated by default? Performance 
 reasons?
'cause it's not really that useful. uncaught (by the proper checks)
segmentation fault is the serious bug, program must crach and spit out
postmortem dump. without interceptions crach point (which is written
into the dump too) will be right at the place where it shots it's foot.
and with signal handler installed... who knows?

crash+coredump is alot more useful than intercepting error and...
trying to recover from undefined state? or just exit to OS, losing
valuable information about a crash?


signature.asc
Description: PGP signature


Re: Intended behavior or bug (private vs public static)

2014-11-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, November 07, 2014 05:43:28 Andre via Digitalmars-d-learn wrote:
 Hi,

 following code fails with errors:
 class test.A member b is not accessible

 I am not sure, whether it should work or not?

 Kind regards
 André

 module app;
 import test;

 void main()
 {
   A.b();
 }

 module test;

 class A
 {
   private void b(){}
   static void b(string b){}
 }

That looks like a bug. All you have to do is change the order of the two
function declarations or rename the non-static one to something else, and it
compiles. So, somehow, the fact that the non-static one has the same name as
the static one and the fact that it comes first screws up accessing the
static one. And explicitly marking the static one as public doesn't help.
So, you should report is a compiler bug:

https://issues.dlang.org

- Jonathan M Davis