How to implement immutable ring buffer?

2015-05-27 Thread drug via Digitalmars-d-learn

Could somebody share his thoughts on the subject?
Would it be efficient? Is it possible to avoid memory copying to provide 
immutability? To avoid cache missing ring buffer should be like array, 
not list, so it's possible that the whole buffer should be moved. Is it 
neccessary to be real immutable, may be some form of fake immutabitiy is 
enough?
I'd like to try immutability in my app, and ring buffer is what I don't 
know how to use in the realm of immutability.


Thanks


Re: problem with gc?

2015-05-27 Thread Anonymouse via Digitalmars-d-learn

On Wednesday, 27 May 2015 at 08:42:01 UTC, zhmt wrote:
When I enable the --profle, get something like this, it doesnt 
give me too much help:

[...]


Tried callgrind and kcachegrind? If nothing else it's better at 
illustrating the same output, assuming you have graphviz/dot 
installed.


Given --dump-instr you can also get instruction-level profiling 
if you're really wondering what's happening.


Re: problem with gc?

2015-05-27 Thread zhmt via Digitalmars-d-learn

On Wednesday, 27 May 2015 at 09:39:42 UTC, Anonymouse wrote:

On Wednesday, 27 May 2015 at 08:42:01 UTC, zhmt wrote:
When I enable the --profle, get something like this, it doesnt 
give me too much help:

[...]


Tried callgrind and kcachegrind? If nothing else it's better at 
illustrating the same output, assuming you have graphviz/dot 
installed.


Given --dump-instr you can also get instruction-level profiling 
if you're really wondering what's happening.


@Anonymouse

Thank u very much, I have tried this:

 valgrind  --tool=callgrind ./gamelibdtest

callgrind_annotate callgrind.out.29234


 Ir  file:function

124,918,002  ???:_D9invariant12_d_invariantFC6ObjectZv 
[/mnt/hgfs/mydoc/dworkspace/bin/gamelibdtest]
 27,235,809  ???:_D2gc2gc2GC6mallocMFNbmkPmxC8TypeInfoZPv 
[/mnt/hgfs/mydoc/dworkspace/bin/gamelibdtest]
 22,484,758  
/mnt/hgfs/mydoc/dworkspace/gamelibdtest//usr/include/dmd/phobos/std/format.d:_D3std6format74__T14formatUnsignedTS3std6format16__T7sformatTaTiZ7sformatFAaxAaiZ4SinkTaZ14formatUnsignedFNaNfS3std6format16__T7sformatTaTiZ7sformatFAaxAaiZ4SinkmKS3std6format18__T10FormatSpecTaZ10FormatSpeckbZv 
[/mnt/hgfs/mydoc/dworkspace/bin/gamelibdtest]
 19,171,341  ???:_D2gc2gc3Gcx10smallAllocMFNbhKmkZPv 
[/mnt/hgfs/mydoc/dworkspace/bin/gamelibdtest]
 16,334,730  ???:pthread_mutex_lock 
[/usr/lib64/libpthread-2.17.so]
 14,519,760  ???:pthread_mutex_unlock 
[/usr/lib64/libpthread-2.17.so]
 14,503,272  
/mnt/hgfs/mydoc/dworkspace/gamelibdtest/../gamelibd/source/gamelibd/net/linux/epollapi.d:_D8gamelibd3net5linux8epollapi8bitExistFiiZb 
[/mnt/hgfs/mydoc/dworkspace/bin/gamelibdtest]
 13,521,278  
/mnt/hgfs/mydoc/dworkspace/gamelibdtest/../gamelibd/source/gamelibd/net/linux/TcpLinuxConn.d:_D8gamelibd3net5linux12TcpLinuxConn12TcpLinuxConn8readSomeMFAhZi'2 
[/mnt/hgfs/mydoc/dworkspace/bin/gamelibdtest]
 12,695,373  ???:_D2gc2gc3Gcx10smallAllocMFNbhKmkZ8tryAllocMFNbZb 
[/mnt/hgfs/mydoc/dworkspace/bin/gamelibdtest]
 12,558,147  
/mnt/hgfs/mydoc/dworkspace/gamelibdtest/../gamelibd/source/gamelibd/net/linux/linuxconn.d:_D8gamelibd3net5linux9linuxconn11handleEventFAS8gamelibd3net5linux8epollapi11epoll_eventZv 
[/mnt/hgfs/mydoc/dworkspace/bin/gamelibdtest]
 12,091,173  
???:_D4core6thread5Fiber39__T4callVE4core6thread5Fiber7Rethrowi1Z4callMFZC6object9Throwable 
[/mnt/hgfs/mydoc/dworkspace/bin/gamelibdtest]
 11,153,058  
/mnt/hgfs/mydoc/dworkspace/gamelibdtest//usr/include/dmd/phobos/std/format.d:_D3std6format18__T10FormatSpecTaZ10FormatSpec75__T17writeUpToNextSpecTS3std6format16__T7sformatTaTiZ7sformatFAaxAaiZ4SinkZ17writeUpToNextSpecMFNaNfS3std6format16__T7sformatTaTiZ7sformatFAaxAaiZ4SinkZb 
[/mnt/hgfs/mydoc/dworkspace/bin/gamelibdtest]
 10,877,409  
/mnt/hgfs/mydoc/dworkspace/gamelibdtest/../gamelibd/source/gamelibd/net/linux/epollapi.d:_D8gamelibd3net5linux8epollapi8changeEvFiiPviZv 
[/mnt/hgfs/mydoc/dworkspace/bin/gamelibdtest]
 10,676,006  
/mnt/hgfs/mydoc/dworkspace/gamelibdtest/../gamelibd/source/gamelibd/net/linux/TcpLinuxConn.d:_D8gamelibd3net5linux12TcpLinuxConn12TcpLinuxConn9writeSomeMFAhZi 
[/mnt/hgfs/mydoc/dworkspace/bin/gamelibdtest]
 10,279,096  ???:pthread_getspecific 
[/usr/lib64/libpthread-2.17.so]

  9,741,852  ???:__GI_memset [/usr/lib64/libc-2.17.so]
  9,645,888  ???:_d_arraycopy 
[/mnt/hgfs/mydoc/dworkspace/bin/gamelibdtest]
  9,430,244  ???:_D2gc2gc3Gcx5sweepMFNbZm 
[/mnt/hgfs/mydoc/dworkspace/bin/gamelibdtest]
  8,866,869  
???:_D4core6atomic50__T11atomicStoreVE4core6atomic11MemoryOrderi0TbTbZ11atomicStoreFNaNbNiKObbZv 
[/mnt/hgfs/mydoc/dworkspace/bin/gamelibdtest]
  8,661,662  
/mnt/hgfs/mydoc/dworkspace/gamelibdtest/../gamelibd/source/gamelibd/net/linux/TcpLinuxConn.d:_D8gamelibd3net5linux12TcpLinuxConn12TcpLinuxConn5writeMFAhZi 
[/mnt/hgfs/mydoc/dworkspace/bin/gamelibdtest]


Re: Expanding asm.dlang.org

2015-05-27 Thread Vladimir Panteleev via Digitalmars-d

On Monday, 25 May 2015 at 16:45:26 UTC, Andrei Alexandrescu wrote:

On 5/25/15 7:36 AM, Iain Buclaw via Digitalmars-d wrote:

I can add any cross compilers hosted on gdcproject.org
http://gdcproject.org. You'd need to go through Godbolt to
get it on
his host. asm.dlang.org http://asm.dlang.org is a no go
because it has
been tailored for dmd only.


The right answer is to tailor asm.dlang.org for everything. -- 
Andrei


We also have http://dpaste.dzfl.pl/ (which has GDC, LDC, and 
actually runs the code).


Re: Expanding asm.dlang.org

2015-05-27 Thread Iain Buclaw via Digitalmars-d
On 27 May 2015 13:25, Mike via Digitalmars-d digitalmars-d@puremagic.com
wrote:


 I've updated explore.dgnu.org with gdc-4.9, along with ARM and ARMHF
 variants.  ARM supports -mthumb code generation. http://goo.gl/NmdnU1

 Iain


 I added a few platform flags and compared the output with my
cross-compiler.  They look identical.  This is great! Thanks!

Awesome, thanks for clarifying.


Re: DMD Symbol Reference Analysis Pass

2015-05-27 Thread via Digitalmars-d

On Wednesday, 27 May 2015 at 08:38:48 UTC, Per Nordlöw wrote:
AFAIK, in current DMD, I can't get any help in avoiding 
patterns such as


char[] saved_line;
foreach (line; File(foo.txt).byLine)
{
saved_line = line; // should give error
}


If I understand you correctly, a new kind of qualifier for `line` 
may be motivated here. The semantic meaning of `scope` D is not 
related to volatile property. I guess the problem is somewhat 
related to reference counting and ownership, right.


Re: problem with gc?

2015-05-27 Thread zhmt via Digitalmars-d-learn
When I enable the --profle, get something like this, it doesnt 
give me too much help:


 Timer Is 3579545 Ticks/Sec, Times are in Microsecs 



  Num  TreeFuncPer
  CallsTimeTimeCall

1298756  4996649885  49875773773840 int 
gamelibd.net.linux.TcpLinuxConn.TcpLinuxConn.writeSome(ubyte[])
30358909 14353678347  4433441425 146 void 
gamelibd.net.linux.linuxconn.selectAndProcessNetEvents(ulong)
30359249  1670090296  1582462941  52 long 
gamelibd.util.utcNow()
1298744   874889280   858583339 661 
_D8gamelibd3net5linux12TcpLinuxConn12TcpLinuxConn8readSomeMFAhZ9__lambda2MFZv
1300549   25997   803742026 618 int 
gamelibd.net.linux.TcpLinuxConn.TcpLinuxConn.readSome(ubyte[])
2597506   756203332   702092233 270 void 
gamelibd.net.linux.epollapi.changeEv(int, int, void*, int)
30358909  9920075665   285890739   9 void 
gamelibd.net.linux.linuxconn.handleEvent(gamelibd.net.linux.epollapi.epoll_event[])
1298744  5131800498   244989946 188 void 
gamelibd.net.linux.TcpLinuxConn.TcpLinuxConn.doRead(gamelibd.net.linux.epollapi.epoll_event*)
1298768   0   223952199 172 void 
gamelibd.net.linux.IoEventHandler.IoEventHandler.autoReaderFiberSetting(void 
delegate())
1298756  5207337081   210684924 162 int 
gamelibd.net.linux.TcpLinuxConn.TcpLinuxConn.write(ubyte[])
30358953   162443804   162443804   5 @property bool 
gamelibd.util.LinkedList!(gamelibd.net.exceptionsafefiber.ExceptionSafeFiber).LinkedList.isEmpty()
 648485   989705094   139972636 215 int 
gamelibd.net.linux.TcpLinuxConn.TcpLinuxConn.read(ubyte[])
1298919  1008643391   124807374  96 void 
gamelibd.net.exceptionsafefiber.ExceptionSafeFiber.resume()
303590728843187288431872   2 pure nothrow 
@nogc @safe gamelibd.net.exceptionsafefiber.TimerTask 
std.container.rbtree.__T12RedBlackTreeTC8gamelibd3net18exceptionsafefiber9TimerTaskVAyaa25_612e737461727454696d65203c20622e737461727454696d65Vbi1Z.RedBlackTree.front()
1298750  157489732887384898  67 void 
gamelibd.net.linux.IoEventHandler.IoEventHandler.tryResumeReaderFiber()
303590727732591577325915   2 pure nothrow 
@property @nogc @safe ulong 
std.container.rbtree.__T12RedBlackTreeTC8gamelibd3net18exceptionsafefiber9TimerTaskVAyaa25_612e737461727454696d65203c20622e737461727454696d65Vbi1Z.RedBlackTree.length()
45448316156034761560347  13 pure @safe bool 
std.exception.enforce!(bool).enforce(bool, lazy object.Throwable)
25975005190564251905642  19 void 
gamelibd.net.linux.TcpLinuxConn.TcpLinuxConn.throwExceptionIfErrAfterOp(long)
12989514939205649392056  38 
gamelibd.net.exceptionsafefiber.ExceptionSafeFiber 
gamelibd.net.exceptionsafefiber.ExceptionSafeFiber.getThis()
25975188087718146297298  17 
gamelibd.mem.Ptr!(gamelibd.net.provider.Conn).Ptr.getinout(ref 
@property inout(gamelibd.net.provider.Conn) function())
25976935172573037629038  14 
gamelibd.mem.Ptr!(gamelibd.net.exceptionsafefiber.ExceptionSafeFiber).Ptr.getinout(ref 
@property 
inout(gamelibd.net.exceptionsafefiber.ExceptionSafeFiber) 
function())
1298756   47994165534717468  26 void 
gamelibd.net.linux.IoEventHandler.IoEventHandler.enableRead()


DConf 2015 Livestreaming?

2015-05-27 Thread via Digitalmars-d

Isn't there any live-streaming of DConf this year?


Re: DMD Symbol Reference Analysis Pass

2015-05-27 Thread via Digitalmars-d

On Wednesday, 27 May 2015 at 10:53:48 UTC, Per Nordlöw wrote:

On Wednesday, 27 May 2015 at 09:54:33 UTC, Marc Schütz wrote:
Yes. First of all, `File.byLine.front` is the function that 
needs to get annotated, like this:


   char[] front() return {
   // ...
   return buffer;
   }

The `return` keyword here means the same thing as in DIP25,


Is this supportd in 2.067 with -dip25 flag?

If so shouldn't we qualify `File.byLine.front` with return when 
DIP-25 becomes stable?


I qualified `front` with `return` here

https://github.com/nordlow/justd/blob/master/bylinefast.d#L84

but compiling this with DMD 2.067 along with flag -dip25 doesn't 
complain about


https://github.com/nordlow/justd/blob/master/bylinefast.d#L188

Did you mean that this too is a planned feature?


Re: DIP78 - macros without syntax extensions

2015-05-27 Thread Kagamin via Digitalmars-d

On Tuesday, 26 May 2015 at 23:47:41 UTC, Dennis Ritchie wrote:
If this proposal is considered, it is required to propose to 
look

at the implementation of macros in Nemerle. Many believe that it
is in Nemerle macros implemented the most successful compared to
other modern languages. Of course, the most successful macros 
are

implemented in Lisp, but the syntax of the language is poor :)


The problem with declarative macro system is that you would need 
to learn yet another language. Possibly turing-complete. And a 
declarative turing-complete language is an overkill both for 
usage and implementation. Imperative macros get it done in an 
intuitive way in the existing language.


Re: DConf 2015 Livestreaming?

2015-05-27 Thread Liam McSherry via Digitalmars-d

On Wednesday, 27 May 2015 at 10:20:04 UTC, Per Nordlöw wrote:

Isn't there any live-streaming of DConf this year?


Unfortunately, there doesn't seem to be any streaming this year: 
http://forum.dlang.org/thread/zpwxvgiaigdbweach...@forum.dlang.org


Re: How to implement immutable ring buffer?

2015-05-27 Thread drug via Digitalmars-d-learn

On 27.05.2015 11:04, thedeemon wrote:

This whole idea sounds self-contradictory.
Ring buffer is a mutable-array-based implementation of something, for
example of a queue. You can ask about immutable implementations of a
queue, but that would be another question, not involving a ring buffer.

What do you want to do with this buffer, what do you need it for?
In general I need to have the last n instances of some objects queue. 
Now it implemented using ring buffer. Probably, you're right about 
immutable queue, it is more suitable definition here.


Re: DMD Symbol Reference Analysis Pass

2015-05-27 Thread via Digitalmars-d

On Tuesday, 26 May 2015 at 21:22:38 UTC, Per Nordlöw wrote:
No, DMD cannot currently handle scope on foreach elements. It 
errors as


 Error: basic type expected, not scope



Quite possible, didn't test it. Anyway, my point was that it 
simply isn't necessary to ever mark a local variable as `scope`. 
The compiler sees all local variables and can figure things out 
by itself. It only needs help in function signatures, in the form 
of explicit `scope` and `return` annotations.


example, it would figure out that you're assigning a reference 
to a value with shorter lifetime (i.e. the slice to the 
buffer) to a value with longer lifetime (saved_line), which it 
would disallow. (Btw, I don't think to!string is enough, 
because it is probably a no-op in this case: string - string).


No to!string is not a no-op in this case. It allocates but it 
needs to create an immutable char array that is: char[] - 
string


I see, File.byLine returns a range of char[], I thought it 
returned a string range. Then you're of course right.




However, byLine has another problem, which boils down to the 
same cause as the problem with RCArray, namely that the 
content of the buffer is reused in each iteration.


This is what I meant with volatile. Is there a better word for 
this?


I guess it's fine, and now I remember again that ranges with this 
property have been called volatile ranges.




the owner can be modified while references to it exist. For 
byLine, this is not a safety violation, but for RCArray it is. 
A solution applicable to both is to detect this and then 
either treat such a situation as @system, or make the owner 
`const` as long as the references are alive.


AFAIK: Allowing scope in foreach would solve this problem in my 
case.


See above. Conceptually, you can of course treat it as if it were 
marked with `scope`, but an actual annotation should not be 
necessary.


Re: problem with gc?

2015-05-27 Thread zhmt via Digitalmars-d-learn

@jklp



And also you could try to surround the whole block with 
`GC.disable` and `GC.enable`. This would help to determine if 
the GC is involved:


---
Ptr!Conn conn = connect(127.0.0.1,8881);
GC.disable;
ubyte[100] buf;
string str;
for(int i=0; iN; i++)
{
str = format(%s,i);
conn.write(cast(ubyte[]) str);
conn.read(buf[0..str.length]);
n++;
}
GC.enable;
conn.close();
---


I have tried this, and throughput falls down as well too. Does 
this mean the gc is not involved? I am confused.


Re: DMD Symbol Reference Analysis Pass

2015-05-27 Thread via Digitalmars-d

On Wednesday, 27 May 2015 at 08:43:07 UTC, Per Nordlöw wrote:

On Wednesday, 27 May 2015 at 08:38:48 UTC, Per Nordlöw wrote:
AFAIK, in current DMD, I can't get any help in avoiding 
patterns such as


   char[] saved_line;
   foreach (line; File(foo.txt).byLine)
   {
   saved_line = line; // should give error
   }


If I understand you correctly, a new kind of qualifier for 
`line` may be motivated here. The semantic meaning of `scope` D 
is not related to volatile property. I guess the problem is 
somewhat related to reference counting and ownership, right.


See my other reply. Originally I thought so too, but it turns out 
they can't really be separated. It's basically an instance of 
Rust's restriction exactly one mutable reference, or N immutable 
references, but not both at the same time.


Re: DIP78 - macros without syntax extensions

2015-05-27 Thread Dennis Ritchie via Digitalmars-d

On Wednesday, 27 May 2015 at 09:40:35 UTC, Kagamin wrote:
The point is to streamline ast creation. I think, helper 
methods can be provided by phobos in, say, std.macros to 
simplify ast creation for common constructs. Well, in a way 
libraries are a form of DSL...


std.macros it may, this is the right way! At least, it would suit 
me :)


Re: DMD Symbol Reference Analysis Pass

2015-05-27 Thread via Digitalmars-d

On Wednesday, 27 May 2015 at 08:30:33 UTC, Marc Schütz wrote:
See above. Conceptually, you can of course treat it as if it 
were marked with `scope`, but an actual annotation should not 
be necessary.


But now you're talking about an upcoming feature in DMD, right?

AFAIK, in current DMD, I can't get any help in avoiding patterns 
such as


char[] saved_line;
foreach (line; File(foo.txt).byLine)
{
saved_line = line; // should give error
}

Right?

Are you saying that adding DMD support for qualifying `line` as 
`scope` is not the right way to solve this problem?


Re: DIP78 - macros without syntax extensions

2015-05-27 Thread ZombineDev via Digitalmars-d

On Tuesday, 26 May 2015 at 20:23:11 UTC, Kagamin wrote:
http://wiki.dlang.org/DIP78 - Proposal for a macro system 
without syntactical extensions to the language. Hence it 
doesn't allow arbitrary syntax.


I really like how powerful and easy to use are AST macros in nim. 
IMO, if D gets such, it would become the language with the best 
meta-programming abilities D - :D

Here's a nice presentation about them:
http://www.infoq.com/presentations/nimrod


Re: DIP78 - macros without syntax extensions

2015-05-27 Thread Dennis Ritchie via Digitalmars-d

On Wednesday, 27 May 2015 at 08:14:36 UTC, Kagamin wrote:
The problem with declarative macro system is that you would 
need to learn yet another language. Possibly turing-complete. 
And a declarative turing-complete language is an overkill both 
for usage and implementation. Imperative macros get it done in 
an intuitive way in the existing language.


Yes, declarative macros can destroy an imperative language, 
because they can change the syntax of the language beyond 
recognition. Ie macrosystem will be more powerful than the 
language itself. Unfortunately, Nemerle, Scala and turned :)
But, in my opinion, there should be options to combine 
declarative macros with imperative languages. You just need to 
properly limit these macros to a certain moment.
Is not it possible to combine in the desired degree of 
declarative macros with imperative languages?


Re: DIP78 - macros without syntax extensions

2015-05-27 Thread Kagamin via Digitalmars-d

On Wednesday, 27 May 2015 at 09:31:33 UTC, Dennis Ritchie wrote:
Is not it possible to combine in the desired degree of 
declarative macros with imperative languages?


The point is to streamline ast creation. I think, helper methods 
can be provided by phobos in, say, std.macros to simplify ast 
creation for common constructs. Well, in a way libraries are a 
form of DSL...


Re: Uphill

2015-05-27 Thread Chris via Digitalmars-d

On Tuesday, 26 May 2015 at 17:13:18 UTC, ketmar wrote:

On Tue, 26 May 2015 10:07:08 +, Chris wrote:

With Go I have the sinking feeling that it won't be able to 
contend with
C++ - or D for that matter. It took off due to Google and a 
fool-proof,
easy-to-use infrastructure. But it is way too limited and 
limiting to be
useful for more sophisticated tasks. Go's core devs even say 
that they
wanted it to be an easy-to-use, middle-of-the-road language 
for those
who work in their code mines, focusing on a high output, and 
it doesn't
matter, if you have to write the same function or for-loop 
with slight

modifications over and over and over again.


and it really doesn't matter... for Rob Pike. he also don't 
like shared
libraries and other bells and whistles. sometimes he is right, 
but

sometimes he is too radical.

Go is a java from google, aimed to raise a bunch of easily 
replaceable

programmers.


Exactly. As such it cannot be a serious contender as regards 
quality and versatility. There will be loads of Go code around, 
millions of for-loops on hundreds of thousands of servers, but I 
don't think it will go any further. Languages like D that are 
flexible and take useful concepts on board are much better suited 
for the programming challenges of the future (e.g. sophisticated 
high speed data processing algorithms).


The thing is that Java and Python (and soon Go?) hit a brick wall 
sooner or later. Huge efforts are made to improve speed, 
flexibility and whatnot (JIT, Cython etc). But the real problem 
lies in rigid and narrow minded design decisions taken more than 
a decade ago. This is why it's still back to C and C++ for 
serious stuff.[1]


[1] For more than a decade I've been hearing that with Java 
8.x/9.x/10.x this or that issue will be fixed, or that Python 
will soon have native performance. It never happens and it never 
will. It's time to move on. Take the D train. :-)



so, like java, Go can't be complicated. both Gosling and
Pike are highly talented people, and that talent helps them to 
design

dumb languages (which is not as easy as it seems ;-).




Re: How to implement immutable ring buffer?

2015-05-27 Thread Daniel Kozák via Digitalmars-d-learn

On Wed, 27 May 2015 09:20:52 +
drug via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:

 Could somebody share his thoughts on the subject?
 Would it be efficient? Is it possible to avoid memory copying to
 provide immutability? To avoid cache missing ring buffer should be
 like array, not list, so it's possible that the whole buffer should
 be moved. Is it neccessary to be real immutable, may be some form of
 fake immutabitiy is enough?
 I'd like to try immutability in my app, and ring buffer is what I
 don't know how to use in the realm of immutability.
 
 Thanks

Maybe http://dlang.org/phobos/std_typecons.html#.Rebindable could help
you.


Re: DMD Symbol Reference Analysis Pass

2015-05-27 Thread via Digitalmars-d

On Wednesday, 27 May 2015 at 08:38:48 UTC, Per Nordlöw wrote:

On Wednesday, 27 May 2015 at 08:30:33 UTC, Marc Schütz wrote:
See above. Conceptually, you can of course treat it as if it 
were marked with `scope`, but an actual annotation should not 
be necessary.


But now you're talking about an upcoming feature in DMD, right?



Well, obviously, nothing of what we're talking about works with 
current DMD. Even scope doesn't do anything (except for 
delegates).


AFAIK, in current DMD, I can't get any help in avoiding 
patterns such as


char[] saved_line;
foreach (line; File(foo.txt).byLine)
{
saved_line = line; // should give error
}

Right?


Yes.



Are you saying that adding DMD support for qualifying `line` as 
`scope` is not the right way to solve this problem?


Yes. First of all, `File.byLine.front` is the function that needs 
to get annotated, like this:


char[] front() return {
// ...
return buffer;
}

The `return` keyword here means the same thing as in DIP25, 
namely that the returned value is owned by `this`. In your 
example, the owner is the temporary returned by 
`File(foo.txt).byLine`, which means that the returned buffer 
must no longer be used when that temporary gets destroyed, i.e. 
the read strings must not escape the foreach (without being 
copied), which allows the buffer to be safely released then. This 
is the original problem that `scope` was meant to address.


Conceptually, you're right that now `line` needs to be annotated 
with `scope`, because otherwise you wouldn't be allowed to store 
the scoped slices there. But there really isn't any point in 
actually adding that annotation, because it can always be 
inferred by the compiler (it can add the annotation for you when 
it sees that you assign a scoped value to it).


This alone is then already enough to prevent the volatility 
problem in your example, because it is longer possible for the 
individual lines to outlive the byLine() temporary that gets 
iterated over.


However, it is not enough in the general case:

auto lines = stdin.ByLine;
auto line1 = lines.front;
lines.popFront();
// line1 now changes
auto line2 = lines.front;

In this case, the rule that `line1` must not outlive `lines` is 
fulfilled, but still it gets invalidated. With byLine(), this 
just leads to unexpected behaviour, but with e.g. reference 
counting, it can cause memory corruption (use after free). 
Therefore, any complete scope proposal needs to address this 
problem, too.


What I propose is the following: The compiler keeps track of 
outstanding loans to owned objects. As long as any such loan 
exists (in the above example, `line1` and `line2`), the owner 
(i.e. `lines`) will either become read-only (const), or 
alternatively, it will stay mutable, but mutating it will become 
@system. This effectively addresses both the safety problems as 
well as volatile ranges, because they are actually the same 
problem.


I hope it is now clear what I want to say. It is unfortunately a 
complicated topic...


Re: problem with gc?

2015-05-27 Thread Anonymouse via Digitalmars-d-learn

On Wednesday, 27 May 2015 at 10:24:59 UTC, zhmt wrote:

@Anonymouse

Thank u very much, I have tried this:

 valgrind  --tool=callgrind ./gamelibdtest

callgrind_annotate callgrind.out.29234


 Ir  file:function

[...]


Without touching on the actual profile (which I'll leave to those 
better knowledgeable than I), open those callgrind.out.pid.* 
files in KCachegrind to get callgraphs.


See https://imgur.com/AZEutCE,XXIDBvB,qehWaHg,bpTxS,3YfcJdh for 
some examples.


Re: DMD Symbol Reference Analysis Pass

2015-05-27 Thread via Digitalmars-d

On Wednesday, 27 May 2015 at 09:54:33 UTC, Marc Schütz wrote:
Yes. First of all, `File.byLine.front` is the function that 
needs to get annotated, like this:


char[] front() return {
// ...
return buffer;
}

The `return` keyword here means the same thing as in DIP25,


Is this supportd in 2.067 with -dip25 flag?

If so shouldn't we qualify `File.byLine.front` with return when 
DIP-25 becomes stable?


Re: How to implement immutable ring buffer?

2015-05-27 Thread thedeemon via Digitalmars-d-learn

This whole idea sounds self-contradictory.
Ring buffer is a mutable-array-based implementation of something, 
for example of a queue. You can ask about immutable 
implementations of a queue, but that would be another question, 
not involving a ring buffer.


What do you want to do with this buffer, what do you need it for?


Re: problem with gc?

2015-05-27 Thread zhmt via Digitalmars-d-learn




What happened when the code changes a little? Who will give an 
explaination,Thanks a lot?


what happend if you use sformat instead?

Ptr!Conn conn = connect(127.0.0.1,8881);
ubyte[100] buf;
char[100] buf2;
for(int i=0; iN; i++)
{
auto str = sformat(buf2, %s,i);
conn.write((cast(ubyte*)str.ptr)[0..str.length]);
conn.read(buf[0..str.length]);
n++;
}
conn.close();


@Daniel Kozák
Thanks for reply.

I have tried sformat, but it doesnt work: throughput falls down, 
and the cpu keeps busy.


Re: problem with gc?

2015-05-27 Thread zhmt via Digitalmars-d-learn
If I pass a timeout with 1ms to epoll_wait,the cpu will not be 
busy when throughput falls down.


Re: problem with gc?

2015-05-27 Thread zhmt via Digitalmars-d-learn

It seems that  dlang library is not so effient?


Re: Expanding asm.dlang.org

2015-05-27 Thread Mike via Digitalmars-d


I've updated explore.dgnu.org with gdc-4.9, along with ARM and 
ARMHF
variants.  ARM supports -mthumb code generation. 
http://goo.gl/NmdnU1


Iain


I added a few platform flags and compared the output with my 
cross-compiler.  They look identical.  This is great! Thanks!


Re: How to implement immutable ring buffer?

2015-05-27 Thread drug via Digitalmars-d-learn

On 27.05.2015 11:10, Daniel Kozák via Digitalmars-d-learn wrote:


On Wed, 27 May 2015 09:20:52 +
drug via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:


Could somebody share his thoughts on the subject?
Would it be efficient? Is it possible to avoid memory copying to
provide immutability? To avoid cache missing ring buffer should be
like array, not list, so it's possible that the whole buffer should
be moved. Is it neccessary to be real immutable, may be some form of
fake immutabitiy is enough?
I'd like to try immutability in my app, and ring buffer is what I
don't know how to use in the realm of immutability.

Thanks


Maybe http://dlang.org/phobos/std_typecons.html#.Rebindable could help
you.

I guess it won't be efficient, because it would be ring buffer of (in 
some form) pointers. It's suitable if elements of the buffer are 
processed independently each other. In other case cache misses are 
provided, I think.


Re: shared libs for OSX

2015-05-27 Thread Martin Nowak via Digitalmars-d

On Tuesday, 26 May 2015 at 16:25:52 UTC, bitwise wrote:

Isn't it better to avoid private undocumented functions?
Not only better, but mandatory, otherwise Apple will reject the 
app from the app store.


Calling back into an unloaded image without proving a mean to 
deregister the callback is a bug, so you might fix it.


Looking at the code [1] again there is also an interesting 
sImagesToNotifyAboutOtherImages.


[1]: 
http://opensource.apple.com/source/dyld/dyld-95.3/src/dyld.cpp


Re: DConf parking info and code

2015-05-27 Thread Adam D. Ruppe via Digitalmars-d-announce

Where is the conference itself?


Re: shared libs for OSX

2015-05-27 Thread Martin Nowak via Digitalmars-d

On Wednesday, 27 May 2015 at 06:45:49 UTC, Jacob Carlborg wrote:
I'm not sure. The ___tls_get_addr function [1] is used when 
accessing a TLS variable on OS X. In all native 
implementations, both on OS X and Linux, the parameter is not 
just a void* but struct containing the image header as well.


On Linux you call it with an dso index and an offset. The DSO 
index is assigned by the runtime linker (there is a special 
relocation for that). Something similar could be done manually if 
not natively supported on OSX.


Re: problem with gc?

2015-05-27 Thread Steven Schveighoffer via Digitalmars-d-learn

On 5/27/15 2:42 AM, zhmt wrote:

When I enable the --profle, get something like this, it doesnt give me
too much help:



I don't see any GC function here, I don't think you are are focusing on 
the right portion of the code. Seems like the gamelib library is 
consuming all the time. You may want to check with the author of that 
code for help.


-Steve


Re: DIP78 - macros without syntax extensions

2015-05-27 Thread Dennis Ritchie via Digitalmars-d

On Wednesday, 27 May 2015 at 12:37:51 UTC, Kagamin wrote:

On Wednesday, 27 May 2015 at 12:34:49 UTC, Daniel Kozák wrote:

What if use the symbol '#' ?


Yep, I like this symbol for macro too.


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


OK. This symbol is already used in a wrong place :)

http://dlang.org/lex.html#special-token-sequence

You can still use `:`. The colon is used even to refer to some 
Lisp macros, for example:


(loop :for key :in keys
:collect (cons key 0))

Still, as an option, you can use the `'` . This symbol is also 
used in Lisp, in some places, for example:


(key-weight 'sweet)

Or apostrophes, too, somewhere involved in the D?


Re: Proof of concept - library AA

2015-05-27 Thread Martin Nowak via Digitalmars-d

On Monday, 25 May 2015 at 23:39:18 UTC, IgorStepanov wrote:

On Sunday, 24 May 2015 at 14:13:26 UTC, Martin Nowak wrote:

Would be interesting to get some opinions on this.

https://github.com/D-Programming-Language/druntime/pull/1282


BTW, I have one idea. We may declare the AA ABI:
AA is a pointer to the next layout:


This is intended as temporary solution to simplify the transition 
to a library aa.
Extending this conversion to other types for against the goal to 
replace the built-in AA.


Null argument and function resolution

2015-05-27 Thread Andrea Fontana via Digitalmars-d-learn

Check this example:
http://dpaste.dzfl.pl/53f85bae4382

Calling with null, both c-tor match.
Is there a way to solve this?

Something like:

this(in ubyte* data) if( ??? )
{

}


Andrea


Re: DerelictMantle - unofficial, experimental, reverse-engineered

2015-05-27 Thread ponce via Digitalmars-d-announce

On Wednesday, 27 May 2015 at 12:06:20 UTC, ParticlePeter wrote:

http://code.dlang.org/packages/derelict_extras-mantle/~master

Currently Windows only. Don't know if this will ever change. 
AMD:
The initial iteration of Mantle is intended specifically for 
Windows on PCs.​


Please let me know if you get the triangle drawn or displayed.

Cheers, ParticlePeter


Probably a good basis for the future DerelictVulkan :)


Re: Uphill

2015-05-27 Thread Paulo Pinto via Digitalmars-d

On Wednesday, 27 May 2015 at 10:01:35 UTC, Chris wrote:

On Tuesday, 26 May 2015 at 17:13:18 UTC, ketmar wrote:

On Tue, 26 May 2015 10:07:08 +, Chris wrote:

With Go I have the sinking feeling that it won't be able to 
contend with
C++ - or D for that matter. It took off due to Google and a 
fool-proof,
easy-to-use infrastructure. But it is way too limited and 
limiting to be
useful for more sophisticated tasks. Go's core devs even say 
that they
wanted it to be an easy-to-use, middle-of-the-road language 
for those
who work in their code mines, focusing on a high output, and 
it doesn't
matter, if you have to write the same function or for-loop 
with slight

modifications over and over and over again.


and it really doesn't matter... for Rob Pike. he also don't 
like shared
libraries and other bells and whistles. sometimes he is right, 
but

sometimes he is too radical.

Go is a java from google, aimed to raise a bunch of easily 
replaceable

programmers.


Exactly. As such it cannot be a serious contender as regards 
quality and versatility. There will be loads of Go code around, 
millions of for-loops on hundreds of thousands of servers, but 
I don't think it will go any further. Languages like D that are 
flexible and take useful concepts on board are much better 
suited for the programming challenges of the future (e.g. 
sophisticated high speed data processing algorithms).


The thing is that Java and Python (and soon Go?) hit a brick 
wall sooner or later. Huge efforts are made to improve speed, 
flexibility and whatnot (JIT, Cython etc). But the real problem 
lies in rigid and narrow minded design decisions taken more 
than a decade ago. This is why it's still back to C and C++ for 
serious stuff.[1]


[1] For more than a decade I've been hearing that with Java 
8.x/9.x/10.x this or that issue will be fixed, or that Python 
will soon have native performance. It never happens and it 
never will. It's time to move on. Take the D train. :-)




Only when I can sell D to customers that put money into this kind 
of stuff


http://www.azulsystems.com/press-2014/azul-systems-and-orc-partner-to-enable-smarter-high-performance-trading

http://chronicle.software/products/koloboke-collections/

http://devblogs.nvidia.com/parallelforall/next-wave-enterprise-performance-java-power-systems-nvidia-gpus/

Ecosystems count more than language features.

--
Paulo


Re: problem with gc?

2015-05-27 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 27 May 2015 at 10:27:08 UTC, zhmt wrote:

It seems that  dlang library is not so effient?


The gamelibd could be doing a lot more than just echoing... it 
sounds to me that your socket might be blocking and epoll is busy 
looping waiting for it to become available again.


Re: Prevent slices from referencing old array after realocation?

2015-05-27 Thread Steven Schveighoffer via Digitalmars-d-learn

On 5/27/15 1:55 AM, Gr8Ape wrote:

I'm writing a program that handles lots of slices of larger
arrays. I need the data of each of them all together for one
operation, but otherwise it's more convenient to handle the
elements in small groups. I could just store a pointer to my
array, an offset, and a length but since I'm using D I'd much
prefer to use slices...

So I was looking through the documentation on slices and found
out that if the array has to realocate then slices pointing to
that array will keep on pointing to that block of memory, rather
than the new location. Given that I'll be working with arrays
that can vary wildly in size and that giving all of them the
maximum capacity so they never realocate would be extremely
inefficent, I need a workaround.

So I'm wondering if there's a way to tell all the slices of an
underlying array to now point to the new underlying array upon
reallocation? Or would I have to iterate through and reassign
every slice?


Slices can't do this, because they have no idea about each other. So 
when you append to one slice, you can't have it update all other 
relevant slices.


However, you could create a type that does this.

-Steve


Re: DIP78 - macros without syntax extensions

2015-05-27 Thread Jacob Carlborg via Digitalmars-d

On 2015-05-27 10:06, Kagamin wrote:


I believe 78 allows a simpler implementation and requires less changes
to the language, though I'm not sure if frontend can get it done on a
purely semantical level: similar techniques like mixins and static if
rely on syntax.


DIP50 would require a minimal amount of syntax change, the only thing is 
prefixing a function with the macro keyword. DIP78 on the other hand, 
it's not so easy to see that a function declaration is actual a macro 
declaration.


In that case I would prefer the macro keyword. It's already a 
reserved, for exactly this purpose, so it will be backwards compatible.


I would say that neither of the DIP's contain a lot of detail. So it's 
hard to know which one is more complex. In DIP50 there's quite a lot of 
optional/bonus features. To me, implementing only the minimal 
requirements look very similar to DIP78.


One thing that would be more complex in DIP50 would be the Context 
class. Although I'm not sure if that's needed in DIP78 as well.



Maybe a macro should be called with a special syntax,
e.g. myAssert!(a==b);


I have thought of that too. But I haven't been able to come up with a 
syntax that looks good and doesn't conflict with any existing 
syntax/symbol. The above syntax is already used for template instantiation.


--
/Jacob Carlborg


Re: DIP78 - macros without syntax extensions

2015-05-27 Thread Kagamin via Digitalmars-d

On Wednesday, 27 May 2015 at 11:53:00 UTC, Jacob Carlborg wrote:
DIP50 would require a minimal amount of syntax change, the only 
thing is prefixing a function with the macro keyword. DIP78 
on the other hand, it's not so easy to see that a function 
declaration is actual a macro declaration.


Well, that's the point: the function is a normal function, only 
some of its parameters require specially prepared arguments, this 
can't be missed as soon as arguments are passed to the respective 
parameters.


In that case I would prefer the macro keyword. It's already a 
reserved, for exactly this purpose, so it will be backwards 
compatible.


Well, maybe, I just didn't need the keyword.

One thing that would be more complex in DIP50 would be the 
Context class. Although I'm not sure if that's needed in 
DIP78 as well.


No, passing of Context is not proposed.


Maybe a macro should be called with a special syntax,
e.g. myAssert!(a==b);


I have thought of that too. But I haven't been able to come up 
with a syntax that looks good and doesn't conflict with any 
existing syntax/symbol. The above syntax is already used for 
template instantiation.


I mean, the template instantiation syntax can inform the compiler 
that the expression is evaluated at compile time with possible 
code generation, so that the compiler is prepared to what macro 
will do. This resembles similarity between macros and templates. 
If macros can use existing syntax of a function call, I see no 
problem if they use another existing syntax.


Re: DIP78 - macros without syntax extensions

2015-05-27 Thread Daniel Kozák via Digitalmars-d

On Wed, 27 May 2015 12:07:09 +
Dennis Ritchie via Digitalmars-d digitalmars-d@puremagic.com wrote:

 On Wednesday, 27 May 2015 at 11:53:00 UTC, Jacob Carlborg wrote:
  I have thought of that too. But I haven't been able to come up 
  with a syntax that looks good and doesn't conflict with any 
  existing syntax/symbol. The above syntax is already used for 
  template instantiation.
 
 What if use the symbol '#' ?

Yep, I like this symbol for macro too.


problem with custom predicate

2015-05-27 Thread via Digitalmars-d-learn
I am trying to use a Container class with a custom predicate, but 
the following code does not compile. Any hints on how to do it?


import std.container;

class C
{
int[] prio;
RedBlackTree!(int, (a,b)=prio[a]prio[b]) tree;
}

I think I understand the reason why this does not work (the 
lambda cannot access the 'this' to get to 'prio'), but I can't 
think of a way to make it work. Any Ideas?





Re: Null argument and function resolution

2015-05-27 Thread Adam D. Ruppe via Digitalmars-d-learn

Two options:

1) add an overload that takes typeof(null)

this(typeof(null)) { /* handles the null literal specially */ }

2) Cast null to a specific type when making it:

new YourClass(cast(ubyte*) null);


Re: DIP78 - macros without syntax extensions

2015-05-27 Thread Dennis Ritchie via Digitalmars-d

On Wednesday, 27 May 2015 at 11:53:00 UTC, Jacob Carlborg wrote:
I have thought of that too. But I haven't been able to come up 
with a syntax that looks good and doesn't conflict with any 
existing syntax/symbol. The above syntax is already used for 
template instantiation.


What if use the symbol '#' ?


DerelictMantle - unofficial, experimental, reverse-engineered

2015-05-27 Thread ParticlePeter via Digitalmars-d-announce

http://code.dlang.org/packages/derelict_extras-mantle/~master

Currently Windows only. Don't know if this will ever change. AMD:
The initial iteration of Mantle is intended specifically for 
Windows on PCs.​


Please let me know if you get the triangle drawn or displayed.

Cheers, ParticlePeter


Re: DIP78 - macros without syntax extensions

2015-05-27 Thread Dennis Ritchie via Digitalmars-d

On Wednesday, 27 May 2015 at 12:55:05 UTC, Dennis Ritchie wrote:

Or apostrophes, too, somewhere involved in the D?


Similarly, this option is no longer, as is used as:
char c = 'c';

Though...


Re: Parallelism

2015-05-27 Thread Robbin via Digitalmars-d
Thank you,  core.thread was exactly what I would have started 
with if I'd just seen the derived line in the example.  My 
earlier careless reading led me to believe I needed to compose my 
own class, which felt more complicated than it should be.


Re: shared libs for OSX

2015-05-27 Thread Martin Nowak via Digitalmars-d

On Tuesday, 26 May 2015 at 16:25:52 UTC, bitwise wrote:
Since all global functions and symbols are shared between 
images anyways, receiving the callback in the main image would 
be fine. So in this case, unregistering the callbacks is no 
longer needed.


That only works when the host executable is linked against 
druntime, but falls when you load runtime dynamically, e.g. a D 
plugin for a C host.


Re: DIP78 - macros without syntax extensions

2015-05-27 Thread Dennis Ritchie via Digitalmars-d

On Wednesday, 27 May 2015 at 13:12:05 UTC, Meta wrote:
As far as I know, the : and ' symbols in Lisp don't have 
anything to do with macros. : is for keyword arguments and ' is 
for creating AST literals. It makes sense that these would be 
heavily used with macros, of course, but they are not part of 
Lisp's macro system.


Yes, but IMO, these symbols can be activated in the future 
macrosystem D.


Re: DIP78 - macros without syntax extensions

2015-05-27 Thread ixid via Digitalmars-d

On Wednesday, 27 May 2015 at 12:34:49 UTC, Daniel Kozák wrote:


On Wed, 27 May 2015 12:07:09 +
Dennis Ritchie via Digitalmars-d digitalmars-d@puremagic.com 
wrote:


On Wednesday, 27 May 2015 at 11:53:00 UTC, Jacob Carlborg 
wrote:
 I have thought of that too. But I haven't been able to come 
 up with a syntax that looks good and doesn't conflict with 
 any existing syntax/symbol. The above syntax is already used 
 for template instantiation.


What if use the symbol '#' ?


Yep, I like this symbol for macro too.


What's wrong with using the word macro? We don't want symbol soup.


Re: DIP78 - macros without syntax extensions

2015-05-27 Thread Kagamin via Digitalmars-d

On Wednesday, 27 May 2015 at 12:34:49 UTC, Daniel Kozák wrote:

What if use the symbol '#' ?


Yep, I like this symbol for macro too.


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


Re: DerelictMantle - unofficial, experimental, reverse-engineered

2015-05-27 Thread ParticlePeter via Digitalmars-d-announce

On Wednesday, 27 May 2015 at 12:44:29 UTC, ponce wrote:

On Wednesday, 27 May 2015 at 12:06:20 UTC, ParticlePeter wrote:

http://code.dlang.org/packages/derelict_extras-mantle/~master

Currently Windows only. Don't know if this will ever change. 
AMD:
The initial iteration of Mantle is intended specifically for 
Windows on PCs.​


Please let me know if you get the triangle drawn or displayed.

Cheers, ParticlePeter


Probably a good basis for the future DerelictVulkan :)


Yes, and get a head start in learning the Vulkan API :)



Re: DIP78 - macros without syntax extensions

2015-05-27 Thread Meta via Digitalmars-d

On Wednesday, 27 May 2015 at 12:55:05 UTC, Dennis Ritchie wrote:

On Wednesday, 27 May 2015 at 12:37:51 UTC, Kagamin wrote:

On Wednesday, 27 May 2015 at 12:34:49 UTC, Daniel Kozák wrote:

What if use the symbol '#' ?


Yep, I like this symbol for macro too.


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


OK. This symbol is already used in a wrong place :)

http://dlang.org/lex.html#special-token-sequence

You can still use `:`. The colon is used even to refer to some 
Lisp macros, for example:


(loop :for key :in keys
:collect (cons key 0))

Still, as an option, you can use the `'` . This symbol is also 
used in Lisp, in some places, for example:


(key-weight 'sweet)

Or apostrophes, too, somewhere involved in the D?


As far as I know, the : and ' symbols in Lisp don't have anything 
to do with macros. : is for keyword arguments and ' is for 
creating AST literals. It makes sense that these would be heavily 
used with macros, of course, but they are not part of Lisp's 
macro system.


Signals

2015-05-27 Thread Robbin via Digitalmars-d
I'm writing a daemon in D on linux.  I need to be able to stop 
(kill) it. The traditional C method is a signal handler.  I can 
do this, but I can't figure out how to get the handler to do 
anything to tell the rest of the daemon to quit.


In a C++ handler, I closed the files that were open, removed a 
PID file and exited.  Nothing complicated in the job.  It was 
more complicated in the implementation - I did a longjump from 
the signal handler to execute the cleanup code.


I would love to setup std.signals classes and from the 
core.stdc.signal signal handler call std.signals emit() to 
trigger the std.signals observer.


Is there a canonical D way of catching a SIGTERM and unwinding 
everything?


RC


Re: Signals

2015-05-27 Thread Adam D. Ruppe via Digitalmars-d
The way I do it is to set a global variable in the signal 
handler, then have the loop watch for it. So like


__gshared bool terminated = false;
extern(C) void handleSigTerm(int) { terminated = true; }

void main() {
while(!terminated) {
  if(select()  0)
 if(errno == EINTR) continue; // let the loop check 
the flag again

  // the rest of the stuff
}

// do normal cleanup here, and as the functions return
// naturally they will do unwinding.
}



Of course, with this strategy, if there's some long operation 
running inside the loop it won't get a chance to check the 
flag how you handle that is up to you. Maybe check that flag 
from time to time and throw an exception from work functions if 
it is set.



But there's no convenient way to exit from the handler itself 
while doing unwinding. You can exit, sure (use the C exit 
function), and the OS will clean up a lot of stuff but D 
destructors won't be called that way.


Re: Martin Nowak's talk cancelled

2015-05-27 Thread Lionello Lunesu via Digitalmars-d-announce

On 26/05/15 15:25, Andrei Alexandrescu wrote:

Sad news - Martin missed his flight and found no viable alternative to
make it to DConf.

For his slot at 10:00 AM on Thursday, we'll look into teleconferencing
options for him. Alternatively, we're now taking applications from the
other speakers and attendees to fill his slot. Please email your
proposals to Walter and myself if interested.


Andrei


Daniel suggested to turn it into a round of lightning talks. These are 
more spontaneous and don't need preparation. Might get people to talk 
that wouldn't fill a 1-hour talk.


L.


Now official: we are livestreaming DConf 2015

2015-05-27 Thread Andrei Alexandrescu via Digitalmars-d-announce
Thanks to John Colvin! He rigged his webcam centrally so we can 
livestream DConf 2015 in passable quality to youtube. Link:


https://www.youtube.com/watch?v=-OCl-jWyT9E

It's live now (30 minutes of break still ongoing so not a lot going on 
at the moment). Schedule at:


http://dconf.org/2015/schedule/index.html

Times are in MDT (GMT-0600).


Andrei


Re: Now official: we are livestreaming DConf 2015

2015-05-27 Thread Kai Nacke via Digitalmars-d-announce
On Wednesday, 27 May 2015 at 19:01:00 UTC, Andrei Alexandrescu 
wrote:
Thanks to John Colvin! He rigged his webcam centrally so we can 
livestream DConf 2015 in passable quality to youtube. Link:


https://www.youtube.com/watch?v=-OCl-jWyT9E

It's live now (30 minutes of break still ongoing so not a lot 
going on at the moment). Schedule at:


http://dconf.org/2015/schedule/index.html

Times are in MDT (GMT-0600).


Andrei


Hi!

Any chance to change the YouTube settings? Here in Germany I get 
only the message:
Live streaming is not available in your country due to rights 
issues.


Regards,
Kai


Re: problem with custom predicate

2015-05-27 Thread Steven Schveighoffer via Digitalmars-d-learn

On 5/27/15 9:59 AM, Meta wrote:


I thought unaryFun *does* work with all callables, including
structs/classes with opCall?


It (binaryFun actually) declares an alias. But you need an actual 
instance to use in this case. You simply can't declare that in a type 
definition, and it won't be set up properly in the constructor even if 
you could. You need an instance in order to use an alias to that instance.


What likely would happen is if the functor is a callable type, and that 
type is not a functor itself (i.e. doesn't define static opCall), is 
that RedBlackTree would then require an instance of that type as part of 
the constructor.


-Steve


Re: problem with gc?

2015-05-27 Thread via Digitalmars-d-learn

On Wednesday, 27 May 2015 at 05:48:13 UTC, zhmt wrote:




The code you posted is the client code, but the issue seems to be 
on the server side.

Can you post the server code and also the timing code?




Re: Prevent slices from referencing old array after realocation?

2015-05-27 Thread via Digitalmars-d-learn

On Wednesday, 27 May 2015 at 07:55:29 UTC, Gr8Ape wrote:




You can keep an index and a count instead of a slice.
If you know your data well, you can exploit this knowledge, and 
this has the potential to save you many bytes per slice when 
dealing with large data sets.
Depending on your access patterns, it also has the potential to 
be fairly more cpu-efficient.


Re: DConf 2015 Livestreaming?

2015-05-27 Thread extrawurst via Digitalmars-d

On Wednesday, 27 May 2015 at 17:32:06 UTC, Gary Willoughby wrote:

On Wednesday, 27 May 2015 at 10:32:32 UTC, Liam McSherry wrote:

On Wednesday, 27 May 2015 at 10:20:04 UTC, Per Nordlöw wrote:

Isn't there any live-streaming of DConf this year?


Unfortunately, there doesn't seem to be any streaming this 
year: 
http://forum.dlang.org/thread/zpwxvgiaigdbweach...@forum.dlang.org


I hope there is at least downloadable videos.


That has always been the case..


Re: DConf 2015 Livestreaming?

2015-05-27 Thread Joakim via Digitalmars-d

On Wednesday, 27 May 2015 at 17:32:06 UTC, Gary Willoughby wrote:

On Wednesday, 27 May 2015 at 10:32:32 UTC, Liam McSherry wrote:

On Wednesday, 27 May 2015 at 10:20:04 UTC, Per Nordlöw wrote:

Isn't there any live-streaming of DConf this year?


Unfortunately, there doesn't seem to be any streaming this 
year: 
http://forum.dlang.org/thread/zpwxvgiaigdbweach...@forum.dlang.org


I hope there is at least downloadable videos.


Yes, the university organizing the event is recording videos that 
will be put online at some point.


Re: DConf 2015 Livestreaming?

2015-05-27 Thread weaselcat via Digitalmars-d

On Wednesday, 27 May 2015 at 18:06:31 UTC, extrawurst wrote:
On Wednesday, 27 May 2015 at 17:32:06 UTC, Gary Willoughby 
wrote:

On Wednesday, 27 May 2015 at 10:32:32 UTC, Liam McSherry wrote:

On Wednesday, 27 May 2015 at 10:20:04 UTC, Per Nordlöw wrote:

Isn't there any live-streaming of DConf this year?


Unfortunately, there doesn't seem to be any streaming this 
year: 
http://forum.dlang.org/thread/zpwxvgiaigdbweach...@forum.dlang.org


I hope there is at least downloadable videos.


That has always been the case..


Let me rephrase it for him,
I hope there is at least downloadable videos within the next 
month instead of last year's fiasco.


Re: Proof of concept - library AA

2015-05-27 Thread H. S. Teoh via Digitalmars-d
On Wed, May 27, 2015 at 05:16:51PM +, IgorStepanov via Digitalmars-d wrote:
 On Wednesday, 27 May 2015 at 14:12:02 UTC, Martin Nowak wrote:
 On Sunday, 24 May 2015 at 15:13:41 UTC, Vladimir Panteleev wrote:
 Could you elaborate on what these magic semantics are?
 
 and no easy solution exists for the ++aa[key1][key2] case.
 
 Is this specific to the pre-increment? aa[key1][key2]++ is generally
 a useful pattern.
 
 This applies to pre/post increment as well as assignment and
 opOpAssign.  When an lvalue is needed the compiler will call a
 special runtime function GetX to obtain an lvalue for aa[key1], i.e.
 the entry will be default initialized iff missing.
 If the expression is an rvalue though (aa[key1][key2]), a missing
 key1 will trigger a range error.
 In an opIndex(Key) you have no idea whether the whole expression I an
 lvalue or an rvalue.
 
 IIRC the construction/assignment of a value is also handled
 specifically.
 
 BTW, may be we should create DIP about opIndex extending?
[...]

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

This issue has been known since 2012.


T

-- 
Genius may have its limitations, but stupidity is not thus handicapped. -- 
Elbert Hubbard


Re: DConf 2015 Livestreaming?

2015-05-27 Thread Dicebot via Digitalmars-d
Inofficial ad-hoc stream : 
https://www.youtube.com/watch?v=-OCl-jWyT9E

(may randomly stop and get restarted)
(thanks John Colvin)


Re: DConf 2015 Livestreaming?

2015-05-27 Thread Andrej Mitrovic via Digitalmars-d
On 5/27/15, Dicebot via Digitalmars-d digitalmars-d@puremagic.com wrote:
 Inofficial ad-hoc stream :
 https://www.youtube.com/watch?v=-OCl-jWyT9E
 (may randomly stop and get restarted)
 (thanks John Colvin)

Nice!

Btw, youtube preemptively blocks this in Germany, only because it is a
live-stream and I guess they're just scared they'll get sued. Luckily
VPN here is to save the day. :)


Re: shared libs for OSX

2015-05-27 Thread Jacob Carlborg via Digitalmars-d

On 2015-05-27 15:38, Martin Nowak wrote:


On Linux you call it with an dso index and an offset. The DSO index is
assigned by the runtime linker (there is a special relocation for that).
Something similar could be done manually if not natively supported on OSX.


It is natively support.

--
/Jacob Carlborg


Re: Expanding asm.dlang.org

2015-05-27 Thread Andrei Alexandrescu via Digitalmars-d

On 5/27/15 5:38 AM, Vladimir Panteleev wrote:

On Monday, 25 May 2015 at 16:45:26 UTC, Andrei Alexandrescu wrote:

On 5/25/15 7:36 AM, Iain Buclaw via Digitalmars-d wrote:

I can add any cross compilers hosted on gdcproject.org
http://gdcproject.org. You'd need to go through Godbolt to
get it on
his host. asm.dlang.org http://asm.dlang.org is a no go
because it has
been tailored for dmd only.


The right answer is to tailor asm.dlang.org for everything. -- Andrei


We also have http://dpaste.dzfl.pl/ (which has GDC, LDC, and actually
runs the code).


That should also get integrated into the Borg: ide.dlang.org. Vladimir, 
are you up for it? -- Andrei


Re: DConf 2015 Livestreaming?

2015-05-27 Thread Jacob Carlborg via Digitalmars-d

On 2015-05-27 20:24, weaselcat wrote:


Let me rephrase it for him,
I hope there is at least downloadable videos within the next month
instead of last year's fiasco.


20 talks, one talk per week, that is five months for all talks.

--
/Jacob Carlborg


Re: DIP78 - macros without syntax extensions

2015-05-27 Thread Jacob Carlborg via Digitalmars-d

On 2015-05-27 14:17, Kagamin wrote:


Well, that's the point: the function is a normal function, only some of
its parameters require specially prepared arguments, this can't be
missed as soon as arguments are passed to the respective parameters.


I prefer to be more explicit in this case, especially since the keyword 
is already available.



In that case I would prefer the macro keyword. It's already a
reserved, for exactly this purpose, so it will be backwards compatible.


Well, maybe, I just didn't need the keyword.


I don't need it either, it's just what I preferred.


No, passing of Context is not proposed.


The feeling I have it that it's hard to know if it's needed or not 
without implementing/using the macro system.



I mean, the template instantiation syntax can inform the compiler that
the expression is evaluated at compile time with possible code
generation, so that the compiler is prepared to what macro will do. This
resembles similarity between macros and templates. If macros can use
existing syntax of a function call, I see no problem if they use another
existing syntax.


True, but how would that the syntax look like for template macro, if 
possible?


--
/Jacob Carlborg


Re: problem with custom predicate

2015-05-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/27/15 9:11 AM, Simon =?UTF-8?B?QsO8cmdlciI=?= 
simon.buer...@rwth-aachen.de wrote:

On Wednesday, 27 May 2015 at 14:58:39 UTC, drug wrote:


Do you want to dynamically change priority?

Actually yes. In my actual code I am not using a RedBlackTree but my own
Container (a heap with the possibility to modify elements inside), which
is notified when prio changes so it can do a (local) reordering.


It would be a very bad idea to change prio if the RBTree is constructed 
already (and if this works).



Why prio is outside of your predicate?

Well, how would I get it into the lambda? In C++ I would use a
comparision class, and the constructor of the container would take an
instance of that class. But D's RedBlackTree-constructor does not take
such a (run-time) argument. And I dont see a way to get prio into the
predicate, which is a template-argument.


This is true, RedBlackTree does not take a functor as a parameter to the 
constructor, it just uses an alias.


This should work if your RedBlackTree is scoped inside a function where 
the data exists. But at the time of declaration inside the class, the 
instance of prio doesn't exist, so you can't alias it.


It would be a good enhancement I think to add support for function objects.

-Steve



Re: DIP78 - macros without syntax extensions

2015-05-27 Thread Idan Arye via Digitalmars-d

On Wednesday, 27 May 2015 at 08:14:36 UTC, Kagamin wrote:

On Tuesday, 26 May 2015 at 23:47:41 UTC, Dennis Ritchie wrote:
If this proposal is considered, it is required to propose to 
look
at the implementation of macros in Nemerle. Many believe that 
it
is in Nemerle macros implemented the most successful compared 
to
other modern languages. Of course, the most successful macros 
are

implemented in Lisp, but the syntax of the language is poor :)


The problem with declarative macro system is that you would 
need to learn yet another language. Possibly turing-complete. 
And a declarative turing-complete language is an overkill both 
for usage and implementation. Imperative macros get it done in 
an intuitive way in the existing language.


But D already has such a declarative language - the one used in 
template metaprogramming. I think a macro system that plays well 
with that template metaprogramming sub-language will be really 
nice. For example, CTFE that works like a macro and returns 
types/aliases:


Auto deduceType(Auto args) {
// some complex imperative code to deduce the type from 
the args

return DeducedType;
}

struct Foo(T...) {
deduceType(T) value;
}


Re: problem with custom predicate

2015-05-27 Thread Timon Gehr via Digitalmars-d-learn

On 05/27/2015 05:30 PM, Steven Schveighoffer wrote:

On 5/27/15 9:11 AM, Simon =?UTF-8?B?QsO8cmdlciI=?=
simon.buer...@rwth-aachen.de wrote:

On Wednesday, 27 May 2015 at 14:58:39 UTC, drug wrote:


Do you want to dynamically change priority?

Actually yes. In my actual code I am not using a RedBlackTree but my own
Container (a heap with the possibility to modify elements inside), which
is notified when prio changes so it can do a (local) reordering.


It would be a very bad idea to change prio if the RBTree is constructed
already (and if this works).


Why prio is outside of your predicate?

Well, how would I get it into the lambda? In C++ I would use a
comparision class, and the constructor of the container would take an
instance of that class. But D's RedBlackTree-constructor does not take
such a (run-time) argument. And I dont see a way to get prio into the
predicate, which is a template-argument.


This is true, RedBlackTree does not take a functor as a parameter to the
constructor, it just uses an alias.

This should work if your RedBlackTree is scoped inside a function where
the data exists. But at the time of declaration inside the class, the
instance of prio doesn't exist, so you can't alias it.

It would be a good enhancement I think to add support for function objects.

-Steve



Also, apart from missing implementation, there is no good reason why the 
code given should not work, is there? I think nested template 
instantiation should work in all scopes. (Of course, there is the issue 
that nested structs are somewhat arbitrarily not given a context pointer 
when declared within a class/struct, so this might be a little 
inconsistent in case it also works for structs, no question for classes 
though: just instantiate as nested class.)


Re: DMD Symbol Reference Analysis Pass

2015-05-27 Thread weaselcat via Digitalmars-d

On Wednesday, 27 May 2015 at 11:02:24 UTC, Per Nordlöw wrote:

On Wednesday, 27 May 2015 at 10:53:48 UTC, Per Nordlöw wrote:

On Wednesday, 27 May 2015 at 09:54:33 UTC, Marc Schütz wrote:
Yes. First of all, `File.byLine.front` is the function that 
needs to get annotated, like this:


  char[] front() return {
  // ...
  return buffer;
  }

The `return` keyword here means the same thing as in DIP25,


Is this supportd in 2.067 with -dip25 flag?

If so shouldn't we qualify `File.byLine.front` with return 
when DIP-25 becomes stable?


I qualified `front` with `return` here

https://github.com/nordlow/justd/blob/master/bylinefast.d#L84

but compiling this with DMD 2.067 along with flag -dip25 
doesn't complain about


https://github.com/nordlow/justd/blob/master/bylinefast.d#L188

Did you mean that this too is a planned feature?


I might be wrong, but I thought dip25 was only enabled in @safe 
annotated code?


Re: DIP78 - macros without syntax extensions

2015-05-27 Thread weaselcat via Digitalmars-d

On Wednesday, 27 May 2015 at 12:39:52 UTC, ixid wrote:

On Wednesday, 27 May 2015 at 12:34:49 UTC, Daniel Kozák wrote:


On Wed, 27 May 2015 12:07:09 +
Dennis Ritchie via Digitalmars-d digitalmars-d@puremagic.com 
wrote:


On Wednesday, 27 May 2015 at 11:53:00 UTC, Jacob Carlborg 
wrote:
 I have thought of that too. But I haven't been able to come 
 up with a syntax that looks good and doesn't conflict with 
 any existing syntax/symbol. The above syntax is already 
 used for template instantiation.


What if use the symbol '#' ?


Yep, I like this symbol for macro too.


What's wrong with using the word macro? We don't want symbol 
soup.


this, there's a reason people don't use lisp.


Re: DIP78 - macros without syntax extensions

2015-05-27 Thread Dennis Ritchie via Digitalmars-d

On Wednesday, 27 May 2015 at 15:20:38 UTC, weaselcat wrote:

On Wednesday, 27 May 2015 at 12:39:52 UTC, ixid wrote:

On Wednesday, 27 May 2015 at 12:34:49 UTC, Daniel Kozák wrote:


On Wed, 27 May 2015 12:07:09 +
Dennis Ritchie via Digitalmars-d 
digitalmars-d@puremagic.com wrote:


On Wednesday, 27 May 2015 at 11:53:00 UTC, Jacob Carlborg 
wrote:
 I have thought of that too. But I haven't been able to 
 come up with a syntax that looks good and doesn't conflict 
 with any existing syntax/symbol. The above syntax is 
 already used for template instantiation.


What if use the symbol '#' ?


Yep, I like this symbol for macro too.


What's wrong with using the word macro? We don't want symbol 
soup.


this, there's a reason people don't use lisp.


Lisp is not used due to other reasons, symbol soup typical for 
Perl :)

$? ? s:;s:s;;$?: : s;;=]=%-{-|}|`{; ;
y; -/:-@[-`{-};`-{/ -; ;
s;;$_;see


Re: problem with custom predicate

2015-05-27 Thread Meta via Digitalmars-d-learn
On Wednesday, 27 May 2015 at 15:30:28 UTC, Steven Schveighoffer 
wrote:
On 5/27/15 9:11 AM, Simon =?UTF-8?B?QsO8cmdlciI=?= 
simon.buer...@rwth-aachen.de wrote:

On Wednesday, 27 May 2015 at 14:58:39 UTC, drug wrote:


Do you want to dynamically change priority?
Actually yes. In my actual code I am not using a RedBlackTree 
but my own
Container (a heap with the possibility to modify elements 
inside), which
is notified when prio changes so it can do a (local) 
reordering.


It would be a very bad idea to change prio if the RBTree is 
constructed already (and if this works).



Why prio is outside of your predicate?

Well, how would I get it into the lambda? In C++ I would use a
comparision class, and the constructor of the container would 
take an
instance of that class. But D's RedBlackTree-constructor does 
not take
such a (run-time) argument. And I dont see a way to get prio 
into the

predicate, which is a template-argument.


This is true, RedBlackTree does not take a functor as a 
parameter to the constructor, it just uses an alias.


This should work if your RedBlackTree is scoped inside a 
function where the data exists. But at the time of declaration 
inside the class, the instance of prio doesn't exist, so you 
can't alias it.


It would be a good enhancement I think to add support for 
function objects.


-Steve


I thought unaryFun *does* work with all callables, including 
structs/classes with opCall?


Re: Signals

2015-05-27 Thread Robbin via Digitalmars-d
I'm using nanomsg to communicate between various components 
(actually distributed across a number of computers) and my main 
event loops are waiting for a message.  The reads are 
encapsulated in a class, so I guess I'll change from a recv to a 
poll and add a second channel to communicate when it is time to 
die.  In the signal handler I can send a message and in the 
class, send a std.signal to end the thread and then clean up the 
main loop and exit.  nn_poll is a c routine, so I should work 
comfortably in the handler.


I wish there was a more direct way to do this.  Signals are a 
bread and butter aspect of the Linux architecture.  I guess 
mangling is at the root of the problem.


Thank you.



Re: DMD Symbol Reference Analysis Pass

2015-05-27 Thread via Digitalmars-d

On Wednesday, 27 May 2015 at 14:13:03 UTC, Marc Schütz wrote:
I general, `return` is supposed to work (with -dip25), but only 
in combination with `ref`, not slices or pointers. DMD probably 
ignores it here instead of printing an error message.


So, *should* it error for slices or not?


Re: Wiki table for available compiler packages by platform/OS

2015-05-27 Thread Ozan via Digitalmars-d-announce

Great page.
Thanks for it.
It's a very helpful guide for the different flavours of D 
compilers.


Regards,  Ozan


[Issue 14093] [REG2.065] __traits(compiles, cast(Object)(tuple)) is true even if it doesn't compile.

2015-05-27 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=14093

Igor Stepanov wazar.leoll...@yahoo.com changed:

   What|Removed |Added

 Status|RESOLVED|REOPENED
 CC||wazar.leoll...@yahoo.com
 Resolution|FIXED   |---

--- Comment #6 from Igor Stepanov wazar.leoll...@yahoo.com ---
This issue is not fully solved.
There is simpler example:
-
struct FooBar
{
int a;
int b;
}

void test14093()
{
FooBar foo;
auto obj = cast(Object)foo; //e2ir: cannot cast foo of type FooBar to type
object.Object
}
-
Moreover, I think, this issue is solved incorrectly: alias this mechanism
should reject `cast(Object)(point._tupleAliasThis_)` variant and continue
process the root casting cast(Object)point excluding alias this.
And result error message should be 
Error: cannot cast expression point of type Tuple!(int, x, int, y) to
object.Object.
We are interested in subtyping (alias this, or inheritance) only when it can
done its work (casting, .member ...).

--


Re: Proof of concept - library AA

2015-05-27 Thread Martin Nowak via Digitalmars-d

On Sunday, 24 May 2015 at 15:13:41 UTC, Vladimir Panteleev wrote:

Could you elaborate on what these magic semantics are?


and no easy solution exists for the ++aa[key1][key2] case.


Is this specific to the pre-increment? aa[key1][key2]++ is 
generally a useful pattern.


This applies to pre/post increment as well as assignment and 
opOpAssign.
When an lvalue is needed the compiler will call a special runtime 
function GetX to obtain an lvalue for aa[key1], i.e. the entry 
will be default initialized iff missing.
If the expression is an rvalue though (aa[key1][key2]), a missing 
key1 will trigger a range error.
In an opIndex(Key) you have no idea whether the whole expression 
I an lvalue or an rvalue.


IIRC the construction/assignment of a value is also handled 
specifically.


Re: DMD Symbol Reference Analysis Pass

2015-05-27 Thread via Digitalmars-d

On Wednesday, 27 May 2015 at 11:02:24 UTC, Per Nordlöw wrote:

On Wednesday, 27 May 2015 at 10:53:48 UTC, Per Nordlöw wrote:

On Wednesday, 27 May 2015 at 09:54:33 UTC, Marc Schütz wrote:
Yes. First of all, `File.byLine.front` is the function that 
needs to get annotated, like this:


  char[] front() return {
  // ...
  return buffer;
  }

The `return` keyword here means the same thing as in DIP25,


Is this supportd in 2.067 with -dip25 flag?

If so shouldn't we qualify `File.byLine.front` with return 
when DIP-25 becomes stable?


I qualified `front` with `return` here

https://github.com/nordlow/justd/blob/master/bylinefast.d#L84

but compiling this with DMD 2.067 along with flag -dip25 
doesn't complain about


https://github.com/nordlow/justd/blob/master/bylinefast.d#L188

Did you mean that this too is a planned feature?


I general, `return` is supposed to work (with -dip25), but only 
in combination with `ref`, not slices or pointers. DMD probably 
ignores it here instead of printing an error message.


Re: DConf parking info and code

2015-05-27 Thread John Colvin via Digitalmars-d-announce

On Wednesday, 27 May 2015 at 14:00:20 UTC, Adam D. Ruppe wrote:

Where is the conference itself?


Sorenson centre, sc213a/b


Re: DConf parking info and code

2015-05-27 Thread Steven Schveighoffer via Digitalmars-d-announce

On 5/27/15 8:34 AM, John Colvin wrote:

On Wednesday, 27 May 2015 at 14:00:20 UTC, Adam D. Ruppe wrote:

Where is the conference itself?


Sorenson centre, sc213a/b


Sorensen Andrei informs me :)

-Steve



Re: DConf parking info and code

2015-05-27 Thread Steven Schveighoffer via Digitalmars-d-announce

On 5/27/15 8:34 AM, John Colvin wrote:

On Wednesday, 27 May 2015 at 14:00:20 UTC, Adam D. Ruppe wrote:

Where is the conference itself?


Sorenson centre, sc213a/b


In case this helps:

https://www.google.com/maps/place/Sorensen+Center,+Utah+Valley+University,+800+W+University+Pkwy,+Orem,+UT+84058/@40.2784748,-111.7140463,18z/data=!4m2!3m1!1s0x874d9ae2291a2bf5:0xf88259cc27d3c4b3

-Steve


Re: Null argument and function resolution

2015-05-27 Thread Andrea Fontana via Digitalmars-d-learn

The first answer is the one I was looking for. Very useful.
You should add to next this week in d tips.

On Wednesday, 27 May 2015 at 14:09:48 UTC, Adam D. Ruppe wrote:

Two options:

1) add an overload that takes typeof(null)

this(typeof(null)) { /* handles the null literal specially */ }

2) Cast null to a specific type when making it:

new YourClass(cast(ubyte*) null);




Re: problem with custom predicate

2015-05-27 Thread drug via Digitalmars-d-learn

On 27.05.2015 13:50, Simon Bürger simon.buer...@rwth-aachen.de wrote:

I am trying to use a Container class with a custom predicate, but the
following code does not compile. Any hints on how to do it?

import std.container;

class C
{
 int[] prio;
 RedBlackTree!(int, (a,b)=prio[a]prio[b]) tree;
}

I think I understand the reason why this does not work (the lambda
cannot access the 'this' to get to 'prio'), but I can't think of a way
to make it work. Any Ideas?


Do you want to dynamically change priority? Why prio is outside of your 
predicate?


Re: problem with custom predicate

2015-05-27 Thread via Digitalmars-d-learn

On Wednesday, 27 May 2015 at 14:58:39 UTC, drug wrote:


Do you want to dynamically change priority?
Actually yes. In my actual code I am not using a RedBlackTree but 
my own Container (a heap with the possibility to modify elements 
inside), which is notified when prio changes so it can do a 
(local) reordering.



Why prio is outside of your predicate?
Well, how would I get it into the lambda? In C++ I would use a 
comparision class, and the constructor of the container would 
take an instance of that class. But D's RedBlackTree-constructor 
does not take such a (run-time) argument. And I dont see a way to 
get prio into the predicate, which is a template-argument.


As I am implementing my own container anyway, I could of course 
do it the C++-way. But I was wondering if there is another way.


Re: DIP78 - macros without syntax extensions

2015-05-27 Thread Artur Skawina via Digitalmars-d
On 05/27/15 17:47, Idan Arye via Digitalmars-d wrote:
 On Wednesday, 27 May 2015 at 08:14:36 UTC, Kagamin wrote:
 On Tuesday, 26 May 2015 at 23:47:41 UTC, Dennis Ritchie wrote:
 If this proposal is considered, it is required to propose to look
 at the implementation of macros in Nemerle. Many believe that it
 is in Nemerle macros implemented the most successful compared to
 other modern languages. Of course, the most successful macros are
 implemented in Lisp, but the syntax of the language is poor :)

 The problem with declarative macro system is that you would need to learn 
 yet another language. Possibly turing-complete. And a declarative 
 turing-complete language is an overkill both for usage and implementation. 
 Imperative macros get it done in an intuitive way in the existing language.
 
 But D already has such a declarative language - the one used in template 
 metaprogramming. I think a macro system that plays well with that template 
 metaprogramming sub-language will be really nice. For example, CTFE that 
 works like a macro and returns types/aliases:
 
 Auto deduceType(Auto args) {
 // some complex imperative code to deduce the type from the args
 return DeducedType;
 }
 
 struct Foo(T...) {
 deduceType(T) value;
 }

That already works. Eg:

   alias deduceType(Args...) = typeof({
  // some complex imperative code to deduce the type from the args
  import std.range;
  return mixin(iota(Args.length).map!q{`Args[`~text(a)~']'}().join(+));
   }());

   struct Foo(T...) {
  deduceType!(T) value;
   }

   static assert(is(typeof(Foo!(short, ubyte, bool).value)==int));


What all these proposals seem to be about is:

a) better introspection (ie exposing a (preferably simplified and std) AST)
b) AST injection
c) better syntax
d) better optimizations, meaning skipping the emission of code and data
 that is never used at runtime.

artur



Re: Signals

2015-05-27 Thread Gary Willoughby via Digitalmars-d

On Wednesday, 27 May 2015 at 13:52:33 UTC, Robbin wrote:
I'm writing a daemon in D on linux.  I need to be able to stop 
(kill) it. The traditional C method is a signal handler.  I can 
do this, but I can't figure out how to get the handler to do 
anything to tell the rest of the daemon to quit.


In a C++ handler, I closed the files that were open, removed a 
PID file and exited.  Nothing complicated in the job.  It was 
more complicated in the implementation - I did a longjump from 
the signal handler to execute the cleanup code.


I would love to setup std.signals classes and from the 
core.stdc.signal signal handler call std.signals emit() to 
trigger the std.signals observer.


Is there a canonical D way of catching a SIGTERM and unwinding 
everything?


RC


I've usually just done this:

import core.stdc.stdlib : exit;
import core.sys.posix.signal : bsd_signal, SIGTERM;

extern(C) void handleTermination(int signal)
{
// Clean up code here.
exit(signal);
}

bsd_signal(SIGTERM, handleTermination);


Re: DConf 2015 Livestreaming?

2015-05-27 Thread Gary Willoughby via Digitalmars-d

On Wednesday, 27 May 2015 at 10:32:32 UTC, Liam McSherry wrote:

On Wednesday, 27 May 2015 at 10:20:04 UTC, Per Nordlöw wrote:

Isn't there any live-streaming of DConf this year?


Unfortunately, there doesn't seem to be any streaming this 
year: 
http://forum.dlang.org/thread/zpwxvgiaigdbweach...@forum.dlang.org


I hope there is at least downloadable videos.


Re: Proof of concept - library AA

2015-05-27 Thread IgorStepanov via Digitalmars-d

On Wednesday, 27 May 2015 at 14:12:02 UTC, Martin Nowak wrote:
On Sunday, 24 May 2015 at 15:13:41 UTC, Vladimir Panteleev 
wrote:

Could you elaborate on what these magic semantics are?


and no easy solution exists for the ++aa[key1][key2] case.


Is this specific to the pre-increment? aa[key1][key2]++ is 
generally a useful pattern.


This applies to pre/post increment as well as assignment and 
opOpAssign.
When an lvalue is needed the compiler will call a special 
runtime function GetX to obtain an lvalue for aa[key1], i.e. 
the entry will be default initialized iff missing.
If the expression is an rvalue though (aa[key1][key2]), a 
missing key1 will trigger a range error.
In an opIndex(Key) you have no idea whether the whole 
expression I an lvalue or an rvalue.


IIRC the construction/assignment of a value is also handled 
specifically.


BTW, may be we should create DIP about opIndex extending?
What do you want about following?
Let, if opIndex is template, and the first template argument is a 
bool value, compiler should pass true, if this is a part of 
l-value expression:


struct Foo
{
Foo[] children;
this(int value)
{
this.value = value;
}
int value;

ref Foo opIndex(bool lvl)(size_t idx)
{
if (idx  children.length)
return children[idx];
static if (lvl)
{
children.length = idx + 1;
return children[idx];
}
else
{
throw new Exception(out of bounds);
}
}
}


Foo f;
f[5][3] = Foo(42); translates to
f.opIndex!(true)(5).opIndex!(true)(3) = Foo(42);

auto x = f[5][4]; translates to
auto x = f.opIndex!(false)(5).opIndex!(false)(3);


Re: Null argument and function resolution

2015-05-27 Thread ketmar via Digitalmars-d-learn
On Wed, 27 May 2015 14:09:47 +, Adam D. Ruppe wrote:

 Two options:
 
 1) add an overload that takes typeof(null)
 
 this(typeof(null)) { /* handles the null literal specially */ }

you keep breaking my box of thinking. ;-) never thought about such 
declaration.

signature.asc
Description: PGP signature


Re: Martin Nowak's talk cancelled

2015-05-27 Thread Lionello Lunesu via Digitalmars-d-announce

On 27/05/15 13:01, Andrei Alexandrescu wrote:

On 5/27/15 12:13 PM, Lionello Lunesu wrote:

Daniel suggested to turn it into a round of lightning talks. These are
more spontaneous and don't need preparation. Might get people to talk
that wouldn't fill a 1-hour talk.


Good. So you go first? -- Andrei


Sure :)


  1   2   >