Re: Program exited with code -11

2015-06-24 Thread weaselcat via Digitalmars-d-learn

On Tuesday, 23 June 2015 at 06:50:28 UTC, Charles Hawkins wrote:

On Tuesday, 23 June 2015 at 03:31:37 UTC, weaselcat wrote:
On Tuesday, 23 June 2015 at 03:29:14 UTC, Charles Hawkins 
wrote:

[...]


Try to compile with either ldc or gdc and the -g flag, it 
should give you a backtrace. dmd seems to not like linux wrt 
backtraces.


Thanks.  I wish!  I haven't had any success in compiling with 
anything but dub.  gdc, dmd, rdmd always give me module mylib 
is in file 'mylib.d' which cannot be read on my import 
mylib; statement.  I've tried every permutation of -I and -L 
that I can think of.  It almost appears that one either uses 
dub for everything or nothing and I'm getting pretty frustrated 
with it as well.  Perhaps I should just go back to 
old-fashioned make files?


you can instruct dub to use other compilers with the --compiler 
option

valid options include dmd,ldc,gdc,gdmd,ldmd


Re: Program exited with code -11

2015-06-24 Thread weaselcat via Digitalmars-d-learn

On Wednesday, 24 June 2015 at 07:52:10 UTC, Charles Hawkins wrote:

On Wednesday, 24 June 2015 at 06:54:57 UTC, weaselcat wrote:
On Tuesday, 23 June 2015 at 06:50:28 UTC, Charles Hawkins 
wrote:

[...]


you can instruct dub to use other compilers with the 
--compiler option

valid options include dmd,ldc,gdc,gdmd,ldmd


Ah, a sort of hidden option.  I've only been typing dub and 
thus, dub --help.  Didn't think to do dub build --help.


Is there a quick way to get gdc to recognize 
std.experimental.logger?  I'm already spoiled by it.  Choosing 
between it and a backtrace is difficult.


I believe it's available as a dub package albeit outdated, should 
be roughly similar though.


Re: Program exited with code -11

2015-06-22 Thread weaselcat via Digitalmars-d-learn

On Tuesday, 23 June 2015 at 03:29:14 UTC, Charles Hawkins wrote:
Thanks, Adam.  I'm coming from OCaml and haven't seen a seg 
fault in years.  Didn't recognize it. :D  Hopefully I can 
figure it out from here.


Try to compile with either ldc or gdc and the -g flag, it should 
give you a backtrace. dmd seems to not like linux wrt backtraces.


Re: Does anyone get line numbers in stack traces on Linux?

2015-06-17 Thread weaselcat via Digitalmars-d-learn

On Wednesday, 17 June 2015 at 11:07:29 UTC, weaselcat wrote:

On Wednesday, 17 June 2015 at 07:53:16 UTC, Atila Neves wrote:
I thought it was because I was weird and I use gold as my 
linker, but ld.bfd produced the same results. The most I could 
find in bug reports was someone complaining it used to work 
but the consensus was that it never did?


Atila


addr2line


BTW, I use the backtrace API from glibc to dump a stack trace 
that is filtered through addr2line and demangled.


Re: Does anyone get line numbers in stack traces on Linux?

2015-06-17 Thread weaselcat via Digitalmars-d-learn

On Wednesday, 17 June 2015 at 07:53:16 UTC, Atila Neves wrote:
I thought it was because I was weird and I use gold as my 
linker, but ld.bfd produced the same results. The most I could 
find in bug reports was someone complaining it used to work but 
the consensus was that it never did?


Atila


addr2line


Re: AMD Windows 7

2015-06-12 Thread weaselcat via Digitalmars-d-learn

On Friday, 12 June 2015 at 10:54:46 UTC, Chris wrote:
Has anyone run into problems with D on AMD processors? I'm 
talking about Windows 7 on a HP625 laptop in particular.


Can you be any more specific? What kind of problems?


Re: Shortest way to allocate an array and initialize it with a specific value.

2015-06-11 Thread weaselcat via Digitalmars-d-learn

On Thursday, 11 June 2015 at 07:57:47 UTC, Per Nordlöw wrote:

On Wednesday, 10 June 2015 at 22:03:52 UTC, Ali Çehreli wrote:

Another option:

void main()
{
   auto a2 = new ubyte[5];


But this causes an extra zero-initialization of a2.


just an fyi, gdc optimizes this away(looks like it overwrites the 
typeinfo,) ldc does not.


Re: Python's features, which requires D

2015-05-23 Thread weaselcat via Digitalmars-d-learn

On Friday, 22 May 2015 at 00:23:30 UTC, Dennis Ritchie wrote:

Hi,
I've collected some of Python's features. It seems to me that 
they are not in the D!


Surely all this is in the D? :)
http://rextester.com/CNQQR


After another review, I think some of these conversions to D 
could be expressed much easier if the built-in slice had 
multidimensional slicing


It was added in 2.066* but I don't think there's any plans to add 
support for it to slices.


* - you can see an example at 
http://denis-sh.bitbucket.org/unstandard/unstd.multidimarray.html


Re: How to append range to array?

2015-05-23 Thread weaselcat via Digitalmars-d-learn
On Saturday, 23 May 2015 at 07:03:35 UTC, Vladimir Panteleev 
wrote:

int[] arr = [1, 2, 3];
auto r = iota(4, 10);
// ???
assert(equal(arr, iota(1, 10)));


import std.array : array;
arr ~ r.array;


Re: How to append range to array?

2015-05-23 Thread weaselcat via Digitalmars-d-learn

On Saturday, 23 May 2015 at 08:35:45 UTC, weaselcat wrote:
On Saturday, 23 May 2015 at 07:03:35 UTC, Vladimir Panteleev 
wrote:

int[] arr = [1, 2, 3];
auto r = iota(4, 10);
// ???
assert(equal(arr, iota(1, 10)));


import std.array : array;
arr ~ r.array;


woops, meant ~=

but this is probably fairly inefficient. Working with ranges and
arrays at the same time feels really badly designed.


Re: Dual conditions in D and Python

2015-05-23 Thread weaselcat via Digitalmars-d-learn
On Saturday, 23 May 2015 at 17:17:17 UTC, Andrei Alexandrescu 
wrote:

On 5/21/15 2:35 PM, Ali Çehreli wrote:

On 05/21/2015 12:44 PM, Meta wrote:

All we need is user-defined opIs and then we're really 
cooking with gas.


if (5 is between(4, 6))
{
//...
}



We're almost there. :)

bool is_between(T0, T1, T2)(T0 what, T1 min, T2 max)
{
return (what = min)  (what = max);
}

void main()
{
if (5.is_between(4, 6)) {
// ...
}
}


In fact we'll be there with 2.068:

http://dlang.org/phobos-prerelease/std_algorithm_sorting.html#.ordered

if (ordered(4, 5, 6)) { ... }
if (strictlyOrdered(4, 5, 6)) { ... }


Andrei


I didn't realize this got pulled, I remember it being discussed a 
while back on the general NG. Good addition.


Re: Dual conditions in D and Python

2015-05-21 Thread weaselcat via Digitalmars-d-learn

On Thursday, 21 May 2015 at 23:14:47 UTC, Dennis Ritchie wrote:

On Thursday, 21 May 2015 at 21:35:22 UTC, Ali Çehreli wrote:

We're almost there. :)

bool is_between(T0, T1, T2)(T0 what, T1 min, T2 max)
{
   return (what = min)  (what = max);
}

void main()
{
   if (5.is_between(4, 6)) {
   // ...
   }
}

Ali


A condition is that if, for example, that? :)

if (5  2  -9  -13  10 == 10  21 != 45):
print(OK)


this looks like gibberish upon first sight and is not something 
I'd want to see in code I inherit.


Re: fwiw - quora on stroustrup/static if/D

2015-05-21 Thread weaselcat via Digitalmars-d-learn

On Thursday, 21 May 2015 at 17:36:00 UTC, Laeeth Isharc wrote:

https://www.quora.com/What-does-Bjarne-Stroustrup-think-about-different-programming-languages


The C++ standard committee already reviewed static_if
IIRC Andrei and Walter said they were being incredibly unfair.


http://forum.dlang.org/thread/cdgzdesltjefjvnjb...@forum.dlang.org#post-cdgzdesltjefjvnjbspk:40forum.dlang.org
pretty long thread on it if you want to dig through it.

And I'll end my post with an excerpt from the ISOCPP paper, and 
IMO the reason C++ is the way it is:


Being a new and realtively simple-to-use new feature, static_if 
would un-
doubtedly be used by many who have no need for the relatively 
small increme-

natal improvement in performance offered.


Re: Python's features, which requires D

2015-05-21 Thread weaselcat via Digitalmars-d-learn

On Friday, 22 May 2015 at 00:23:30 UTC, Dennis Ritchie wrote:

Hi,
I've collected some of Python's features. It seems to me that 
they are not in the D!


Surely all this is in the D? :)
http://rextester.com/CNQQR


D doesn't have list comprehensions, so it's difficult to directly 
port these.
off the top of my head, the last one can easily be done with 
std.range.stride


P.S. I think that all of this is written in D is much more lines 
of code!

and they can be done in less with APL and J.


Re: Python's features, which requires D

2015-05-21 Thread weaselcat via Digitalmars-d-learn

On Friday, 22 May 2015 at 01:52:30 UTC, Dennis Ritchie wrote:

On Friday, 22 May 2015 at 01:17:17 UTC, weaselcat wrote:
D doesn't have list comprehensions, so it's difficult to 
directly port these.


I can not imagine how difficult it is to implement it in D, but 
I'm pretty sure that nested for loops to fill arrays (in D, you 
can call them differently, for example, force :)) will be very 
useful thing, because Python is a veryIt is often used.
Besides, I do not understand what could be the problem with 
nested loops in arrays, because std.algorithm.map works on the 
principle of nested loops. I think that the biggest problem in 
the implementation of this should not be. Excuse me if I'm 
wrong.


off the top of my head, the last one can easily be done with 
std.range.stride


import std.stdio, std.range;

void main()
{
int[] a = [ 1, 2, 3, 4, 5, 6 ];

writeln(stride(a, 2)); // [1, 3, 5] #odd #print(x[::2]) #OK
// [2, 4, 6] #even #print(x[1::2]) #no equivalent in D

writeln(stride(a[1..$], 2));


auto x = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
// [2, 6, 10] #print(x[1::4]) #no equivalent in D

writeln(stride(a[1..$], 4));

}




Re: opIndex vs. opSlice for empty slices

2015-05-21 Thread weaselcat via Digitalmars-d-learn

On Friday, 22 May 2015 at 05:47:28 UTC, Mike Parker wrote:
I've always used opSlice to produce empty slices, but having 
recently read the documentation at [1], I see this:


To overload a[], simply define opIndex with no parameters:

And no mention that opSlice can fill the same role. Am I right 
to infer that we should prefer opIndex over opSlice for this? 
If so, what's the rationale?



[1] http://dlang.org/operatoroverloading.html#slice


http://forum.dlang.org/thread/luadir$t0g$1...@digitalmars.com#post-luadir:24t0g:241:40digitalmars.com


Re: functors with template lambdas

2015-05-15 Thread weaselcat via Digitalmars-d-learn

On Saturday, 16 May 2015 at 02:06:45 UTC, weaselcat wrote:

very long standing compiler bug
https://issues.dlang.org/show_bug.cgi?id=3051


see also
https://issues.dlang.org/show_bug.cgi?id=5710

unsure if they're duplicate bugs, never really looked into it.


Re: functors with template lambdas

2015-05-15 Thread weaselcat via Digitalmars-d-learn

On Saturday, 16 May 2015 at 02:04:39 UTC, Vlad Levenfeld wrote:

I think this code should be allowed, but it isn't:

struct Functor (T)
{
T a;

auto ref fmap (alias f)()
{
return Functor (f(a));
}
}

auto ref identity (T)(auto ref T a)
{
return a;
}

void main()
{
Functor!int a;

static auto id (T)(T x)
{return x;}

a.fmap!identity; // ok

a.fmap!id; // ok

a.fmap!((int x) = x); // ok

		a.fmap!(x = x); // Error: template instance fmap!((x) = x) 
cannot use local '__lambda1' as parameter to non-global 
template fmap(alias f)()

}

This seems like one of those things that doesn't work because 
of some compiler implementation detail rather than a 
consequence of the language rules but I'm not sure. Opinion?


very long standing compiler bug
https://issues.dlang.org/show_bug.cgi?id=3051


Re: problem with parallel foreach

2015-05-13 Thread weaselcat via Digitalmars-d-learn

On Wednesday, 13 May 2015 at 09:01:05 UTC, Gerald Jansen wrote:

On Wednesday, 13 May 2015 at 03:19:17 UTC, thedeemon wrote:
In case of Python's parallel.Pool() separate processes do the 
work without any synchronization issues. In case of D's 
std.parallelism it's just threads inside one process and they 
do fight for some locks, thus this result.


Okay, so to do something equivalent I would need to use 
std.process. My next question is how to pass the common data to 
the sub-processes. In the Python approach I guess this is 
automatically looked after by pickling serialization. Is there 
something similar in D? Alternatively, would the use of 
std.mmfile to temporarily store the common data be a reasonable 
approach?


Assuming you're on a POSIX compliant platform, you would just 
take advantage of fork()'s shared memory model and pipes - i.e, 
read the data, then fork in a loop to process it, then use pipes 
to communicate. It ran about 3x faster for me by doing this, and 
obviously scales with the workloads you have(the provided data 
only seems to have 2.) If you could provide a larger dataset and 
the python implementation, that would be great.


I'm actually surprised and disappointed that there isn't a 
fork()-backend to std.process OR std.parallel. You have to use 
stdc


Re: Memory usage tracking

2015-05-10 Thread weaselcat via Digitalmars-d-learn

On Sunday, 10 May 2015 at 10:43:37 UTC, tcak wrote:

On Sunday, 10 May 2015 at 09:44:42 UTC, tcak wrote:
I am testing my web server right now. I started 5 separate 
consoles and continuously sending request by using curl to 
it.


It uses shared memory as well, thought from `ipcs -a`, I don't 
see more than necessary amount of allocation.


At the moment, server received about 1.5M requests, and memory 
usage has reached to 128MB according to System Monitor of 
Ubuntu. (top gives a similar value as well). I saw now on 
`top` command that about 650KB shared memory is used only.


Is there any way to find out what is using that big space in 
memory? Would `-profile` do that?


Problem is that if I was to be using `-profile` flag, server 
would slow down, and I wouldn't be able to test it correctly 
already.


Hmm. Server was compiled in debug mode. Right now, it is 2.2M 
requests, and 174MB memory is in use.


Which compiler are you using? Also, debug mode might have linked 
against debug phobos - do a ldd on your executable.


Re: Cannot find -lphobos

2015-05-10 Thread weaselcat via Digitalmars-d-learn

On Sunday, 10 May 2015 at 14:41:17 UTC, Ali Çehreli wrote:

On 05/10/2015 12:45 AM, Marko Grdinic wrote:
I works just fine on Windows, but I am having difficulty 
figuring out
what the trouble is on my Bodhi 1.4 Virtual Box. I've followed 
the
instruction on the Codeblocks Wiki and set the parameters, but 
when I

try to compile, it complains that it can't find Phobos.

/usr/bin/ld: cannot find -lphobos2

I've checked the search directories and the library 
directories are
where it says they would be. I am not particularly familiar 
with Linux

so I am not sure how to proceed from here.

Any advice?


dmd's -v flag may give some clues:

  $ dmd foo.d -v

dmd outputs the config file that it uses and the linker flags 
that it passes.


Ali


additionally if not using dmd it may have the libraries named 
differently.
a quick google says Bodhi linux is based on Ubuntu which doesn't 
ship dmd due to licensing issues AFAIK.


Re: Signs by which to recognize D1

2015-05-06 Thread weaselcat via Digitalmars-d-learn

On Wednesday, 6 May 2015 at 07:56:53 UTC, Daren Scot Wilson wrote:
Someone looks at a chunk of D code of murky origin.  Possibly, 
it is old, maybe D1 not D2.  Inadequately commented, believe it 
or not, and not other information.


What are some easy to spot details in the syntax by which the 
onlooker can know it's D1 not D2?


a lot of keywords(pure,nothrow, shared, etc) aren't available in 
D1 afaik, you generally see those sprinkled all over any modern D 
code.


Re: Destruction in D

2015-04-30 Thread weaselcat via Digitalmars-d-learn

On Thursday, 30 April 2015 at 20:07:11 UTC, bitwise wrote:
After reading GC page in the reference, it seems that class 
destructors are called on a separate thread, in parallel to the 
main thread. Is this correct?


There's no guarantee what thread will be used in the standard GC 
implementation AFAIK.




What about structs? Are the destructors called when they go out 
of scope in a C++ RAII fashion, or do they happen on a separate 
thread too?


If they're on the stack(not allocated with `new`), then they have 
their destructor called upon leaving scope ala C++ RAII, 
otherwise see above.


Re: Create a case-insensitive startsWith

2015-04-28 Thread weaselcat via Digitalmars-d-learn

On Tuesday, 28 April 2015 at 21:45:10 UTC, PhilipDaniels wrote:

Beginner question. Given

  if (startsWith(input, 0x, 0X))

How do I turn that into a case-insensitive startsWith? 
startsWith says it takes a predicate but I can't figure out how 
to pass it one. The examples all use a == b !? These attempts 
below, and other things I have tried, fail with cannot deduce 
function from argument types.


  if (startsWith!icmp(a, b) == 0(input, 0x))
  if (startsWith!std.uni.icmp(a, b) == 0(input, 0x))
  if (startsWith!((a,b) = icmp(a,b) == 0)(input, 0x))


I believe the issue is that the predicate expects a boolean, icmp 
returns an int. Try a == toLower(b) as your predicate(there's 
probably a better solution somewhere hidden in phobos though.)


Re: std.json questions

2015-04-26 Thread weaselcat via Digitalmars-d-learn

On Sunday, 26 April 2015 at 17:14:22 UTC, extrawurst wrote:

On Saturday, 25 April 2015 at 18:30:33 UTC, Baz wrote:

On Saturday, 25 April 2015 at 09:56:25 UTC, tired_eyes wrote:
I think this is ugly and clunky approach, what is the 
beautiful one?


What you clearly need is a serializer:

look at these:

http://wiki.dlang.org/Libraries_and_Frameworks#Serialization

and also:

https://github.com/search?utf8=✓q=serializer+language%3ADtype=Repositoriesref=searchresults

some of them might have an API to save load an object or a 
struct in a single call.


too bad D:YAML links are broken, do you know where to find that 
project ?


https://github.com/kiith-sa/D-YAML


Re: Structural exhaustive matching

2015-04-22 Thread weaselcat via Digitalmars-d-learn

On Wednesday, 22 April 2015 at 04:54:39 UTC, Martin Nowak wrote:

On Tuesday, 21 April 2015 at 15:36:28 UTC, Jadbox wrote:
What's the best equivalent to Rust's structural enum/pattern 
(match)ing? Is it also possible to enforce exhaustive matches? 
Basically, I'm curious on what the best way to do ADTs in D.


If it needs to be really fast, use final switch on the tag of a 
discriminated union.


enum Tag { A, B, C }
struct Val
{
  Tag tag;
  union
  {
A a;
B b;
C c;
  }
}

void too(Val val)
{
  final switch (val.tag)
  {
  case Tag.A: writeln(val.a); break;
  case Tag.B: writeln(val.b); break;
  case Tag.C: writeln(val.c); break;
  }
}


there's no reason this should be faster than Algebraic(restricted 
variant) from std.variant, is there? implementation issue?


Re: Structural exhaustive matching

2015-04-21 Thread weaselcat via Digitalmars-d-learn

On Tuesday, 21 April 2015 at 15:36:28 UTC, Jadbox wrote:
What's the best equivalent to Rust's structural enum/pattern 
(match)ing? Is it also possible to enforce exhaustive matches? 
Basically, I'm curious on what the best way to do ADTs in D.


D's ADTs are in std.variant, the equivalent of matching is the 
.visit property AFAIK


Re: Reading whitespace separated strings from stdin?

2015-04-20 Thread weaselcat via Digitalmars-d-learn

On Tuesday, 21 April 2015 at 01:31:58 UTC, TheGag96 wrote:
Hi guys! I had this homework assignment for data structures 
that has a pretty easy solution in C++. Reading input like 
this...


1 2 3 # $
4 3 * ! #
20 3 / # $ #
62 # $
2 3 8 * + #
4 48 4 2 + / #
SUM # $
1 2 3 4 5 #
R #
@

...where @ denotes the end of input is fairly simple in C++:

string token = ;
while (token != @) {
  //handle input
}

Note that having newlines doesn't matter at all; every token is 
just assumed to be separated by whitespace. However in D, I 
looked around could not find a solution better than this:


foreach (line; stdin.byLine) {
  foreach (token; line.split) {
//handle input
  }
}

Is there any way to do this without two loops/creating an 
array? readf( %d, token); wasn't cutting it either.


Thanks.


import std.stdio;
import std.array;
void main(){
auto tokens = stdin.readln('@').split;
writeln(tokens);
}

[1, 2, 3, #, $, 4, 3, *, !, #, 20, 3, 
/, #, $, #, 62, #, $, 2, 3, 8, *, +, #, 
4, 48, 4, 2, +, /, #, SUM, #, $, 1, 2, 
3, 4, 5, #, R, #, @]


Re: Maxime's micro allocation benchmark much faster ?

2015-03-31 Thread weaselcat via Digitalmars-d-learn

On Tuesday, 31 March 2015 at 20:56:09 UTC, Laeeth Isharc wrote:
Trying on a different beefier machine with 2.066 and 2.067 
release versions installed:


1mm allocations:
2.066: 0.844s
2.067: 0.19s

10mm allocations

2.066: 1m 17.2 s
2.067: 0m  1.15s

So numbers were ballpark right before, and allocation on this 
micro-benchmark much faster.


Wow! props to the people that worked on the GC.


using exceptions in @nogc

2015-03-30 Thread weaselcat via Digitalmars-d-learn

was this ever solved?
I did some research and saw static immutable ones suggested a few 
times, but they can't be chained AFAIK.


Re: using exceptions in @nogc

2015-03-30 Thread weaselcat via Digitalmars-d-learn

On Tuesday, 31 March 2015 at 03:12:42 UTC, ketmar wrote:

On Tue, 31 Mar 2015 01:40:52 +, weaselcat wrote:


was this ever solved?


nope. there were some suggestions, but no decision was made.


sigh
do you know if there's an open enhancement request for this?


Re: Passing myself, a struct, as a C callback context

2015-03-29 Thread weaselcat via Digitalmars-d-learn

On Monday, 30 March 2015 at 02:53:36 UTC, Paul O'Neil wrote:


As of dmd 2.067, doing this is deprecated.


where is this documented? I don't see it in the release notes.


Re: Passing myself, a struct, as a C callback context

2015-03-29 Thread weaselcat via Digitalmars-d-learn

On Monday, 30 March 2015 at 03:02:07 UTC, Paul O'Neil wrote:

On 03/29/2015 10:57 PM, weaselcat wrote:

On Monday, 30 March 2015 at 02:53:36 UTC, Paul O'Neil wrote:


As of dmd 2.067, doing this is deprecated.


where is this documented? I don't see it in the release notes.


I don't see it in the release notes either, but it's happening.
 Maybe
it's an instance of a more general thing?


if it works in 2.066 you should submit a bug report, either this 
shouldn't be a deprecation or it should be in the release notes.


Re: D's type classes pattern ?

2015-03-24 Thread weaselcat via Digitalmars-d-learn

On Tuesday, 24 March 2015 at 15:51:00 UTC, matovitch wrote:

Hi,

It's been a long time since I coded some d code... sorry I take
the lazy way asking for advices. :D

Lets say I want to implement some generic algorithm. I would 
like

to checks the types passed to my algorithm implements a specific
interface.

interface IStuff(Stuff)
{
 void foo();
}

class TypeClass(T, I) : I(T)
{
 alias this T;
}

void myAwesomeAlgo(Stuff) (TypeClass!(Stuff, IStuff) stuff)
{
 stuff.foo();
}


Well it seems that I have worked out my question in trying to
formulate it...Would something like this work ?


interface Foo{
}
void Bar(T : Foo)(T t){
}

but interfaces enable runtime polymorphism, you can just accept 
the interface itself

void Fun(Foo foo){
}


Re: Template reference parameter

2015-03-23 Thread weaselcat via Digitalmars-d-learn

On Monday, 23 March 2015 at 22:39:28 UTC, rumbu wrote:

I have only one template and I think it's impossible to define 
specializations since it's supposed that a random member of 
A... will be passed sometime by reference:


auto ref?
http://dlang.org/template.html#auto-ref-parameters


Re: final methods by default

2015-03-20 Thread weaselcat via Digitalmars-d-learn

On Friday, 20 March 2015 at 14:25:22 UTC, ref2401 wrote:

Why aren't methods of class final by default?


history

use final class, it should devirtualize all methods.
see: https://github.com/D-Programming-Language/dmd/pull/4427


Re: Dlang seems like java now,but why not let d more like C# Style?

2015-03-14 Thread weaselcat via Digitalmars-d-learn

On Saturday, 14 March 2015 at 23:46:28 UTC, Ellery Newcomer wrote:
And C# has LINQ, which when combined with the last point is 
fricken awesome.


what does LINQ offer that UFCS-style functional programming does 
not?


Re: Memoization in compile-time

2015-03-13 Thread weaselcat via Digitalmars-d-learn

On Friday, 13 March 2015 at 13:16:27 UTC, weaselcat wrote:

On Friday, 13 March 2015 at 12:49:48 UTC, Dennis Ritchie wrote:
On Friday, 13 March 2015 at 02:38:18 UTC, Rikki Cattermole 
wrote:
You could assign it to e.g. an enum. Or force it over using 
meta-programming.


And this code can be rewritten to D?

template int n
struct Factorial
{
   enum { value = n * Factorialn - 1::value };
};

template 
struct Factorial0
{
   enum { value = 1 };
};

int main()
{
   constexpr auto x = Factorial5::value;
   constexpr auto y = Factorial7::value;
}


confusingly, D uses enum for named compile-time constants.
http://ddili.org/ders/d.en/enum.html

If you take Rikki's example and apply it to an enum(i.e,
enum x = factorial(5);
)

the program will fail to compile if it can't be computed at 
compile-time.


woops, walked away to get coffee before I submitted and got
beaten to the punch by a better answer : )


Re: Memoization in compile-time

2015-03-13 Thread weaselcat via Digitalmars-d-learn

On Friday, 13 March 2015 at 12:49:48 UTC, Dennis Ritchie wrote:
On Friday, 13 March 2015 at 02:38:18 UTC, Rikki Cattermole 
wrote:
You could assign it to e.g. an enum. Or force it over using 
meta-programming.


And this code can be rewritten to D?

template int n
struct Factorial
{
enum { value = n * Factorialn - 1::value };
};

template 
struct Factorial0
{
enum { value = 1 };
};

int main()
{
constexpr auto x = Factorial5::value;
constexpr auto y = Factorial7::value;
}


confusingly, D uses enum for named compile-time constants.
http://ddili.org/ders/d.en/enum.html

If you take Rikki's example and apply it to an enum(i.e,
enum x = factorial(5);
)

the program will fail to compile if it can't be computed at 
compile-time.


Re: moving from c++ to D is easy?

2015-03-12 Thread weaselcat via Digitalmars-d-learn

On Thursday, 12 March 2015 at 13:01:31 UTC, ayush wrote:
Is D a lot like c++ ? I am currently midway through learning 
c++ and I also want to learn D . So should i focus on one or 
learn both together? Will I find learning D easy if I already 
know c++ ?


D is very much like C++, but the biggest issue I found moving 
from C++ to D was trying to apply C++ idioms that only existed to 
work around ugly C++ warts(i.e, CRTP)


Re: auto function attributes based on type

2015-03-12 Thread weaselcat via Digitalmars-d-learn

On Thursday, 12 March 2015 at 05:01:50 UTC, amber wrote:

On Thursday, 12 March 2015 at 04:51:42 UTC, amber wrote:

On Thursday, 12 March 2015 at 04:04:28 UTC, weaselcat wrote:

On Thursday, 12 March 2015 at 03:12:15 UTC, amber wrote:

...
http://dlang.org/function.html#function-attribute-inference 
might be a good read if you haven't read it already.


I did read it but didn't really understand it, so I've come to 
D.learn for more help.


I think it means I can just write the function like so:

struct S(T) {
   someFunc(int i) {// impl}
}

and if possible it will be pure, nothrow, @safe and @nogc.



thanks,
amber


This works nicely after checking with 
__traits(getFunctionAttributes, S!T.someFunc)


Very cool :)

bye,
amber


You can also use the __PRETTY_FUNCTION__ keyword to display 
information about a function.

http://dlang.org/traits.html#specialkeywords


Re: auto function attributes based on type

2015-03-11 Thread weaselcat via Digitalmars-d-learn

On Thursday, 12 March 2015 at 03:12:15 UTC, amber wrote:

...
http://dlang.org/function.html#function-attribute-inference might 
be a good read if you haven't read it already.


Re: is struct delete deterministic? (cf used in Unique)

2015-03-07 Thread weaselcat via Digitalmars-d-learn

On Saturday, 7 March 2015 at 23:48:39 UTC, Timothee Cour wrote:

I'm a little confused about the following:
clear,delete,destroy.
My understanding is that clear is deprecated and delete is 
planned to be
deprecated, so we should only ever use destroy (which 
deterministic calls

the destructor but doesn't release memory).

Unique uses delete however in the destructor. Is that still 
guaranteeing
deterministic destruction when the uniqued element is either a 
class or
struct? (ie if the destructor has a file handle resource, will 
it be

deterministically freed?)


structs are allocated on the stack(unless instantiated with new), 
and call their destructor when you leave their scope. Unique 
still guarantees deterministic destruction because it's wrapped 
around a struct, it's a fairly common 'D idiom' I'd say(i.e, look 
at how File is implemented - D's runtime and standard library are 
surprisingly well documented and easy to read.)


I'm not sure why Unique uses delete, might just be bitrot.


Is std.signals deprecated?

2015-03-05 Thread weaselcat via Digitalmars-d-learn
Seems barely maintained and there was a proposed replacement 
claiming it was broken(http://wiki.dlang.org/Review/std.signal) 
that never got approved.


Is std.signals worth using over a dub package?


Re: Will D have a serious dedicated well supported IDE like Visual Studio or Eclipse?

2015-02-26 Thread weaselcat via Digitalmars-d-learn

On Friday, 27 February 2015 at 04:12:50 UTC, AJ wrote:

On Thursday, 26 February 2015 at 20:23:10 UTC, Rinzler wrote:
I a beginner with D, actually I have almost done nothing. I am 
using a Mac, and Xamarin Studio seem to be the best choice, 
but I am not even able to make it auto-complete the standard 
library. Does anybody know how to do it?


I am in the same boat and totally agree.  It's tough going from 
the user-experience of IntelliJ IDEA or Visual Studio back to 
vi on OS X with D.  There seems to be a large hole in support 
for D debugging outside of Visual D (line numbers, variable 
values, etc).  I was hoping to use D for a new project, but I 
don't feel the tools are ready yet.


GDB works fine with D, I use it regularly.
http://wiki.dlang.org/Open_Source_Projects#Debugging_support_by_compiler:


Re: What is the Correct way to Malloc in @nogc section?

2015-02-14 Thread weaselcat via Digitalmars-d-learn

On Saturday, 14 February 2015 at 06:38:19 UTC, ketmar wrote:

On Sat, 14 Feb 2015 00:57:33 +, weaselcat wrote:


On Friday, 13 February 2015 at 22:55:27 UTC, anonymous wrote:

On Thursday, 12 February 2015 at 23:52:41 UTC, Foo wrote:

This is something I've done recently.
Would be glad if my code will help you: 
https://github.com/Dgame/m3

Especially the m3.d module could be useful for you.


/* Class and Struct */

emplace: You can't assume zero-initialization for structs. 
destruct: Is

not memory-safe, and must not be marked @trusted.

/* Array */

make: You can't assume zero-initialization. T.sizeof is not 
the size of

an element.
reserve: Not safe (you're freeing the old memory), must not be
@trusted.
append: T.sizeof is not the size of an element. You're 
multiplying

twice with T.sizeof; in `append`, and also in `reserve`.
destruct: Not safe, must not be @trusted.


Low level memory management isn't easy.
Bugs like these wouldn't exist if D had decent smart pointer
implementations in its standard library. You seem 
knowledgeable enough,

care to lend a hand? ; )


how smart pointers can help here? they don't magically hiding 
all the

low-level mechanics.


The file he was referring to was a smart pointer implementation.


Re: What is the Correct way to Malloc in @nogc section?

2015-02-13 Thread weaselcat via Digitalmars-d-learn

On Friday, 13 February 2015 at 22:55:27 UTC, anonymous wrote:

On Thursday, 12 February 2015 at 23:52:41 UTC, Foo wrote:

This is something I've done recently.
Would be glad if my code will help you:
https://github.com/Dgame/m3
Especially the m3.d module could be useful for you.


/* Class and Struct */

emplace: You can't assume zero-initialization for structs.
destruct: Is not memory-safe, and must not be marked @trusted.

/* Array */

make: You can't assume zero-initialization. T.sizeof is not the 
size of an element.
reserve: Not safe (you're freeing the old memory), must not be 
@trusted.
append: T.sizeof is not the size of an element. You're 
multiplying twice with T.sizeof; in `append`, and also in 
`reserve`.

destruct: Not safe, must not be @trusted.


Low level memory management isn't easy.
Bugs like these wouldn't exist if D had decent smart pointer 
implementations in its standard library. You seem knowledgeable 
enough, care to lend a hand? ; )


Re: GC has a barbaric destroyng model, I think

2015-02-12 Thread weaselcat via Digitalmars-d-learn

On Thursday, 12 February 2015 at 08:33:35 UTC, Kagamin wrote:
Truth be told, D has no guideline for deterministic destruction 
of managed resources.


+1

don't complain about people wondering why class destructors don't 
work when there's no _real_ way to do it in D beyond 'drop down 
to C level and get going.' D is absolutely horrid for resource 
management.


Question about scope of @nogc

2015-02-11 Thread weaselcat via Digitalmars-d-learn

(Scope might have been a bad word choice...)

Is @nogc intended to only stop from calling functions that 
allocate with the GC, or from interacting with the GC altogether? 
Is there a technical reason that functions such as addrange, etc 
cannot be @nogc if the former since AFAIK such functions do not 
allocate.


Thanks.


Re: Intended to be able to RefCount an interface?

2015-02-09 Thread weaselcat via Digitalmars-d-learn

On Tuesday, 10 February 2015 at 05:09:00 UTC, Jakob Ovrum wrote:

On Tuesday, 10 February 2015 at 04:44:55 UTC, weaselcat wrote:

Thread title.


interface Itest{

}

class testclass : Itest{
}

void main()
{
   import std.typecons;
   auto test = RefCounted!Itest(new testclass());
}

If you change the refcounted to type testclass it doesn't 
compile because refcounted doesn't support classes.


Is this a bug, or intended?


I think this is a bug, and that the current RefCounted needs to 
reject interfaces.


I assumed as much, thanks.

AFAIK, it is intended that RefCounted!SomeClass is supposed to 
reference-count the actual class instance, not its reference, 
which is what RefCounted!SomeInterface currently does.


Is there currently an enhancement request open for this on the 
bug tracker? I cannot find anything.


Intended to be able to RefCount an interface?

2015-02-09 Thread weaselcat via Digitalmars-d-learn

Thread title.


interface Itest{

}

class testclass : Itest{
}

void main()
{
import std.typecons;
auto test = RefCounted!Itest(new testclass());
}

If you change the refcounted to type testclass it doesn't compile 
because refcounted doesn't support classes.


Is this a bug, or intended?


Re: How to write asia characters on console?

2015-02-07 Thread weaselcat via Digitalmars-d-learn

On Sunday, 8 February 2015 at 05:57:31 UTC, Lave Zhang wrote:

Hi,

My first D program is like this:
---
import std.stdio;

void main(string[] args)
{
  dstring s1 = hello你好d;
  writeln(s1);
}
---
But the output is not correct(and my console codepage is 936):

C:\D\dmd2\samples\ddmd hello.d -offilename hello.exe
C:\D\dmd2\samples\dhello.exe
hello浣犲ソ

thanks.


Hi,
I tried your code and it works fine for me. I think the windows 
console only supports UTF-16, try using wchar/wstring instead of 
dchar/dstring.


Re: Better native D 2D graphics library?

2015-02-07 Thread weaselcat via Digitalmars-d-learn

On Saturday, 7 February 2015 at 22:09:03 UTC, Gan wrote:

Is there a better D graphics library in the works?

I'm using SFML(which is very easy and has lots of features) but 
it seems to use a lot of ram(if you leave it running for a 
while on a graphic intensive scene) and trying to make it 
include the dependencies with the compiled executable is 
complicated.


Is there a D 2D graphics library that's just as easy, cross 
platform, doesn't use X11, allows drawing to off-screen buffers 
and drawing those to screen? (plus supports nice drawing of 
shapes, circles, rectangles, lines)


I'm probably asking too much- I doubt such a thing exists.


Not what you're asking for, but you could always use SDL - I 
believe it has two or three bindings to D. Check on dub.


I doubt you're going to find anything like SFML written in D as 
it's a lot of work to maintain such a project, and just 
duplication of effort. It's why most projects in most languages 
just wrap SDL in some form.


Re: ubyte array to uint?

2015-02-05 Thread weaselcat via Digitalmars-d-learn

On Friday, 6 February 2015 at 05:18:45 UTC, Gan wrote:

Is there a simple way of conversion? Something like:
uint length = to!uint(buffer[0 .. 4]);

Right now I have:
uint length = *cast(uint*)buffer[0 .. 4].ptr;

Which I'm not entirely sure is the correct way to do that.


Hi,

check out std.bitmanip.read

http://dlang.org/phobos/std_bitmanip.html#.read


Re: When to use typecons.proxy vs alias this?

2015-01-24 Thread weaselcat via Digitalmars-d-learn

On Sunday, 25 January 2015 at 03:55:18 UTC, Adam D. Ruppe wrote:

Use alias this if you want implicit conversions too.

Proxy keeps the types separate

void foo(Base b) { }

struct Modified {
   Base b;
   alias b this;
}

foo(Modified()); //works


That wouldn't work if it was proxied though, which you 
sometimes want to force everything to go through your 
modification.


So the only difference is that proxy doesn't have implicit 
conversions? Hm. Might be worth pointing out on the docs.


When to use typecons.proxy vs alias this?

2015-01-24 Thread weaselcat via Digitalmars-d-learn
I can't find much documentation/usage of typecons.proxy, but it 
seems extremely similar to alias this.
The documentation page( 
http://dlang.org/library/std/typecons/proxy.html ) doesn't really 
seem to elaborate on this at all.


Re: On Variable References

2015-01-21 Thread weaselcat via Digitalmars-d-learn

On Wednesday, 21 January 2015 at 17:14:29 UTC, Meta wrote:
On Wednesday, 21 January 2015 at 08:23:44 UTC, Per Nordlöw 
wrote:
On Wednesday, 21 January 2015 at 08:22:44 UTC, Per Nordlöw 
wrote:

  int x;
  auto ref xr;


Correction: I, of course mean,

   int x = 42;
   auto ref xr = x;


Walter is strongly against adding references a la C++ to D, as 
he believes they are too complicated and bug prone. He's made 
several posts on this, but I can't find them now.


Artificial constraints like this and no default constructor 
implementations for structs makes D annoying to use for 
programming that relies heavily on deterministic resource 
management tbh.


Re: simple assignment statement compiles but becomes a run time error

2015-01-18 Thread weaselcat via Digitalmars-d-learn

On Sunday, 18 January 2015 at 19:51:02 UTC, WhatMeWorry wrote:

On Sunday, 18 January 2015 at 19:42:33 UTC, WhatMeWorry wrote:


I've got a OpenGL function returning a pointer

// const GLubyte *version = glGetString(GL_VERSION);  // C++ 
and openLG code


// the following compiles with no errors or warnings

char openglVersion[100] = fromStringz(glGetString(GL_VERSION));
// ABENDS HERE!


// documentation from std.string shows
// pure @system inout(char)[] fromStringz(inout(char)* 
cString);


// Seems pretty innocuous to me.


Debugger returns:
Unhandled exception at 0x76AC2F71 (KernelBase.dll) in 
WhatVersionOfOpenGL.exe


Hi,

try replacing the fromStringz with to!string from std.conv