Re: What do you use to generate documentation?

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

On 2017-01-19 19:45, Suliman wrote:


It's seems that there is no any big changes in this deal.


The upcoming 2.073.0 (now in release candidate) has a completely new 
default Ddoc theme.


--
/Jacob Carlborg


Re: What do you use to generate documentation?

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

On 2013-03-13 10:35, Andrea Fontana wrote:

I've tried to build documentation using ddoc format and dmd.

dmd -c -D -o- ...

Generated documentation looks ugly and without stylesheet. Am I wrong?


Yes :). The upcoming 2.073.0 (now in release candidate) has a completely 
new default Ddoc theme.


--
/Jacob Carlborg


Re: Phobos: Determining number of hours or minutes or seconds till now

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

On 20/01/2017 9:29 AM, Rene Zwanenburg wrote:

On Thursday, 19 January 2017 at 14:04:36 UTC, aberba wrote:

Using the standard library, how do a get number of hours or seconds or
minutes or days or months or years till current time from a past
timestamp (like "2 mins ago")? Not with manual calculations but from
Phobos functions.


You can get a duration by subtracting two timestamps. For example:

auto delta = (Clock.currTime - timeStamp).total!"seconds";


As per the documentation this is wrong for anything beyond a few weeks.
Although I have no idea if that's the case implementation wise.


Re: Making .exe

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

On Thursday, 19 January 2017 at 21:47:53 UTC, Dlearner wrote:


Yo!
Okay I did this and I run the .exe and it works, but if I try 
to copy/paste it on my desktop and run it, it (obviously) 
doesn't work.  Is there a way to somehow compile the source, 
.dll's and image file that I'm using together into one 
executable?


If your app has dependencies, you should bundle them all up and 
distribute it all as a zip file or installer. That's not specific 
to D.


with not working wtih BitFlags

2017-01-19 Thread Jot via Digitalmars-d-learn




struct EnumToFlags(alias E) {
template opDispatch(string Name) {
enum opDispatch = 1 << __traits(getMember, E, Name);
};
};


enum X
{
a,b,c
}

auto q = EnumtoFlags!X;


auto m = q.a;

with(q)
{
   auto m = a;
}

a undefined.

Any way to get it to work? Maybe a full blowing string mixin is 
needed to generate the flag enum?






Re: cannot alias array ;/

2017-01-19 Thread Jot via Digitalmars-d-learn

On Thursday, 19 January 2017 at 12:50:06 UTC, John Colvin wrote:

On Thursday, 19 January 2017 at 07:48:03 UTC, Jot wrote:

alias a = myarray[k];

fails

myarray is a multidimensial array that I want to reduce 
writing it every time but D complains that it can't alias it.


I simply want it to do a direct substitution, nothing fancy, 
just to reducing typing.


Simplest solution, has brackets that you may not like:

void main()
{
int[][] a = [[1]];
size_t k = 0;
ref foo() { return a[k]; };
foo() = [3];
assert(a == [[3]]);
}


I just use a pointer and dereference ;/


Re: iterating through members of bitfields

2017-01-19 Thread Nestor via Digitalmars-d-learn

On Wednesday, 18 January 2017 at 12:52:56 UTC, drug wrote:
I've "solved" the same problem by using AliasSeq to generate 
bitfields so that for iterating over bitfields I can iterate 
over alias sequence and mixin code. Not very good but it works.


Interesting, could you provide a working example?


Re: Making .exe

2017-01-19 Thread Dlearner via Digitalmars-d-learn

On Thursday, 19 January 2017 at 20:56:41 UTC, Nemanja Boric wrote:

On Thursday, 19 January 2017 at 18:58:31 UTC, Dlearner wrote:

[...]


Hello!

The binary should be in the working directory:

```
➜   dub init
Package recipe format (sdl/json) [json]:
Name [test-dub]:
Description [A minimal D application.]:
Author name [Nemanja]:
License [proprietary]:
Copyright string [Copyright © 2017, Nemanja]:
Add dependency (leave empty to skip) []:
Successfully created an empty project in 
'/home/burgos/work/test-dub'.

Package sucessfully created in .
➜   echo 'import std.stdio;\nvoid main() { writeln("Hello!"); 
}' > source/app.d

➜   dub --build=release
Performing "release" build using dmd for x86_64.
test-dub ~master: building configuration "application"...
Linking...
Running ./test-dub
Hello!
➜   ./test-dub
Hello!
➜   ll
total 820K
-rw-rw-r-- 1 burgos burgos  168 Jan 19 21:53 dub.json
drwxrwxr-x 2 burgos burgos 4,0K Jan 19 21:52 source
-rwxrwxr-x 2 burgos burgos 811K Jan 19 21:53 test-dub <- the 
executable

```

You can ommit --build=release - this makes a "release mode" 
binary (without assertions and bounds check), which is a faster 
& smaller version of the binary, but with less sanity checks.


Yo!
Okay I did this and I run the .exe and it works, but if I try to 
copy/paste it on my desktop and run it, it (obviously) doesn't 
work.  Is there a way to somehow compile the source, .dll's and 
image file that I'm using together into one executable?


Re: Making .exe

2017-01-19 Thread Nemanja Boric via Digitalmars-d-learn

On Thursday, 19 January 2017 at 18:58:31 UTC, Dlearner wrote:

Hey!
I wrote a little program that has an image bounce around and 
change colours, like the old DVD player screensavers.  How can 
I build this as a little .exe file that I can send to someone?  
In the dub documentation there is something like `dub 
--build=`, but I'm not entirely sure what this does.


Thanks!


Hello!

The binary should be in the working directory:

```
➜   dub init
Package recipe format (sdl/json) [json]:
Name [test-dub]:
Description [A minimal D application.]:
Author name [Nemanja]:
License [proprietary]:
Copyright string [Copyright © 2017, Nemanja]:
Add dependency (leave empty to skip) []:
Successfully created an empty project in 
'/home/burgos/work/test-dub'.

Package sucessfully created in .
➜   echo 'import std.stdio;\nvoid main() { writeln("Hello!"); }' 
> source/app.d

➜   dub --build=release
Performing "release" build using dmd for x86_64.
test-dub ~master: building configuration "application"...
Linking...
Running ./test-dub
Hello!
➜   ./test-dub
Hello!
➜   ll
total 820K
-rw-rw-r-- 1 burgos burgos  168 Jan 19 21:53 dub.json
drwxrwxr-x 2 burgos burgos 4,0K Jan 19 21:52 source
-rwxrwxr-x 2 burgos burgos 811K Jan 19 21:53 test-dub <- the 
executable

```

You can ommit --build=release - this makes a "release mode" 
binary (without assertions and bounds check), which is a faster & 
smaller version of the binary, but with less sanity checks.


Re: Phobos: Determining number of hours or minutes or seconds till now

2017-01-19 Thread Rene Zwanenburg via Digitalmars-d-learn

On Thursday, 19 January 2017 at 14:04:36 UTC, aberba wrote:
Using the standard library, how do a get number of hours or 
seconds or minutes or days or months or years till current time 
from a past timestamp (like "2 mins ago")? Not with manual 
calculations but from Phobos functions.


You can get a duration by subtracting two timestamps. For example:

auto delta = (Clock.currTime - timeStamp).total!"seconds";


Making .exe

2017-01-19 Thread Dlearner via Digitalmars-d-learn

Hey!
I wrote a little program that has an image bounce around and 
change colours, like the old DVD player screensavers.  How can I 
build this as a little .exe file that I can send to someone?  In 
the dub documentation there is something like `dub 
--build=`, but I'm not entirely sure what this does.


Thanks!


Re: What do you use to generate documentation?

2017-01-19 Thread Adam D. Ruppe via Digitalmars-d-learn

On Thursday, 19 January 2017 at 18:45:05 UTC, Suliman wrote:

It's seems that there is no any big changes in this deal.


I made my doc gen since then and ddox has grown since then as 
well. Only other major change is ddoc just got new styling in the 
newest dmd beta. Still the same ddoc, just nicer looking out of 
the box.


ok. I know that there is a lot of other docs-gen, but who can 
give me answer about flag `-c` why its used?


dmd -c means do not link the executable. You use it when just 
creating object files (for separate linking) or when you don't 
want the program generated for some other reason.


Since the command is just meant to generate docs, it used -c to 
skip generating the exe too.


Re: What do you use to generate documentation?

2017-01-19 Thread Suliman via Digitalmars-d-learn

On Thursday, 19 January 2017 at 18:09:20 UTC, Basile B. wrote:

On Thursday, 19 January 2017 at 15:20:37 UTC, Suliman wrote:
What do dflag: `-c do not link`. Should I pass it during the 
generation of the docs? dub is append it's automatically, but 
if I want to generate new docs every rebuild of app what is 
the reason to use this flag?


Oh no 2013 !! I thought it was a hot conversation. I've been 
trapped. Why didn't you create your own subject ?


It's seems that there is no any big changes in this deal.

ok. I know that there is a lot of other docs-gen, but who can 
give me answer about flag `-c` why its used?


Re: What do you use to generate documentation?

2017-01-19 Thread Basile B. via Digitalmars-d-learn

On Thursday, 19 January 2017 at 15:20:37 UTC, Suliman wrote:
What do dflag: `-c do not link`. Should I pass it during the 
generation of the docs? dub is append it's automatically, but 
if I want to generate new docs every rebuild of app what is the 
reason to use this flag?


Oh no 2013 !! I thought it was a hot conversation. I've been 
trapped. Why didn't you create your own subject ?


Re: What do you use to generate documentation?

2017-01-19 Thread Basile B. via Digitalmars-d-learn

On Thursday, 19 January 2017 at 17:06:39 UTC, Nemanja Boric wrote:

On Thursday, 19 January 2017 at 16:47:07 UTC, Basile B. wrote:

[...]


I've submitted few PRs but they never got merged. We're 
maintaining, unofficially, fork that does compile and it's 
available at: 
https://github.com/sociomantic-tsunami/harbored-mod


Good to know !


Re: What do you use to generate documentation?

2017-01-19 Thread Nemanja Boric via Digitalmars-d-learn

On Thursday, 19 January 2017 at 16:47:07 UTC, Basile B. wrote:
On Wednesday, 13 March 2013 at 09:35:18 UTC, Andrea Fontana 
wrote:

[...]


I use harbored-mod (https://github.com/kiith-sa/hmod-dub). What 
I like about it:


1/ I'm not good with web things. The default styling is Okay 
for me so I don't have to lost time at writing some templates 
or others css files.
2/ I can call it in a single step from my IDE. For example 
after installing a static library, if i don't understand the 
API:
- a double click to generate, using a custom tool, the doc 
using an IDE environment var that symbolize the sources files 
of the lib.
- a double click to open the newly generated doc in the 
web-browser.


It's really a no-brainer.

Unfortunately It's not maintained anymore, but I'll go back to 
harbored the day the fork won't compile anymore.


I've submitted few PRs but they never got merged. We're 
maintaining, unofficially, fork that does compile and it's 
available at: https://github.com/sociomantic-tsunami/harbored-mod


Re: What do you use to generate documentation?

2017-01-19 Thread Basile B. via Digitalmars-d-learn

On Wednesday, 13 March 2013 at 09:35:18 UTC, Andrea Fontana wrote:

I've tried to build documentation using ddoc format and dmd.

dmd -c -D -o- ...

Generated documentation looks ugly and without stylesheet. Am I 
wrong? I expected a phobos-like documentation.


So, what do you use to generate your D docs? Doxygen or 
something else?


I use harbored-mod (https://github.com/kiith-sa/hmod-dub). What I 
like about it:


1/ I'm not good with web things. The default styling is Okay for 
me so I don't have to lost time at writing some templates or 
others css files.
2/ I can call it in a single step from my IDE. For example after 
installing a static library, if i don't understand the API:
- a double click to generate, using a custom tool, the doc 
using an IDE environment var that symbolize the sources files of 
the lib.
- a double click to open the newly generated doc in the 
web-browser.


It's really a no-brainer.

Unfortunately It's not maintained anymore, but I'll go back to 
harbored the day the fork won't compile anymore.


Re: What do you use to generate documentation?

2017-01-19 Thread Suliman via Digitalmars-d-learn
What do dflag: `-c do not link`. Should I pass it during the 
generation of the docs? dub is append it's automatically, but if 
I want to generate new docs every rebuild of app what is the 
reason to use this flag?


Phobos: Determining number of hours or minutes or seconds till now

2017-01-19 Thread aberba via Digitalmars-d-learn
Using the standard library, how do a get number of hours or 
seconds or minutes or days or months or years till current time 
from a past timestamp (like "2 mins ago")? Not with manual 
calculations but from Phobos functions.


Re: cannot alias array ;/

2017-01-19 Thread John Colvin via Digitalmars-d-learn

On Thursday, 19 January 2017 at 07:48:03 UTC, Jot wrote:

alias a = myarray[k];

fails

myarray is a multidimensial array that I want to reduce writing 
it every time but D complains that it can't alias it.


I simply want it to do a direct substitution, nothing fancy, 
just to reducing typing.


Simplest solution, has brackets that you may not like:

void main()
{
int[][] a = [[1]];
size_t k = 0;
ref foo() { return a[k]; };
foo() = [3];
assert(a == [[3]]);
}


Re: Mixin template confusion / compiler error.

2017-01-19 Thread Ali Çehreli via Digitalmars-d-learn

On 01/19/2017 01:06 AM, Ali Çehreli wrote:

> In other words, D's string
> mixins are the same as C's macros.

I was testing you! :p I meant "NOT the same as". :p

Ali



Re: Mixin template confusion / compiler error.

2017-01-19 Thread Ali Çehreli via Digitalmars-d-learn

On 01/19/2017 12:41 AM, Chris Katko wrote:

> 1 - Is there any way TO get the output 64,64?

You can mixin the entire statement. I used the ~ operator but you can 
use format() or the return value of a function as well:


mixin("array_t!(" ~ sizer2D!() ~ ") case2;");
// ...
mixin("array3_t!(" ~ sizer2D!() ~ ") case6;");

With function call:

mixin(makeDeclaration(/* ... */));

> 2 - Is this very non-standard / unrecommended practice and there's a
> much better way to do this?

There are other options like using literals like 64. Perhaps an 
AliasSeq!(64, 64) could be useful.


> enum MAP_SIZE
> {
> PLANET = 2048,
> SHIP = 256,
> SHUTTLE = 64,
> (etc)
> } //this could also be translated to an array lookup. ala SHIP = 0,
> SHUTTLE = 1, etc. with an array holding the sizes.
>
> and then I pass MAP_SIZE, into a map class, which then builds layers
> into that map based on the MAP_SIZE. The layers are statically sized at
> compile-time by translating a given MAP_SIZE down to the actual required
> dimensions.
>
> So in plain English: Based on a MAP_SIZE, the inner structures are all
> sized appropriately at compile-time.

I think the best way of doing this is by producing the entire code as 
string but look at the implementation of std.bitmanip.bitfields to see 
how it's actually a mixin template than contains an enum, I think to 
prevent name-polluting the scope that it's mixed in.


> "no commas" seem so arbitrary from an abstract, novice
> perspective.

I think AliasSeq is your best bet in that case.

> What if I was pre-processing English statements which include
> commas?

Of course you can do that as strings but mixed-in code must obey the 
spec and it must be "a valid StatementList". In other words, D's string 
mixins are the same as C's macros.


Ali



Re: Mixin template confusion / compiler error.

2017-01-19 Thread Daniel N via Digitalmars-d-learn

On Thursday, 19 January 2017 at 08:41:53 UTC, Chris Katko wrote:

Thank you!

So:

1 - Is there any way TO get the output 64,64?


Would this work for you?

import std.meta;

alias sizer1D = AliasSeq!(64);
alias sizer2D = AliasSeq!(64,64);

array_t!sizer2D caseX;
array2_t!sizer1D caseY;



Re: switch statement with variable branches

2017-01-19 Thread Stefan Koch via Digitalmars-d-learn

On Thursday, 19 January 2017 at 01:22:56 UTC, Yuxuan Shui wrote:
Somehow I can't use ubyte variables behind 'case', but ulong 
works fine. Why is that?


void main() {
alias TestType = ulong; // won't compile if = ubyte
import std.stdio;
TestType a,b,c;
readf("%s %s %s ", &a, &b, &c);
switch(c){
case a: writeln("a");break;
case b: writeln("b");break;
default: assert(false);
}
}


It is a bug that this code compiled.
Case Variables can only be used on const values, to prevent 
mutation of them inside the switch itself.


try to make the type a const ubyte.


Re: Mixin template confusion / compiler error.

2017-01-19 Thread Chris Katko via Digitalmars-d-learn

Thank you!

So:

1 - Is there any way TO get the output 64,64? It seems like being 
able to get a comma out of a mixin is a useful feature.


2 - Is this very non-standard / unrecommended practice and 
there's a much better way to do this?


For example, in my actual code, I have an enumerator:

enum MAP_SIZE
{
PLANET = 2048,
SHIP = 256,
SHUTTLE = 64,
(etc)
} //this could also be translated to an array lookup. ala 
SHIP = 0, SHUTTLE = 1, etc. with an array holding the sizes.


and then I pass MAP_SIZE, into a map class, which then builds 
layers into that map based on the MAP_SIZE. The layers are 
statically sized at compile-time by translating a given MAP_SIZE 
down to the actual required dimensions.


So in plain English: Based on a MAP_SIZE, the inner structures 
are all sized appropriately at compile-time.


So, for example:

map_t!(MAP_SIZE.SHIP) x;

goes into

map_t(MAP_SIZE s)
{
layer_t!(mixin(sizer2D!(s))) layer;
}

which becomes

map_t(MAP_SIZE s)
{
layer_t!(64,64) layer;
}

and in layer_t:

layer_t(int width, int height)
{
int [width][height] data;
}


Is there a different way to go about this? Should I be building 
some sort of function inside a template that "decides" / 
"translates" a passed template parameter MAP_SIZE to width and 
height values?


I guess I could try putting the mixin inside layer_t and put the 
values into the square brackets, instead of commas. But again, 
"no commas" seem so arbitrary from an abstract, novice 
perspective. What if I was pre-processing English statements 
which include commas?


Thank you for your assistance. I appreciate it.




Re: Mixin template confusion / compiler error.

2017-01-19 Thread Ali Çehreli via Digitalmars-d-learn

On 01/19/2017 12:03 AM, Chris Katko wrote:

> template sizer2D() // no params here for simplicity
> {
> const char [] sizer2D = "64,64";
> }

> array_t!(mixin(sizer2D!())) case2; // FAILS (error below)

> Error: template instance array_t!64 does not match template declaration
> array_t(int width, int height)

The comma operator strikes back but this time it's caught. :) The clue 
was exposed because my compilation has the following dmd flag:


  -de  show use of deprecated features as errors (halt compilation)

According to spec, "The text contents of the string must be compilable 
as a valid StatementList, and is compiled as such.":


  https://dlang.org/spec/statement.html#mixin-statement

So, "64,64" is mixed in as two expressions around a comma operator and 
it gets the value 64.


Ali



Re: Mixin template confusion / compiler error.

2017-01-19 Thread Chris Katko via Digitalmars-d-learn

Addendum:

Writing the following:

writeln(mixin(sizer2D!()));

simply dumps 64 to stdout.



What's going on here? Have I run into a compiler bug?


Re: cannot alias array ;/

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

On Thursday, 19 January 2017 at 07:48:03 UTC, Jot wrote:

alias a = myarray[k];

fails

myarray is a multidimensial array that I want to reduce writing 
it every time but D complains that it can't alias it.


I simply want it to do a direct substitution, nothing fancy, 
just to reducing typing.


alias is not a macro, it is alias to *symbol*. only symbol, not 
any arbitrary expression.


if you want to reduce typing, consider, for example, moving your 
code to nested function and pass `myarray[k]` as ref arg to it. 
like:


void processArray (int[] myarray) {
  void doSomething (ref int a) {
 if (a == 0) a = 42; else a += 69;
  }
  foreach (immutable k; 0..myarray.length) {
if (k%3 == 0 || k%5 == 0) doSomething(myarray[k]);
  }
}


Re: cannot alias array ;/

2017-01-19 Thread Ali Çehreli via Digitalmars-d-learn

On 01/18/2017 11:48 PM, Jot wrote:

alias a = myarray[k];

fails

myarray is a multidimensial array that I want to reduce writing it every
time but D complains that it can't alias it.

I simply want it to do a direct substitution, nothing fancy, just to
reducing typing.



Nested functions work pretty well in some cases:

import std.stdio;

void foo() {
int[double][char][string] aa;
aa["hello"]['b'][ 3.5] = 35;

auto a = "hello";
char b = 'b';

// Works like an alias:
ref theOne() {
return aa[a][b];
}

theOne[1.5] = 15;
theOne[2.5] = 25;

writeln(aa);
}

void main() {
foo();
}

Ali



Mixin template confusion / compiler error.

2017-01-19 Thread Chris Katko via Digitalmars-d-learn
I've tried to narrow this down to the minimum code that exhibits 
the problem.


When I use a mixin, to supply the parameters for a template, it 
works with ONE argument, but NOT TWO.


template sizer2D() // no params here for simplicity
{
const char [] sizer2D = "64,64";  
}   
template sizer1D()
{
const char [] sizer1D = "64"; 
}   

class why_t ()
{
array_t!(64,64) case1;  // works
array_t!(mixin(sizer2D!())) case2; // FAILS (error below)

array2_t!(64) case3; // works
array2_t!(mixin(sizer1D!())) case4; // works

array3_t!(64) case5; // works
	array3_t!(mixin(sizer2D!())) case6; // WORKS using ONE ARGUMENT 
method using default parameter for height (see class)

}

class array_t (int width, int height)
{
int [width][height] data;
}
class array2_t (int width)
{
int [width][width] data;
}
class array3_t (int width, int height=width) //note default param
{
int [width][height] data;
}



The error I get is:

Error: template instance array_t!64 does not match template 
declaration array_t(int width, int height)


Error: template instance a5test.why_t!() error instantiating

And the strange thing is, it's like it's only outputting ONE of 
the two numbers. If it were outputting any other gibberish, it 
shouldn't compile at all. And I'm not misplacing the 1D vs 2D 
function names because originally there was NO 1D version at all. 
It was just the 2D and it wouldn't compile.


Is there any way to get a PRINTOUT of the mixin code upon failure 
to see what it's actually trying to compile?


-


I'm using LDC2:

LDC - the LLVM D compiler (e9b2b4):
  based on DMD v2.068.2 and LLVM 3.5.0