Re: How to convert this function into a template ?

2018-10-02 Thread Vinod K Chandran via Digitalmars-d-learn

On Tuesday, 2 October 2018 at 17:37:58 UTC, Ali Çehreli wrote:

On 10/02/2018 07:39 AM, Vinod K Chandran wrote:

> Thanks a lot. Great help !. I will sure the check the link. :)

I find the Index section useful (yes, can be improved). For 
example, just seach for "append" on this page:


  http://ddili.org/ders/d.en/ix.html

> The doumentation did not tell me about the (T) in template. I
can
> understand the "(T)" s inside the parentheses but i can't
understand the
> one after template name.

The Templates chapter says:

  Although T is an arbitrary name, it is an acronym for "type" 
and

  is very common in templates.


http://ddili.org/ders/d.en/templates.html#ix_templates.function%20template

Ali


Thanks for the reply. Yes, the tutorial in that link contains 
append array. I think its  good for me to learn with this 
tutorial, everything is structured and easy to find.


Re: How to implement D to HTML pages ?

2018-10-02 Thread bauss via Digitalmars-d-learn
On Tuesday, 2 October 2018 at 18:27:04 UTC, Aurélien Plazzotta 
wrote:

On Tuesday, 2 October 2018 at 06:56:33 UTC, bauss wrote:

On Monday, 1 October 2018 at 23:17:59 UTC, rjframe wrote:


vibe.d has more of a node.js feel. There's also 
DiamondMVC[1], which reminds me of ASP.NET (I'm not 100% sure 
whether that's intentional, and I haven't tried Diamond) and 
includes an ORM.


As the creator of Diamond, then I can say it's 100% 
intentional that it reminds of ASP.NET. It was originally just 
an alternative template engine to vibe.d to create views 
similar to razor, but now it's a full-stack web-framework 
specifically targeting enterprise development, hence why the 
similarities to ASP.NET.


As described on the website (https://diamondmvvc.org/):

"Diamond is build on modern principles using vibe.d, inspired 
by ASP.NET and razor templates."


It can also be used in combination with vibe.d projects, in 
which you can just utilize the extra tools Diamond gives you 
such as some additional security, authentication, api 
creation, database management (ORM) etc.


Thank you both for all the links! I guess DiamondMVC is very 
powerful but I would rather avoid using such heavy artillery. 
I'm expecting the learning curve to be very long.


Do you know of template engines in D ? like Jinja2 in Python 
for example. It would be way more lightweight and 
free-dependancies compared to a fully featured framework like 
DiamondMVC, besides the gain in time thanks to the simplicity 
of use.


The learning curve is actually not that long since it's a 
relative small setup. It's a heavy beast, BUT everything is 
pretty much optional and opt-in, so you really only just use what 
you need.


So for templating, just setup a project, the configuration and 
then create views.


As soon as you're familiar with the template syntax then you're 
good to go without knowing the whole framework etc.


You can write templates using D in it.

Simple example: After 3.0.0 which is coming soon then @<> is 
replaced by @()


layout.dd:

```
@


  Website - @


  @


```

home.dd:

Notes: placeholders is equivalent to an associative array in D.

```
@[
  route:
home
---
  placeholders:
[
  "title": "Home"
]
]
Hello World!
```

Output:

```



  Website - Home


  Hello World!


```

It's pretty much plug and play too using this as an empty example 
project:


https://diamondmvc.org/download

See empty project.

It'll be ready to just compile and run.

After that you can just work with views if you just want to use 
simple templates. No need to know the whole framework or any long 
installation guides.


Re: Dynamic Minimum width with Format / writefln

2018-10-02 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 3 October 2018 at 01:14:24 UTC, Chris Katko wrote:
I'm not sure how I made this mistake. But it seems to only show 
up now if I leave .toStringz() with the writefln.


Yeah.

So what's happening here is toStringz returns the C-style char*, 
which printf works well with, but writef doesn't trust it and 
just prints the pointer value instead of trying to traverse it 
looking for a zero terminator (which might not be there).


Just passing a D string will work consistently.

So maybe I've been staring at code too long tonight and simply 
missed it?


oh probably, it happens to everyone :)


Re: Dynamic Minimum width with Format / writefln

2018-10-02 Thread Chris Katko via Digitalmars-d-learn

On Wednesday, 3 October 2018 at 00:34:33 UTC, Adam D. Ruppe wrote:

On Wednesday, 3 October 2018 at 00:14:03 UTC, Chris Katko wrote:
Except it doesn't work and tries to decode col.width-1 into a 
hexadecimal number and only prints that. ("4D6EF6")


That number certainly isn't col.width (unless you have a width 
of like millions)...


It looks more like a pointer. What is the type of col.name? If 
it is string, this code should work fine.


I'm guessing it is a char*...


I'm not sure how I made this mistake. But it seems to only show 
up now if I leave .toStringz() with the writefln.


writefln("%-*s<", col.width-1, col.name.toStringz() /* here */);

So maybe I've been staring at code too long tonight and simply 
missed it?




Re: Dynamic Minimum width with Format / writefln

2018-10-02 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 3 October 2018 at 00:14:03 UTC, Chris Katko wrote:
Except it doesn't work and tries to decode col.width-1 into a 
hexadecimal number and only prints that. ("4D6EF6")


That number certainly isn't col.width (unless you have a width of 
like millions)...


It looks more like a pointer. What is the type of col.name? If it 
is string, this code should work fine.


I'm guessing it is a char*...


Dynamic Minimum width with Format / writefln

2018-10-02 Thread Chris Katko via Digitalmars-d-learn
 - First, I'm confused. The docs say 's' is "whatever it needs to 
be". ("he corresponding argument is formatted in a manner 
consistent with its type:") But what if I specifically want a 
STRING. Because I only see floats, ints, etc. No forced string 
types.


 - Second,

This works fine in D:

printf("%-*s|", col.width-1, col.name.toStringz());

It's a left-aligned, string with a minimum width from the first 
argument, col.width. (-1 because I'm throwing a pipe symbol on 
the end.)


Now with writefln:

writefln("%-*s|", col.width-1, col.name);

Same format specifier, except I don't need a toStringz which is 
nice. Except it doesn't work and tries to decode col.width-1 into 
a hexadecimal number and only prints that. ("4D6EF6")


I looked through the docs:

https://dlang.org/phobos/std_format.html

 '%' Position Flags Width Separator Precision FormatChar

Width:
empty
Integer
'*'

But there are then zero examples or explanations of how to use 
that option. What's going on here?


Re: Dlang tour - Unittesting example

2018-10-02 Thread Steven Schveighoffer via Digitalmars-d-learn

On 10/2/18 8:30 AM, Joe wrote:

On Tuesday, 2 October 2018 at 12:25:19 UTC, Joe wrote:

On Tuesday, 2 October 2018 at 09:59:28 UTC, bauss wrote:

On Tuesday, 2 October 2018 at 04:13:01 UTC, Joe wrote:

There appears to be a problem with the example at

https://tour.dlang.org/tour/en/gems/unittesting

If compiled with -unittest, the resulting program crashes. It 
happens with ldc2 on Linux but it can also be seen if you click on 
"Export" and run it with dmd -unittest.


I think it's more likely a problem with your OS.

I am unable to reproduce that with either of dmd or ldc.


Well then it's also a problem with run.dlang.io, since as I said it 
also happens when you run it there.


I forgot to mention: at the end, it reports "1/1 unittests FAILED". I 
see three tests--two in the struct and the separate one--but the 
assertion failure is in line 49 (the standalone) so apparently the other 
two are not being run (or reported).


I will note that the granularity of the unittests is based on how many 
*modules* were tested. There is only one unittest function in each 
ModuleInfo (as provided by the compiler to the runtime), so that's the 
number that's being reported. So in this case, it's not missing 
unittests, it's running all given unit tests.


-Steve


Re: GC page and block metadata storage

2018-10-02 Thread Per Nordlöw via Digitalmars-d-learn

On Tuesday, 2 October 2018 at 09:43:02 UTC, thedeemon wrote:
I guess you would want to scan the metadata without thrashing 
all the pages. Keeping metadata together compactly is good for 
cache.


Can you briefly elaborate on what use case(s) you hade in mind 
when you wrote this?


Re: Linking with a non-default druntime

2018-10-02 Thread Per Nordlöw via Digitalmars-d-learn

On Tuesday, 2 October 2018 at 16:20:52 UTC, Basile B. wrote:
This works https://github.com/BBasile/druntime/pull/1. Not sure 
if it will be useful.


Ahh, thanks!

I've just found my own way of iterating via a script at

https://github.com/nordlow/scripts/blob/master/dmd-own

that (re)compiles druntime and phobos and then compiles my GC 
test application using toolchain in around 7 secs on my 2 year 
old laptop. I'll stick to that for now.


This assumes the home-directory structure

~/Work/dmd ~master
   druntime ~dmitry-gc
   phobos ~master

. The playground for my GC experiments will be

https://github.com/nordlow/druntime/blob/dmitry-gc/src/gc/impl/dmitry/gc.d

So far I've only described my plan and added a set of debug 
prints.


You're very welcome to comment and destroy my plan. I'm uncertain 
of what kinds of locking (if any) that is needed for a 
thread-local GC allocation (non-mutex I suppose). Please 
elaborate on the subject if you have any experience with 
thread-local GCs.


Would you be interested in making this a druntime PR so you can 
make comments?


Contents of `dmd-own` follows:

#!/usr/bin/env bash

function dmd-own_fn()
{
local DLANG_SRC_ROOT=${HOME}/Work
local DMD_ROOT=${DLANG_SRC_ROOT}/dmd
local DRUNTIME_ROOT=${DLANG_SRC_ROOT}/druntime
local PHOBOS_ROOT=${DLANG_SRC_ROOT}/phobos
local BUILD="debug"

if type clang++ &> /dev/null; then
local HOST_CXX=clang++
else
local HOST_CXX=g++-8
fi
HOST_CXX=g++-8 # use g++ for now because building DMD with 
clang++ seems to generate a dmd binary that segfauls


# rebuild dmd, druntime, phobos on Linux
command make -f posix.mak BUILD=${BUILD} -C ${DMD_ROOT} 
HOST_CXX=${HOST_CXX} > /dev/null 2> /dev/null
# command make -f posix.mak BUILD=${BUILD} -C 
${DRUNTIME_ROOT} > /dev/null
command make -f posix.mak BUILD=${BUILD} -C ${PHOBOS_ROOT} > 
/dev/null


if [ $# = 0 ]; then
echo -e "Usage: $FUNCNAME D_SOURCE_FILE ARG
Example: dmd-own gctester.d --DRT-gcopt=gc:dmitry"
else
local FILE="$1"
local out=$(mktemp)
local ARG="$2"
local NEW_DMD=${DMD_ROOT}/generated/linux/${BUILD}/64/dmd
${NEW_DMD} -debug -unittest -wi -vcolumns ${PWD}/${FILE} 
-of$out

$out ${ARG}
fi
}

dmd-own_fn "$@"


Re: Wrong module initialization order when building with Dub on Windows?

2018-10-02 Thread Jacob Carlborg via Digitalmars-d-learn

On 2018-10-02 08:49, bauss wrote:

Honestly I would say that it should have worked regardless of the module 
order, because it's the runtime arguments.


Basically D's runtime should set them before ANY module constructors are 
called and most definitely before the main function is called.


They are set before calling any module constructors. The arguments are 
set here [1] and the module constructors are run here [2].


[1] 
https://github.com/dlang/druntime/blob/e807e29472fa5973c438f97cd5d4b390ef1a4a5c/src/rt/dmain2.d#L438


[2] 
https://github.com/dlang/druntime/blob/e807e29472fa5973c438f97cd5d4b390ef1a4a5c/src/rt/dmain2.d#L493


--
/Jacob Carlborg


Re: How to implement D to HTML pages ?

2018-10-02 Thread Aurélien Plazzotta via Digitalmars-d-learn

On Tuesday, 2 October 2018 at 06:56:33 UTC, bauss wrote:

On Monday, 1 October 2018 at 23:17:59 UTC, rjframe wrote:


vibe.d has more of a node.js feel. There's also DiamondMVC[1], 
which reminds me of ASP.NET (I'm not 100% sure whether that's 
intentional, and I haven't tried Diamond) and includes an ORM.


As the creator of Diamond, then I can say it's 100% intentional 
that it reminds of ASP.NET. It was originally just an 
alternative template engine to vibe.d to create views similar 
to razor, but now it's a full-stack web-framework specifically 
targeting enterprise development, hence why the similarities to 
ASP.NET.


As described on the website (https://diamondmvvc.org/):

"Diamond is build on modern principles using vibe.d, inspired 
by ASP.NET and razor templates."


It can also be used in combination with vibe.d projects, in 
which you can just utilize the extra tools Diamond gives you 
such as some additional security, authentication, api creation, 
database management (ORM) etc.


Thank you both for all the links! I guess DiamondMVC is very 
powerful but I would rather avoid using such heavy artillery. I'm 
expecting the learning curve to be very long.


Do you know of template engines in D ? like Jinja2 in Python for 
example. It would be way more lightweight and free-dependancies 
compared to a fully featured framework like DiamondMVC, besides 
the gain in time thanks to the simplicity of use.


Re: How to convert this function into a template ?

2018-10-02 Thread Ali Çehreli via Digitalmars-d-learn

On 10/02/2018 07:39 AM, Vinod K Chandran wrote:

> Thanks a lot. Great help !. I will sure the check the link. :)

I find the Index section useful (yes, can be improved). For example, 
just seach for "append" on this page:


  http://ddili.org/ders/d.en/ix.html

> The doumentation did not tell me about the (T) in template. I can
> understand the "(T)" s inside the parentheses but i can't understand the
> one after template name.

The Templates chapter says:

  Although T is an arbitrary name, it is an acronym for "type" and
  is very common in templates.


http://ddili.org/ders/d.en/templates.html#ix_templates.function%20template

Ali



Re: Dlang tour - Unittesting example

2018-10-02 Thread Joe via Digitalmars-d-learn

On Tuesday, 2 October 2018 at 13:24:09 UTC, Basile B. wrote:

The problem is the NaN madness.
Since several values are NaN there's this strange stuff:

void main()
{
import std.stdio;
import std.math : isNaN;
double d;

writeln(d.init);// nan
writeln(d); // nan
writeln(d.nan); // nan

assert(d.isNaN);
assert(d == d.nan);  // fails
assert(d == d.init); // fails
}

the last assert is just crazy.


OK, so changing the example from

// .init a special built-in property that
// returns the initial value of type.
assert(vec.x == double.init);

to

import std.math : isNaN;
assert(vec.x.isNaN);

doesn't cause the crash. Although I'm a bit puzzled still, I 
thought (coming from Python) that when you ran the unittest 
version it would report which tests passed and which failed, not 
run through main().


Re: Linking with a non-default druntime

2018-10-02 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 2 October 2018 at 13:07:04 UTC, Basile B. wrote:

On Monday, 1 October 2018 at 11:10:07 UTC, Per Nordlöw wrote:

On Monday, 1 October 2018 at 08:27:54 UTC, Basile B. wrote:
I think so. Apparently it's registered with a string, e.g 
"manual" and you pass a special druntime option with your 
program to select.
Actually i would be interested to make the interface with 
assignable handlers since you don't seem to be very hot. 
Maybe tomorrow i can try. I'm almost sure that this could 
work but cant be 100% sure. Maybe there'll be issues with 
privacy and events to assign.


Be my guest :)

Thanks!


I see other related topics, did you already start something ?


This works https://github.com/BBasile/druntime/pull/1. Not sure 
if it will be useful.


Re: How to convert this function into a template ?

2018-10-02 Thread Vinod K Chandran via Digitalmars-d-learn
On Tuesday, 2 October 2018 at 12:23:47 UTC, Jonathan M Davis 
wrote:


The template equivalent would have been something like

void arrayAdd(T)(ref T[] x, T value)
{
auto index = x.length;
x.length += 1;
x[index] = value;
}

But if you're new to the language, I'd suggest that you read 
this site / book:


http://ddili.org/ders/d.en/index.html

- Jonathan M Davis

Thanks a lot. Great help !. I will sure the check the link. :)
The doumentation did not tell me about the (T) in template. I can 
understand the "(T)" s inside the parentheses but i can't 
understand the one after template name.





Re: Wrong module initialization order when building with Dub on Windows?

2018-10-02 Thread Kagamin via Digitalmars-d-learn
Missing command line arguments? Sounds like this: 
https://forum.dlang.org/post/eevaqbqufmhhducua...@forum.dlang.org


Re: Dlang tour - Unittesting example

2018-10-02 Thread ag0aep6g via Digitalmars-d-learn

On 10/02/2018 03:24 PM, Basile B. wrote:

The problem is the NaN madness.
Since several values are NaN there's this strange stuff:

void main()
{
     import std.stdio;
     import std.math : isNaN;
     double d;

     writeln(d.init);    // nan
     writeln(d); // nan
     writeln(d.nan); // nan

     assert(d.isNaN);
     assert(d == d.nan);  // fails
     assert(d == d.init); // fails
}

the last assert is just crazy.


NaN simply isn't equal to itself. Has nothing to do with there being 
multiple NaNs. `d == d`, `double.nan == double.nan`, `double.init == 
double.init` are all false, too.


Re: Dlang tour - Unittesting example

2018-10-02 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 2 October 2018 at 12:30:36 UTC, Joe wrote:

On Tuesday, 2 October 2018 at 12:25:19 UTC, Joe wrote:

On Tuesday, 2 October 2018 at 09:59:28 UTC, bauss wrote:

On Tuesday, 2 October 2018 at 04:13:01 UTC, Joe wrote:

There appears to be a problem with the example at

https://tour.dlang.org/tour/en/gems/unittesting

If compiled with -unittest, the resulting program crashes. 
It happens with ldc2 on Linux but it can also be seen if you 
click on "Export" and run it with dmd -unittest.


I think it's more likely a problem with your OS.

I am unable to reproduce that with either of dmd or ldc.


Well then it's also a problem with run.dlang.io, since as I 
said it also happens when you run it there.


I forgot to mention: at the end, it reports "1/1 unittests 
FAILED". I see three tests--two in the struct and the separate 
one--but the assertion failure is in line 49 (the standalone) 
so apparently the other two are not being run (or reported).


The problem is the NaN madness.
Since several values are NaN there's this strange stuff:

void main()
{
import std.stdio;
import std.math : isNaN;
double d;

writeln(d.init);// nan
writeln(d); // nan
writeln(d.nan); // nan

assert(d.isNaN);
assert(d == d.nan);  // fails
assert(d == d.init); // fails
}

the last assert is just crazy.


Re: Linking with a non-default druntime

2018-10-02 Thread Basile B. via Digitalmars-d-learn

On Monday, 1 October 2018 at 11:10:07 UTC, Per Nordlöw wrote:

On Monday, 1 October 2018 at 08:27:54 UTC, Basile B. wrote:
I think so. Apparently it's registered with a string, e.g 
"manual" and you pass a special druntime option with your 
program to select.
Actually i would be interested to make the interface with 
assignable handlers since you don't seem to be very hot. Maybe 
tomorrow i can try. I'm almost sure that this could work but 
cant be 100% sure. Maybe there'll be issues with privacy and 
events to assign.


Be my guest :)

Thanks!


I see other related topics, did you already start something ?


Re: Dlang tour - Unittesting example

2018-10-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 2, 2018 3:59:28 AM MDT bauss via Digitalmars-d-learn 
wrote:
> On Tuesday, 2 October 2018 at 04:13:01 UTC, Joe wrote:
> > There appears to be a problem with the example at
> >
> > https://tour.dlang.org/tour/en/gems/unittesting
> >
> > If compiled with -unittest, the resulting program crashes. It
> > happens with ldc2 on Linux but it can also be seen if you click
> > on "Export" and run it with dmd -unittest.
>
> I think it's more likely a problem with your OS.
>
> I am unable to reproduce that with either of dmd or ldc.

IIRC, we use stdc for formatting floating values and not pure D code
(because correctly converting floating point values to strings is really,
really complicated to implement). So, the result is going to depend on the
system that it's run on. It fails on my system (64-bit FreeBSD). Honestly,
this is basically the same thing as comparing floating point values with ==.
You shouldn't do it. So, I'd argue that it's just plain a bad example.

- Jonathan M Davis





Re: Dlang tour - Unittesting example

2018-10-02 Thread Joe via Digitalmars-d-learn

On Tuesday, 2 October 2018 at 12:25:19 UTC, Joe wrote:

On Tuesday, 2 October 2018 at 09:59:28 UTC, bauss wrote:

On Tuesday, 2 October 2018 at 04:13:01 UTC, Joe wrote:

There appears to be a problem with the example at

https://tour.dlang.org/tour/en/gems/unittesting

If compiled with -unittest, the resulting program crashes. It 
happens with ldc2 on Linux but it can also be seen if you 
click on "Export" and run it with dmd -unittest.


I think it's more likely a problem with your OS.

I am unable to reproduce that with either of dmd or ldc.


Well then it's also a problem with run.dlang.io, since as I 
said it also happens when you run it there.


I forgot to mention: at the end, it reports "1/1 unittests 
FAILED". I see three tests--two in the struct and the separate 
one--but the assertion failure is in line 49 (the standalone) so 
apparently the other two are not being run (or reported).


Re: Dlang tour - Unittesting example

2018-10-02 Thread Joe via Digitalmars-d-learn

On Tuesday, 2 October 2018 at 09:59:28 UTC, bauss wrote:

On Tuesday, 2 October 2018 at 04:13:01 UTC, Joe wrote:

There appears to be a problem with the example at

https://tour.dlang.org/tour/en/gems/unittesting

If compiled with -unittest, the resulting program crashes. It 
happens with ldc2 on Linux but it can also be seen if you 
click on "Export" and run it with dmd -unittest.


I think it's more likely a problem with your OS.

I am unable to reproduce that with either of dmd or ldc.


Well then it's also a problem with run.dlang.io, since as I said 
it also happens when you run it there.


Re: How to convert this function into a template ?

2018-10-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 2, 2018 6:09:53 AM MDT Vinod K Chandran via Digitalmars-
d-learn wrote:
> On Tuesday, 2 October 2018 at 11:49:06 UTC, Jonathan M Davis
>
> wrote:
> > Why do you have a function for that? All you need to do is use
> > the append operator. e.g.
> >
> > x ~= value;
> >
> > - Jonathan M Davis
>
> Thanks for the reply. I did not find that it in documentation.
> Ofcourse i lost a chance to learn about templates. By translating
> a well known function into a template, i can easiy learn the
> concept, since the template documentation is little bit hard to
> understand.

The template equivalent would have been something like

void arrayAdd(T)(ref T[] x, T value)
{
auto index = x.length;
x.length += 1;
x[index] = value;
}

But if you're new to the language, I'd suggest that you read this site /
book:

http://ddili.org/ders/d.en/index.html

- Jonathan M Davis





Re: How to convert this function into a template ?

2018-10-02 Thread Vinod K Chandran via Digitalmars-d-learn
On Tuesday, 2 October 2018 at 11:49:06 UTC, Jonathan M Davis 
wrote:
Why do you have a function for that? All you need to do is use 
the append operator. e.g.


x ~= value;

- Jonathan M Davis


Thanks for the reply. I did not find that it in documentation.  
Ofcourse i lost a chance to learn about templates. By translating 
a well known function into a template, i can easiy learn the 
concept, since the template documentation is little bit hard to 
understand.





Re: How to convert this function into a template ?

2018-10-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 2, 2018 5:40:18 AM MDT Vinod K Chandran via Digitalmars-
d-learn wrote:
> Hi all,
> I have a function and i want to convert this into a template so
> that i can use this function for more than one data type.
> This is my function.
> ```D
> void ArrayAdd( ref int[] x, int value) {
>  int index = x.length ;
>  x.length += 1 ;
>  x[index] = value ;
> }
> ```

Why do you have a function for that? All you need to do is use the append
operator. e.g.

x ~= value;

- Jonathan M Davis





How to convert this function into a template ?

2018-10-02 Thread Vinod K Chandran via Digitalmars-d-learn

Hi all,
I have a function and i want to convert this into a template so 
that i can use this function for more than one data type.

This is my function.
```D
void ArrayAdd( ref int[] x, int value) {
int index = x.length ;
x.length += 1 ;
x[index] = value ;
}
```




Re: Does the WInMain function is mandatory ?

2018-10-02 Thread Vinod K Chandran via Digitalmars-d-learn

On Sunday, 30 September 2018 at 15:06:31 UTC, Mike Parker wrote:
On Sunday, 30 September 2018 at 14:06:20 UTC, Vinod K Chandran 
wrote:




Thanks. It worked.
I  would like to compile this as a gui. Now it starts with the 
cmd. Google search didn't gave me the link i want. Any help ?


With the default OPTLINK linker:

dmd -L/SUBSYSTEM:windows app.d

In this case, user32.lib where MessageBoxW and MessageBoxA 
reside is automatically linked.


When using the MS linker:

dmd -m64 -L/SUBSYSTEM:windows -L/ENTRY:mainCRTStartup app.d 
user32.lib


In this case, user32.lib is not automatically linked. Replace 
-m64 with -m32mscoff for 32-bit output with the MS linker.


-L passes command line options to the current linker.


Thanks for the reply. I think its better to write a program in 
which we can choose this codes from a combobox and click a button 
to start compiling.


Re: Use nested functions as callbacks with Windows API functions?

2018-10-02 Thread John Chapman via Digitalmars-d-learn

On Monday, 1 October 2018 at 20:27:43 UTC, spikespaz wrote:
Of course there is nothing wrong with defining each callback as 
a separate function, but then comes the issue of naming them. I 
also don't like the way it makes my code look.


I think the best you can do is something like this:

---
auto callback(T, string file = __FILE__, size_t line = 
__LINE__)(T handler) {

  import std.traits;

  __gshared T handler_;
  handler_ = handler;

  extern(Windows)
  ReturnType!T fn(Parameters!T args) {
synchronized return handler_(args);
  }

  return &fn;
}

void main() {
  HWND[] list;
  EnumWindows((HWND hwnd, LPARAM lparam) {
list ~= hwnd;
return TRUE;
  }.callback(), 0);
  writeln(list);
}
---



Re: Dlang tour - Unittesting example

2018-10-02 Thread bauss via Digitalmars-d-learn

On Tuesday, 2 October 2018 at 04:13:01 UTC, Joe wrote:

There appears to be a problem with the example at

https://tour.dlang.org/tour/en/gems/unittesting

If compiled with -unittest, the resulting program crashes. It 
happens with ldc2 on Linux but it can also be seen if you click 
on "Export" and run it with dmd -unittest.


I think it's more likely a problem with your OS.

I am unable to reproduce that with either of dmd or ldc.


Re: GC page and block metadata storage

2018-10-02 Thread thedeemon via Digitalmars-d-learn

On Tuesday, 2 October 2018 at 07:25:36 UTC, Per Nordlöw wrote:
Should a new fresh GC for D store block metadata inside the 
page itself or in a (pool) structure separate from the page?


I'm already aware of Dmitry's suggestion to separate value-type 
pools from pools of types possibly containing addresses.


I guess you would want to scan the metadata without thrashing all 
the pages. Keeping metadata together compactly is good for cache. 
Of course it depends on how exactly it's going to be used.


GC page and block metadata storage

2018-10-02 Thread Per Nordlöw via Digitalmars-d-learn
Should a new fresh GC for D store block metadata inside the page 
itself or in a (pool) structure separate from the page?


I'm already aware of Dmitry's suggestion to separate value-type 
pools from pools of types possibly containing addresses.


Re: How to implement D to HTML pages ?

2018-10-02 Thread bauss via Digitalmars-d-learn

On Monday, 1 October 2018 at 23:17:59 UTC, rjframe wrote:


vibe.d has more of a node.js feel. There's also DiamondMVC[1], 
which reminds me of ASP.NET (I'm not 100% sure whether that's 
intentional, and I haven't tried Diamond) and includes an ORM.


As the creator of Diamond, then I can say it's 100% intentional 
that it reminds of ASP.NET. It was originally just an alternative 
template engine to vibe.d to create views similar to razor, but 
now it's a full-stack web-framework specifically targeting 
enterprise development, hence why the similarities to ASP.NET.


As described on the website (https://diamondmvvc.org/):

"Diamond is build on modern principles using vibe.d, inspired by 
ASP.NET and razor templates."


It can also be used in combination with vibe.d projects, in which 
you can just utilize the extra tools Diamond gives you such as 
some additional security, authentication, api creation, database 
management (ORM) etc.




Re: How to implement D to HTML pages ?

2018-10-02 Thread bauss via Digitalmars-d-learn

On Tuesday, 2 October 2018 at 06:56:33 UTC, bauss wrote:


As described on the website (https://diamondmvvc.org/):



Minor typo sorry.

https://diamondmvc.org/