Create doc simultaneously with compilation

2017-02-19 Thread Satoshi via Digitalmars-d-learn
Why is not possible to create documentation, compile code and 
generate header files simultaneously?


When I pass -D and -Dd flags to ldc2 command it won't create doc 
until I don't pass -o- flag too.


Re: Force inline

2017-02-19 Thread Satoshi via Digitalmars-d-learn

On Sunday, 19 February 2017 at 19:19:25 UTC, berni wrote:

Is it possible to force a function to be inlined?

Comparing a C++ and a D program, the main difference in speed 
(about 20-30%) is, because I manage to force g++ to inline a 
function while I do not find any means to do the same on D.



Or make it as template, maybe...


void foo()() {

}


Re: Force inline

2017-02-19 Thread ag0aep6g via Digitalmars-d-learn

On Sunday, 19 February 2017 at 19:19:25 UTC, berni wrote:

Is it possible to force a function to be inlined?


https://dlang.org/spec/pragma.html#inline


Re: Force inline

2017-02-19 Thread Daniel Kozak via Digitalmars-d-learn

Dne 19.2.2017 v 20:19 berni via Digitalmars-d-learn napsal(a):


Is it possible to force a function to be inlined?

Comparing a C++ and a D program, the main difference in speed (about 
20-30%) is, because I manage to force g++ to inline a function while I 
do not find any means to do the same on D.

https://dlang.org/spec/pragma.html#inline



Re: Force inline

2017-02-19 Thread Daniel Kozak via Digitalmars-d-learn

Dne 19.2.2017 v 20:19 berni via Digitalmars-d-learn napsal(a):


Is it possible to force a function to be inlined?

Comparing a C++ and a D program, the main difference in speed (about 
20-30%) is, because I manage to force g++ to inline a function while I 
do not find any means to do the same on D.

yes
https://wiki.dlang.org/DIP56


Force inline

2017-02-19 Thread berni via Digitalmars-d-learn

Is it possible to force a function to be inlined?

Comparing a C++ and a D program, the main difference in speed 
(about 20-30%) is, because I manage to force g++ to inline a 
function while I do not find any means to do the same on D.


Re: Hello, folks! Newbie to D, have some questions!

2017-02-19 Thread bachmeier via Digitalmars-d-learn

On Saturday, 18 February 2017 at 20:15:55 UTC, timmyjose wrote:
4. I have heard good reports of D's metaprogramming 
capabilities (ironically enough, primarily from a thread on the 
Rust user group), and coming from a Common Lisp (and some 
Racket) background, I am deeply interested in this aspect. Are 
D macros as powerful as Lisp macros? Are they semantically 
similar (for instance, I found Rust's macros are quite similar 
to Racket's)?


I was a Scheme/Common Lisp user for quite a while before moving 
to D. Lisp macros are more powerful (there's not much you can't 
do with them), but on the other hand, unless you stick with 
simple use cases, it can be hard to get Lisp macros right. You've 
got the whole defmacro vs hygienic debate. Also, the rule of 
thumb is to avoid macros unless you can't do it with a function.


I was never into heavy metaprogramming with Scheme or Common 
Lisp. The simplicity of D's compile time capabilities mean I do 
more metaprogramming in D, and I actually push a lot of stuff 
from runtime to compile time, which I wouldn't have done with 
Common Lisp.


Re: Hello, folks! Newbie to D, have some questions!

2017-02-19 Thread Jacob Carlborg via Digitalmars-d-learn

On 2017-02-19 13:45, ketmar wrote:


nogc doesn't turn it off, if
says that compiler must ensure that *your* *code* doesn't allocate,


Just to clarify, allocate using the GC. It's perfectly fine to allocate 
using malloc in a @nogc function.


--
/Jacob Carlborg


Re: Hello, folks! Newbie to D, have some questions!

2017-02-19 Thread ketmar via Digitalmars-d-learn

timmyjose wrote:
I can't help here because I am using D for a long time, so I do not 
remember how I have learned it.
Hahaha! Yes, thanks for the honesty. It does make sense because once 
you've been working in some field for some time, it does make it 
harder to explain how exactly you reached that level. In that regard, 
comments from fellow newbies (such as berni) have been quite helpful 
since they're at the same stage as me.
as for me, i basically just jumped into D and started to code. sure, i 
read a little about modules, GC, slices, and such basic things, but 
then i just started to writing my code in D. one can use libc from D 
(with some care), so it allowed me to write in D as in "C dialect", and 
then gradually make my code more "D-like", as i learned more and more 
things.


Re: Hello, folks! Newbie to D, have some questions!

2017-02-19 Thread ketmar via Digitalmars-d-learn

timmyjose wrote:

a). So the GC is part of the runtime even if we specify @nogc
yes. GC is basically just a set of functions and some supporting data 
structures, it is compiled in druntime. @nogc doesn't turn it off, if 
says that compiler must ensure that *your* *code* doesn't allocate, at 
compile time. i.e. @nogc code with GC allocations won't compile at all.



b). Do we manually trigger the GC (like Java's System.gc(), even 
though that's not guaranteed), or does it get triggered automatically 
when we invoke some operations on heap allocated data and/or when the 
data go out of scope?
GC can be invoked *only* on allocation. as long as you don't allocate 
GC data, GC will not be called. of course, things like array/string 
concatenation (and closure creation) allocates, so you'd better be 
careful with your code if you want to avoid GC in some critical part. 
or you can call `GC.disable()` to completely disable GC (and 
`GC.enable()` later, of course ;-).



c). Does Rust have analogues of "new" and "delete", or does it use 
something like smart pointers by default?
`new`. no `delete`, tho, as it is not necessary with GC. actually, 
there is `delete` thingy, but it is deprecated, and you'd better not 
use it unless you are *really* know what you're doing and why. i.e. 
don't prematurely optimize your code, especially without good 
understanding of D's GC.



Fascinating reading about the various use cases that you and others 
have put D to. It does give me a lot more contextual understanding 
now. Thank you!

you're welcome.

as for me, i am using D exclusively for *all* my programming tasks 
(including writing simple shell scripts ;-) for years. and i don't want 
to go back to C/C++ or switch to some [new] hyped language. i have 20+ 
years of programming expirience, and i feel that D is the best language 
i ever used. don't get me wrong, tho: it doesn't mean that D is the 
best language on the planet. what i mean is that D has a best balance 
of features, warts, libs and so on *for* *me*. easy C interop allows me 
to use all the C libraries out there; C-like syntax allows me to port C 
code (i did alot of C ports, including NanoVG, NanoSVG, Tremor Vorbis 
decoder, Opus decoder, etc.); great metaprogramming (for C-like 
language) allows me to skip writing boilerplate code; and so on. ;-)


also, dmd compiler is easily hackable. trying to even compile gcc is a 
PITA, for example. and dmd+druntime+phobos takes ~1.5 minutes to build 
on my old i3.


Re: segmentation fault with Object.factory()

2017-02-19 Thread ag0aep6g via Digitalmars-d-learn

On 02/19/2017 12:13 PM, berni wrote:

And here is what I get when compiling:


$> rdmd test.d
segmentation fault
$> rdmd --extra-file=test2.d test.d
segmentation fault
$> rm -rf /tmp/.rdmd-1000/
$> rdmd --extra-file=test2.d test.d
A
$> rdmd -version
rdmd build 20170122
[...]


Should I report this bug anywhere (or am I wrong again?)


Looks like a bug, yes. Please report on . For 
"component" choose "tools".


Re: Hello, folks! Newbie to D, have some questions!

2017-02-19 Thread Guillaume Piolat via Digitalmars-d-learn

On Saturday, 18 February 2017 at 20:15:55 UTC, timmyjose wrote:
My rudimentary knowledge of the D ecosystem tells me that there 
is a GC in D, but that can be turned off. Is this correct? 
Also, some threads online mention that if we do turn off GC, 
some of the core std libraries may not fully work. Is this 
presumption also correct?


The topic is complex, there are a lot of mitigation techniques.

A - for most real-time programs, you may want to keep the GC heap 
under 200kb. A combination of GC profiling, using values types, 
and manual memory management can get you there. @nogc also helps.


B - some real-time threads don't like to be paused (audio). You 
can unregister them from the runtime which means the GC won't 
stop them on collection. On the other hand this thread won't be 
able to "own" collectable things.


C - finally you can either disable the runtime/GC altogether, or 
not link with it. This create the most effort but with a 
guarantee of not having a GC over the whole application. In most 
cases it's _not worth it_.


The hard part about GC is understanding reachability, but unless 
you are doing very systemy, this can be safely ignored.


You will be just fine.

Secondly, how stable is the language and how fast is the pace 
of development on D?


Language doesn't break nowadays, very stable apart from dreaded 
regressions with the DMD backends.


http://erdani.com/d/downloads.daily.png

2. I am also curious as to what would be the best path for a 
complete beginner to D to learn it effectively?


"Learning D" book seems fitting.

3. Are there some small-scale Open Source projects that you 
would recommend to peruse to get a feel for and learn idiomatic 
D?


I run https://p0nce.github.io/d-idioms/ to get up to speed with 
the weird idiosyncrasies fast. But the above book is way better.


Re: Hello, folks! Newbie to D, have some questions!

2017-02-19 Thread ag0aep6g via Digitalmars-d-learn

On 02/19/2017 12:51 PM, timmyjose wrote:

a). So the GC is part of the runtime even if we specify @nogc


Yup. @nogc is per function, not per program. Other functions are allowed 
to use the GC.



b). Do we manually trigger the GC (like Java's System.gc(), even though
that's not guaranteed), or does it get triggered automatically when we
invoke some operations on heap allocated data and/or when the data go
out of scope?


You can trigger a collection manually with GC.collect [1]. Otherwise, 
the GC can do a collection when you make a GC-managed allocation. If you 
don't make GC allocations, e.g. because you're in @nogc code and the 
compiler doesn't allow you to, then no GC collections will happen.



c). Does Rust have analogues of "new" and "delete", or does it use
something like smart pointers by default?


D, not Rust, right?

D uses `new` for GC allocations. `new` returns a raw pointer or a 
dynamic array (pointer bundled with length for bounds checking).


There is `delete`, but it's shunned/unfashionable. Maybe it's going to 
be deprecated, I don't know. You're supposed to let the GC manage 
deletion, or use `destroy` [2] and GC.free [3] if you have to do it 
manually.


Of course, you can also call C functions like `malloc` and `free` and do 
manual memory management.


Regarding smart pointers, I'm not up to speed. There's 
std.typecons.Unique [4], but I don't know how it compares to other 
languages.



[1] https://dlang.org/phobos/core_memory.html#.GC.collect
[2] https://dlang.org/phobos/object.html#.destroy
[3] https://dlang.org/phobos/core_memory.html#.GC.free


Re: Hello, folks! Newbie to D, have some questions!

2017-02-19 Thread timmyjose via Digitalmars-d-learn

On Sunday, 19 February 2017 at 11:51:02 UTC, timmyjose wrote:

On Saturday, 18 February 2017 at 21:58:15 UTC, ketmar wrote:

[...]


No, you're quite right indeed! First of all, those sound like 
very interesting project! :-), and you're right about the GC 
part. I have some experience in systems programming in C++ and 
also application development in Java. Java's GC never really 
bothered me so much, but it's quite intriguing that you (and 
one more person before) mention that the GC does not fire on 
its own. So a couple of questions here (might be a bit 
premature, but I'm interested!):


[...]


Oops! I meant D, of course. Sorry, still recovering from that 
drug. Heh!



[...]


[...]




Re: Hello, folks! Newbie to D, have some questions!

2017-02-19 Thread timmyjose via Digitalmars-d-learn

On Saturday, 18 February 2017 at 21:58:15 UTC, ketmar wrote:

timmyjose wrote:
Thanks for the very comprehensive response! I think most of my 
doubts are cleared now. You're right though that I'm probably 
worrying too much about GC with my current use case.


i can tell you that i'm doing things like, for example, ZX 
Spectrum emulator and hobbyst videogames (everything in D, even 
low-level gfx), i never really cared about "avoiding GC", and i 
can maintain solid 35/50/60 FPS (depending of my needs) with my 
code.
i.e. that "GC-phobia" (i'm not talking about you specifiallly, 
of course, sorry) is mostly based on nothing. as GC will never 
fire "on it's own", and you can control it, avoiding GC is not 
unnecessary (except some very special cases, of course ;-). the 
key tech here (as usual) is to not allocate in tight loops, 
plan your memory discipline and such. nothing new for people 
used to systems languages. ;-)


No, you're quite right indeed! First of all, those sound like 
very interesting project! :-), and you're right about the GC 
part. I have some experience in systems programming in C++ and 
also application development in Java. Java's GC never really 
bothered me so much, but it's quite intriguing that you (and one 
more person before) mention that the GC does not fire on its own. 
So a couple of questions here (might be a bit premature, but I'm 
interested!):


a). So the GC is part of the runtime even if we specify @nogc

b). Do we manually trigger the GC (like Java's System.gc(), even 
though that's not guaranteed), or does it get triggered 
automatically when we invoke some operations on heap allocated 
data and/or when the data go out of scope?


c). Does Rust have analogues of "new" and "delete", or does it 
use something like smart pointers by default?


sure, you can stop worrying about that and use D as some kind 
of scripting language too, and still have all the features like 
type checking. for things like IRC or email client i absolutely 
don't care about allocations (i.e. doing it left and right) and 
just letting GC to do it's work. my usual IRC client uptime is 
several monthes (after that it runs out of memory, but this is 
'cause it never does any cleanup on it's data, keeping all logs 
and db in memory. i am too lazy to finish it. note that is it 
not a GC fault, it is my code. ;-).


I could not agree more about the type checking bit. It's bitten 
my backside more than I care to remember (even though LLVM and 
Clang do produce better warnings than gcc IMO), and so a stronger 
type checker is always welcome! :-)


Fascinating reading about the various use cases that you and 
others have put D to. It does give me a lot more contextual 
understanding now. Thank you!


Re: Hello, folks! Newbie to D, have some questions!

2017-02-19 Thread timmyjose via Digitalmars-d-learn

On Saturday, 18 February 2017 at 21:51:34 UTC, Daniel Kozak wrote:
Dne 18.2.2017 v 21:15 timmyjose via Digitalmars-d-learn 
napsal(a):



[...]

Hi, welcome in D community


Thank you! I'm glad to be part of this excellent community!


[...]


Yes, by default D use GC. And yes there is a some part of D 
standard library which uses GC. But it is something you can 
avoid if you want. I am using D for many years and for almost 
anything and never have issue with GC.



[...]


D stability is good, really good, for many of us too good :P. I 
have been using D for many years (five or six). And right now 
there is a big effort to never break anything until it makes 
really sense.


That makes sense.

OTOH D development is quite fast. So there are many 
improvements with every release


That sounds very good indeed!


[...]
I can't help here because I am using D for a long time, so I do 
not remember how I have learned it.


Hahaha! Yes, thanks for the honesty. It does make sense because 
once you've been working in some field for some time, it does 
make it harder to explain how exactly you reached that level. In 
that regard, comments from fellow newbies (such as berni) have 
been quite helpful since they're at the same stage as me.



[...]


It is maybe not small-scale but idiomatic D code is in phobos 
itself.


Interesting! I checked out the link that ag0aep6g had shared, and 
I realised that Phobos is the name of the standard library 
itself. It should make for some interesting reading once I get 
the basics down.



[...]
I do not know Lisp macros, but AFAIK there are not semantically 
similar. OTOH D metaprogramming is really powerful and there 
has been some proposals to improve that 
https://wiki.dlang.org/DIP50


Indeed. I'm very much looking forward to learning this powerful 
template system very well!



[...]




Re: Hello, folks! Newbie to D, have some questions!

2017-02-19 Thread timmyjose via Digitalmars-d-learn

On Saturday, 18 February 2017 at 22:17:30 UTC, berni wrote:

I'm new here too (never heard of D before 2017).


Glad to meet someone else new here! :-)

c). The whole community seems infused with both the 
Feminism/SJW


I didn't tried out Rust, but that would draw me away too. 
(Incidentally it was a comment on alternatives for Rust, that 
pointed me to D.)


Absolutely! At first it didn't bother me so much, but when I 
started hanging out of the Rust user groups, I saw the evil side 
of this. People who raised this issues were being castigated and 
publicly ridiculed. That was too much even for me (I'm usually 
the "live and let live" kind of person) because it showed that 
the community over there appeared more interested in such side 
issues than focusing on building up a community based on 
technical sharing and solving technical problems. Very offputting.


2. I am also curious as to what would be the best path for a 
complete beginner to D to learn it effectively?


I started with the online version of the book of Ali Çehreli 
but after a while I decided to buy it and was impressed on its 
size (more than 700 pages!). Meanwhile I'm halfway through.


Hehe. I'm also doing the same... a few chapters in and it's 
smooth sailing so far!


At the same time I'm working on a project of mine, which I just 
started writing in C++ last december, because I couldn't find a 
better language and thought I had to bite the bullet. Meanwhile 
it's completely rewritten in D (but two lines of C code that I 
need to use a C-libraray). Whenever I came across a new concept 
in the book I tried to refactor that project using this concept.


Very nice! :-)

This approach worked very well for me. (And I appreciate this 
Learn-forum, because else I'd not dare to ask my seemingly 
silly questions.)


You wrote:

... area thoroughly!The introspection ...


I just realised, how much I'm thinking in D allready when I saw 
this: At first glance I wondered, what this thoroughly-template 
is about... ;-)


Hahaha!


Re: segmentation fault with Object.factory()

2017-02-19 Thread berni via Digitalmars-d-learn
On Sunday, 19 February 2017 at 10:15:49 UTC, rikki cattermole 
wrote:

What's wrong here?


void main()
{
   A bar = cast(A)Object.factory(__MODULE__ ~ ".AA");
   bar.foo();
}


Oops. I overdid when trying to create a small example. With the 
module it works, but my original program had the module and still 
produced an segmentation fault. After some more investigations I 
found out, that it was not due to a mistake in the program, but 
because rdmd didn't recompile after I called it with an 
--extra-file added. Looks like a bug in rdmd... Here is a small 
example:


test.d:


module test;

import std.stdio;

void main()
{
   B tmp = cast(B)Object.factory("test2.BB");
   tmp.m1();
}

interface A   { abstract void m1(); }
interface B:A { abstract void m2(); }
class AA:A{ override void m1() { writeln("A"); } }


test2.d:


module test2;

import std.stdio;
import test;

class BB:AA,B { override void m2() { writeln("B"); } }


And here is what I get when compiling:


$> rdmd test.d
segmentation fault
$> rdmd --extra-file=test2.d test.d
segmentation fault
$> rm -rf /tmp/.rdmd-1000/
$> rdmd --extra-file=test2.d test.d
A
$> rdmd -version
rdmd build 20170122
[...]


Should I report this bug anywhere (or am I wrong again?)


Re: segmentation fault with Object.factory()

2017-02-19 Thread rikki cattermole via Digitalmars-d-learn

On 19/02/2017 11:06 PM, berni wrote:

I get a segmentation fault, when I run this program:


void main()
{
   A bar = cast(A)Object.factory("AA");
   bar.foo();
}

class A{ abstract void foo(); }
class AA:A { override void foo() {} }


The call of bar.foo() is, where the segmentation fault occurs. When I
use A bar = new AA(); instead of the factory it works.

What's wrong here?


void main()
{
   A bar = cast(A)Object.factory(__MODULE__ ~ ".AA");
   bar.foo();
}


segmentation fault with Object.factory()

2017-02-19 Thread berni via Digitalmars-d-learn

I get a segmentation fault, when I run this program:


void main()
{
   A bar = cast(A)Object.factory("AA");
   bar.foo();
}

class A{ abstract void foo(); }
class AA:A { override void foo() {} }


The call of bar.foo() is, where the segmentation fault occurs. 
When I use A bar = new AA(); instead of the factory it works.


What's wrong here?


Re: How to get the type of a derived class in a method of its base class?

2017-02-19 Thread biozic via Digitalmars-d-learn

On Sunday, 19 February 2017 at 07:52:13 UTC, Max Samukha wrote:

class A {
this(T = this)() {
static assert(is(T == B));
}
}

class B {
}

auto b = new B;

Here, T becomes A, which may be reasonable but is completely 
useless. Is there a way to obtain the type of the class (or 
class instance reference) the method is called on?


Not at compile time:

class A
{
this()
{
assert(typeid(this) == typeid(B));
}
}

class B : A
{
}

auto b = new B;




Re: How to get the type of a derived class in a method of its base class?

2017-02-19 Thread Mike Parker via Digitalmars-d-learn

On Sunday, 19 February 2017 at 07:52:13 UTC, Max Samukha wrote:

class A {
this(T = this)() {
static assert(is(T == B));
}
}

class B {
}

auto b = new B;

Here, T becomes A, which may be reasonable but is completely 
useless. Is there a way to obtain the type of the class (or 
class instance reference) the method is called on?


I believe template this parameters[1] are what you're looking for 
here.


https://dlang.org/spec/template.html#template_this_parameter


Re: JustQuestion: Are 'D' had a browser library?

2017-02-19 Thread Mike Parker via Digitalmars-d-learn

On Sunday, 19 February 2017 at 08:01:56 UTC, dummy wrote:


* Derelict-CEF
Looks like dead and didn't have a document(or tutorial).


It's a binding to the C API of CEF, so you shouldn't expect much 
documentation or any tutorials with it beyond the binding 
specific functionality in the README. If you know how to use the 
CEF C API, then you know how to use Derelict-CEF.


I implemented it as an experiment. It hasn't been updated simply 
because I haven't had a use for it and no one has submitted any 
PRs. So I wouldn't call it dead, just unloved. That said, it 
worked last time I tried it. The CEF API may have changed since 
then, though. If someone wants to get it in shape, I'll happily 
do what I can to facilitate that.





Re: JustQuestion: Are 'D' had a browser library?

2017-02-19 Thread aberba via Digitalmars-d-learn

On Sunday, 19 February 2017 at 08:01:56 UTC, dummy wrote:

Hello!

I need are functions for clawing...

 1. Working javascript(curl didn't)
 2. Get HTML code
 3. GET/POST Request

So, I'm searched about the headless browser for using with D 
before writing a this question.


* Derelict-CEF
Looks like dead and didn't have a document(or tutorial).

* WebkitGtk++
Sadnly, didn't support in GtkD.

* PhantomJS or SlimerJS ← I'm using now.
D can, but need subprocess and javascript file for run.

Of course, It's not a question about d programming language.
Sorry for my poolish question.
But i want to know if had library for D.

Thx.


You can use any D lib with http GET support (Vibe.d[1]: download, 
requests[2]) at code.dlang.org. arsd.dom[3] has dom parsing 
support. or use any XML lib.


[1] http://code.dlang.org/packages/vibe-d
[2] http://code.dlang.org/packages/requests
[3] http://code.dlang.org/packages/arsd

The expiremental XML lib too has nice API 
(https://lodo1995.github.io/experimental.xml/std/experimental/xml/dom/Document.html)


I recommend requests and experimental DOM lib 
(http://code.dlang.org/packages/std-experimental-xml) to 
implement crawling.


Re: How to get the type of a derived class in a method of its base class?

2017-02-19 Thread aberba via Digitalmars-d-learn

On Sunday, 19 February 2017 at 07:52:13 UTC, Max Samukha wrote:



class B {
}

auto b = new B;

Here, T becomes A, which may be reasonable but is completely 
useless. Is there a way to obtain the type of the class (or 
class instance reference) the method is called on?


is B not supposed to inherit from A?
like

class B: A {}


JustQuestion: Are 'D' had a browser library?

2017-02-19 Thread dummy via Digitalmars-d-learn

Hello!

I need are functions for clawing...

 1. Working javascript(curl didn't)
 2. Get HTML code
 3. GET/POST Request

So, I'm searched about the headless browser for using with D 
before writing a this question.


* Derelict-CEF
Looks like dead and didn't have a document(or tutorial).

* WebkitGtk++
Sadnly, didn't support in GtkD.

* PhantomJS or SlimerJS ← I'm using now.
D can, but need subprocess and javascript file for run.

Of course, It's not a question about d programming language.
Sorry for my poolish question.
But i want to know if had library for D.

Thx.