Re: Test if a class is extern(c++)

2017-04-10 Thread BBasile via Digitalmars-d-learn

On Monday, 10 April 2017 at 18:32:05 UTC, Benjamin Thaut wrote:
In particular I want to know if the vtable of the class has the 
class info member.

Is there any way to do this at compile time? At runtime?

Kind Regards
Benjamin Thaut


Hello, I have a trait for this:

https://github.com/BBasile/iz/blob/master/import/iz/types.d#L650




Re: working with and installing multiple versions of dmd and D's std-library on linux/ubuntu

2017-01-20 Thread BBasile via Digitalmars-d-learn

On Friday, 20 January 2017 at 09:54:58 UTC, David wrote:

Hi

I am wondering what a good strategy would be to install and 
work with multiple versions of DMD and the associated standard 
library on Linux/Ubuntu? The background is that for some 
features and libraries I need another compiler/std-lib version 
than for others. So having the opportunity to choose the 
compiler and the associated std-lib manually would be nice.


David


Hi, for me it looks like a feature of the editor or of the IDE. 
It's implemented in Coedit 
(http://bbasile.github.io/Coedit/options_compilers_paths). It 
works fine because the IDE is an environment that manages the 
selection for the different features (this compiler for the 
scripts, this one for DUB, etc) and changing the selection (use 
this compiler for DUB now, use this one later for another 
project) is also applied directly to DCD.


Re: Create Windows "shortcut" (.lnk) with D?

2016-03-05 Thread BBasile via Digitalmars-d-learn

On Sunday, 6 March 2016 at 03:13:23 UTC, 岩倉 澪 wrote:
I'm creating a small installation script in D, but I've been 
having trouble getting shortcut creation to work! I'm a linux 
guy, so I don't know much about Windows programming...


[...]

Any help would be highly appreciated as I'm new to Windows 
programming in D and have no idea what I'm doing wrong!


If you don't want to mess with the Windows API then you can 
dynamically create a script (I do this in CE installer):


void createLnk(string exeName, string displayName)
{
import std.process: environment, executeShell;
import std.file: remove, exists;
import std.random: uniform;
import std.conv: to;

string vbsName;
do vbsName = environment.get("TEMP") ~ r"\shcsh" ~ 
uniform(0,int.max).to!string ~ ".vbs";

while (vbsName.exists);

string vbsCode = "
set WshShell = CreateObject(\"WScript.shell\")
strDesktop = WshShell.SpecialFolders(\"Desktop\")
set lnk = WshShell.CreateShortcut(strDesktop + 
\"\\%s.lnk\")

lnk.TargetPath = \"%s\"
lnk.Save
";
File vbs = File(vbsName, "w");
vbs.writefln(vbsCode, displayName, exeName);
vbs.close;
executeShell(vbsName);

vbsName.remove;
}



Re: Trouble installing DCD on Windows

2016-02-27 Thread BBasile via Digitalmars-d-learn

On Saturday, 27 February 2016 at 10:16:53 UTC, Minas Mina wrote:

Hello.
I'm trying to install DCD on windows 8.1 using DUB but I get an 
error.


When executing "dub build --build=release --config=client" I 
get the following error:
=> Root package dcd contains reference to invalid package 
libdparse >=0.5.0 <0.6.0 <=


run the build.bat file located in the repository, you'll be more 
lucky, but take care to run "git submodule update --init 
--recursive" before (if not already done of course).


Re: Using double value in string template mixin

2016-02-26 Thread BBasile via Digitalmars-d-learn

On Friday, 26 February 2016 at 11:26:51 UTC, BBasile wrote:
No you cannot because you would have to convert the values to 
string using std.conv.to or std.format.format(), but they don't 
work at compile time (see 
https://issues.dlang.org/show_bug.cgi?id=13568).


Erratum! Actually you can, example:

import std.stdio;

string foo(double a)()
{
return "auto value = " ~ a.stringof ~ ";";
}

void main(string[] args)
{
mixin(foo!0.1);
writeln(value); // 0.1
writeln(typeof(value).stringof); // double
}

So you have to use .stringof on the template argument.
Sorry for the previous answer.


Re: Using double value in string template mixin

2016-02-26 Thread BBasile via Digitalmars-d-learn
On Friday, 26 February 2016 at 11:13:08 UTC, Dibyendu Majumdar 
wrote:

I am trying something like this:

template MyTAlloc(int n_vars, double v) {
const char[] MyT = "MyT_init(cast(MyT *) alloca(alloc_size(" ~ 
n_vars ~ ")), " ~ n_vars ~ ", " ~ v ~ ")";


No you cannot because you would have to convert the values to 
string using std.conv.to or std.format.format(), but they don't 
work at compile time (see 
https://issues.dlang.org/show_bug.cgi?id=13568).


Ideally like this:

template MyTAlloc(int n_vars, double v) {
const char[] MyT = "MyT_init(cast(MyT *) alloca(alloc_size(" ~
to!string(n_vars) ~ ")), " ~ to!string(n_vars) ~ ", " ~ 
to!string(v) ~ ")";


But you can try with regular templates or mixin templates.





Re: Using double value in string template mixin

2016-02-26 Thread BBasile via Digitalmars-d-learn
On Friday, 26 February 2016 at 11:03:43 UTC, Dibyendu Majumdar 
wrote:

Hi,

How do I use a double value in a mixin template that is 
generating string?


Thanks and Regards
Dibyendu


Have you an example of what's failing right now to show ?


Re: all functions that have a first arg of type T

2016-02-25 Thread BBasile via Digitalmars-d-learn

On Friday, 26 February 2016 at 04:19:29 UTC, BBasile wrote:

static if (__traits(isStaticFunction,typeof(m2)))

static if (__traits(isStaticFunction, __traits(getMember, 
vulkan_input, m2


Sorry don't copy paste like this there's a superfluous right 
paren.


static if (__traits(isStaticFunction, __traits(getMember, 
vulkan_input, m2)))





Re: all functions that have a first arg of type T

2016-02-25 Thread BBasile via Digitalmars-d-learn
On Friday, 26 February 2016 at 03:57:25 UTC, Nicholas Wilson 
wrote:

foreach(m; __traits(allMembers, vulkan_input))
{
static if (m.endsWith("_T"))
{
foreach(m2; __traits(allMembers, vulkan_input))
{
 static if 
(__traits(isStaticFunction,typeof(m2)))// <- what here?

 {
 enum fn = __traits(getMember,vulkan_input, m2);
 enum parameters = Parameters!(fn);
 static if (parameters[0] == m)
 writeln( m, ":",m2);
 }
}
}
}


static if (__traits(isStaticFunction,typeof(m2)))

static if (__traits(isStaticFunction, __traits(getMember, 
vulkan_input, m2




Re: dub: how to reference a compiled package

2016-02-25 Thread BBasile via Digitalmars-d-learn

On Thursday, 25 February 2016 at 12:15:42 UTC, mahdi wrote:

Hi,

Suppose I have a package `mypack` in `~/mypack`. I run `dub` 
command on this package and have the compiled `mypack` file (OS 
is Linux).


Now I am working on my project. I know how to use the 
source-code of `mypack` package in the project but what if I 
only have the compiled binary? How can I reference and use the 
modules of the compiled `mypack`?


(I looked into the DUB homepage and it's Getting Started page 
but could not find anything).


As you've been told previous you need a D interface file. But 
additionally:


The D interface file must be specified to DUB using

"sourceFiles" : ["folder/interface.di"],

either in a config or in the globals.

The binary, so either a .lib | .a or .obj | .o must be specified 
to DUB using


"DFlags" : ["folder/binary.a"],

Here again also accepted in a config or the globals.

This is because DUB doesn't consider such binary as source file 
but DMD or LDMD2 will accept them as source in the command line.


e.g the DMD equivalent for the two previous example is

DMD "sourceThis.d" "folder/interface.di" "folder/binary.a" 
-ofbin/thesoft


template this and traits getOverloads issue.

2015-11-20 Thread BBasile via Digitalmars-d-learn

Background:
===

http://stackoverflow.com/questions/33764540/warning-about-overriden-methods-when-using-a-mixin

Why this horrible trick has to be used:
===

cast this as (T) in a function template that's been mixed in an 
ancestor is not always usable, unless I miss something:



import std.stdio;

mixin template Bug()
{
import std.traits;
void bug(T)()
{
foreach(member; __traits(allMembers, T))
foreach(overload; __traits(getOverloads, T, member))
{
auto dg = 
writeln(member);
}
}
}

class A
{
mixin Bug;
this(){bug!A;}
void foo(){}
}

class B: A
{
void bar(){}
void bar(uint a){}
this(){bug!B;}
}

void main(){
new A;
new B;
}




a.d(11,27): Error: this for bar needs to be type B not type a.A
a.d(11,27): Error: this for bar needs to be type B not type a.A
a.d(11,27): Error: this for this needs to be type B not type a.A



everything that can be done to avoid the compilations errors will 
also prevent "bar" to be written in the output (because a B will 
never be analyzed). The "only" fix I see is like in the stack 
overflow answer: statically check if the mixin methods are 
already there and remix the mixin in each descendant, so that the 
getOverloads traits works on the right 'this'.


What do you think ? is it a bug ?


Re: template this and traits getOverloads issue.

2015-11-20 Thread BBasile via Digitalmars-d-learn

On Friday, 20 November 2015 at 14:18:00 UTC, Alex Parrill wrote:

If the mixin has to be used on class and on struct, I cant use an 
interface. In this case override will create an error and go back 
to the solution on SO: statically check if things are already 
there.


Templates are not virtual, which is why you might be running 
into issues here; bug thinks it's being called on an `A` object.


This is the origin of the problem, I totally forgot this 
limitation.





Re: template this and traits getOverloads issue.

2015-11-20 Thread BBasile via Digitalmars-d-learn

On Friday, 20 November 2015 at 14:39:29 UTC, Alex Parrill wrote:
Alternatively, you can use a static method and pass in the 
instance.


Initially this solution looked awesome but when `bug()` is 
static, `` returns some functions, not some delegates, which 
is a problem: this implies that I have to find the matching 
delegate type, set `.funcptr` to the value of the `dg` function, 
set `.ptr` to the value of 't'...well not so hard I guess.


But then I have no way to detect when a function is really a 
function or something that might be delegate when instantiated:



{
auto dg = 
if (member == "bar")
writeln(member, " ", typeof(dg).stringof);
}

--> bar void function()
--> bar void function(uint a)


Note that `new B` will print A's members twice, because A's 
constructor is always called and `__traits(allMembers, B)` 
includes A's members.


Not a problem, it was already the case anyway.

But thx much for the attempt.





Re: template this and traits getOverloads issue.

2015-11-20 Thread BBasile via Digitalmars-d-learn

On Friday, 20 November 2015 at 14:49:28 UTC, Adam D. Ruppe wrote:

On Friday, 20 November 2015 at 14:01:13 UTC, BBasile wrote:
everything that can be done to avoid the compilations errors 
will also prevent "bar" to be written in the output (because a 
B will never be analyzed). The "only" fix I see is like in the 
stack overflow answer: statically check if the mixin methods 
are already there and remix the mixin in each descendant, so 
that the getOverloads traits works on the right 'this'.


Did you try using a template this parameter like I said in my 
comment?


foreach(idx, overload; __traits(getOverloads, T, 
member))

{
auto dg = &(__traits(getOverloads, this_, 
member)[idx]);



Yes, using an index and a second call to getOverloads works, 
"finally".

No need to remix. Thx. I hadn't understood what you meant on SO.

One last question: is it possible to nest the calls to functions 
that take this kind of parameters ?


mixin template Bug()
{
 void bug0(this T)(){}
 void bug1(this T)(){}
 void allbugs(this T)(){this.bug0(); this.bug1();}
}

I've tried different parameters and templates and it never works.


Re: template this and traits getOverloads issue.

2015-11-20 Thread BBasile via Digitalmars-d-learn

On Friday, 20 November 2015 at 15:03:06 UTC, Adam D. Ruppe wrote:

On Friday, 20 November 2015 at 14:18:00 UTC, Alex Parrill wrote:
But you don't need a template for this case; mixin templates 
have access to `this`:


Indeed, this is a good answer too.

The difference between this and the template thing I did is 
that yours is virtual so calling it through an interface will 
work even on subclasses. However, you must mix it into each sub 
class.


Mine is a template that only needs to be in the base 
class/interface, but also need a `this` of the derived type to 
see the derived type. (That's why I ran `this.bug();` in the 
constructor of B btw) If you call it on an variable typed as 
the interface, it will only show interface members.


IF i = new A();
i.bug(); // would only show interface members with mine

A a = new A();
a.bug(); // will now show A's members too

That's what the template this parameter does: the type of this 
at the *usage site* is passed as the parameter.



With your solution, the type of this at the *mixin site* is 
available.




I think your solution is generally better for stuff like 
serialization where you are passed an interface but need child 
members too. The template this param I used is nice for 
interface functions that need some kind of covariance; 
returning a type based on how it was used.


I review what I said before. Actually it doesn't work that well.

Using the two methods (yours or A.Parrill's one) the protected 
members in a class that's located in another module are not 
accessible, the relationship to the current class the traits code 
is ran into is totally lost and only public members are visible.


when bug() delcaration is `static void bug(T)(T t)`, pointer to 
members are get using __traits(getMember, t, member) and in your 
solution using _this instead of t. So it's a more for a less.


Re: Linker error from dub?

2015-11-11 Thread BBasile via Digitalmars-d-learn

On Thursday, 12 November 2015 at 02:02:56 UTC, Stiff wrote:

Possibly a dumb question, I'm not sure.
[...]
undefined reference to `cblas_dgemm'
collect2: error: ld returned 1 exit status
--- errorlevel 1
dmd failed with exit code 1.


Any suggestions? I do have a blas library installed, but the 
cblas D project isn't docced very well, so I don't know if 
there's a compatibility issue.


Thanks!


You should add something to tell DUB to link your program with 
the openblas static library since cblas is just a binding. For 
example this should work:


{
 "name" : "tcbuilder",
 "description" : "Thalamocortical network parameter 
parser",

 "dependencies" : {
 "cblas": "~>0.1.0",
 "scid": "~>0.3.0"
 },
 "libs" : [
   "openblas"
 ],
}

And install the 'openblas-devel' package of course. Btw I've 
verified with a simple program and it works, although it just 
included cblas, not scid.


Re: Linker error from dub?

2015-11-11 Thread BBasile via Digitalmars-d-learn

On Thursday, 12 November 2015 at 05:44:37 UTC, Stiff wrote:

On Thursday, 12 November 2015 at 05:17:58 UTC, BBasile wrote:

On Thursday, 12 November 2015 at 02:02:56 UTC, Stiff wrote:

Possibly a dumb question, I'm not sure.
[...]
undefined reference to `cblas_dgemm'
collect2: error: ld returned 1 exit status
--- errorlevel 1
dmd failed with exit code 1.


Any suggestions? I do have a blas library installed, but the 
cblas D project isn't docced very well, so I don't know if 
there's a compatibility issue.


Thanks!


You should add something to tell DUB to link your program with 
the openblas static library since cblas is just a binding. For 
example this should work:


{
 "name" : "tcbuilder",
 "description" : "Thalamocortical network parameter 
parser",

 "dependencies" : {
 "cblas": "~>0.1.0",
 "scid": "~>0.3.0"
 },
 "libs" : [
   "openblas"
 ],
}

And install the 'openblas-devel' package of course. Btw I've 
verified with a simple program and it works, although it just 
included cblas, not scid.


Does the libs element from cblas' dub.json not handle that 
library linkage?


If it does work with OpenBLAS, that would seem to suggest that 
"Works with OpenBLAS and others" is a bit more restrictive than 
it sounds...


On my system it only worked with OpenBlas...so now I don't know 
(its quite probable that the other blas libs work..) but what's 
sure is that you have to fill the libs[] to compile the 
application because the blas C library won't be pre-linked when 
compiling cblas. I mean that even if it's done in cblas D binding 
you'll have to add it anyway in the final project.


I suppose I should also mention that it was compiling fine 
before I actually used a function from the library in my code.


It worked fine because it was not used, not parsed, not linked. 
Maybe just the functions declarations was parsed to solve the 
symbols in the program, but since none was used the 'import 
blas.blas' was eliminated or something like that. This could be 
explained better by someone who knows well DMD architecture...


Re: Linker error from dub?

2015-11-11 Thread BBasile via Digitalmars-d-learn

On Thursday, 12 November 2015 at 06:03:49 UTC, BBasile wrote:
It worked fine because it was not used, not parsed, not linked. 
Maybe just the functions declarations was parsed to solve the 
symbols in the program, but since none was used the 'import 
blas.blas' was eliminated or something like that. This could be 
explained better by someone who knows well DMD architecture...


I think that you would get an error with just the 'import 
blas.blas' and building the debug config.


I've spotted a std.expirmental.allocators bug this summer that 
was revealed in by a similar scheme: extern declaration not used 
in release mode, but in debug mode the symbols, even if not used, 
were not eliminated and the compiler complained about undefined 
symbol this & that !





Re: Deprecation: module std.stream is deprecated

2015-11-08 Thread BBasile via Digitalmars-d-learn

On Sunday, 8 November 2015 at 14:41:11 UTC, Spacen Jasset wrote:
But it doesn't seem efficient and strays off the conceptual 
path. In other words, why chunk things up, join them back, to 
get a stream?


`.byChunk` caches and `.joiner` hides this caching mechanism. 
Both operations happen under the hood "incrementally" while using 
the final input range because of lazy evaluation, so if your file 
is big, you are assured that only slices of N bytes (1024 in my 
example) will be loaded at once in the DRAM (unless you 
accumulate the whole thing later). This matches well to a "file 
stream concept", at least to read.


But as said in Jonathan M Davis's answer you can also read the 
whole file in a string or a ubyte[].



Perhaps the problem is that File is missing a .range() function?


Yes but this is a bit like this that phobos ranges and algorithms 
work. You have many independant low-level blocks with which you 
can compose rather than big classes that wrap everything. The 
whole standard library is organized around this.


std.stream was not compliant with this system and this is why 
"they" deprecated it (at least this is how I understood this).


Re: Parse d source file by using compiler

2015-11-08 Thread BBasile via Digitalmars-d-learn

On Monday, 9 November 2015 at 05:49:25 UTC, tcak wrote:
I checked for a flag in this page 
http://dlang.org/dmd-linux.html , but couldn't have found any 
for this purpose.


Is there a way to parse a d source file so it generates a tree 
in JSON, XML, or something-that-can-be-processed-easily file 
format?


---

My real purpose:

I need to generate hash code (e.g. MD5) for a part of source 
code (let's say a class, struct, or a function). So whether the 
codes are changed or not can be detected. As you will guess, 
comments, text formatting etc. shouldn't affect the hash result.



Use-Case:

I am writing a code generator/back up system. It will check the 
last available code file. If important changes are done in a 
specific part of code, it will increase version number by 1.


You could write your own tool using libdparse[1]: parse, visit 
the AST, create a signature for the declarations that are 
interesting.


---
https://github.com/Hackerpilot/libdparse


Re: conver BigInt to string

2015-11-05 Thread BBasile via Digitalmars-d-learn

On Thursday, 5 November 2015 at 16:39:03 UTC, Namal wrote:

On Thursday, 5 November 2015 at 16:35:01 UTC, BBasile wrote:

On Thursday, 5 November 2015 at 16:29:30 UTC, Namal wrote:
Hello I am trying to convert BigInt to string like that while 
trying to sort it:


string s1 = to!string(a).dup.sort;

and get an error

cannot implicitly convert expression 
(_adSortChar(dup(to(a of type char[] to string


what do I do wrong?


try

".idup"

otherwise

"auto s1 = "


auto did it, but idup leads to

Error: can only sort a mutable array


sorry, I feel embarrassed now...good luck i wish you.


Re: conver BigInt to string

2015-11-05 Thread BBasile via Digitalmars-d-learn

On Thursday, 5 November 2015 at 16:29:30 UTC, Namal wrote:
Hello I am trying to convert BigInt to string like that while 
trying to sort it:


string s1 = to!string(a).dup.sort;

and get an error

cannot implicitly convert expression (_adSortChar(dup(to(a 
of type char[] to string


what do I do wrong?


try

".idup"

otherwise

"auto s1 = "


Re: Align a variable on the stack.

2015-11-05 Thread BBasile via Digitalmars-d-learn
On Thursday, 5 November 2015 at 03:52:47 UTC, TheFlyingFiddle 
wrote:

[...]
I solved the problem by changing the struct to look like this.
align(16) struct Pos
{
float x = float.nan;
float y = float.nan;
float z = float.nan;
float w = float.nan;
}



wow that's quite strange. FP members should be initialized 
without initializer ! Eg you should get the same with


align(16) struct Pos
{
 float x, y, ,z, w;
}





Re: How to detect overflow

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

On Wednesday, 4 November 2015 at 03:55:13 UTC, Namal wrote:

Is there a way to detect overflow for example for:

int i = 2_000_000_000;

int a = i*i*i;

writeln(a);

-> 1073741824


You can use core.checkedint [1]

---

http://dlang.org/phobos/core_checkedint.html


Re: How to detect overflow

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

On Wednesday, 4 November 2015 at 07:19:09 UTC, Ali Çehreli wrote:

On 11/03/2015 10:34 PM, Namal wrote:


http://dlang.org/phobos/core_checkedint.html


Is it just an error in the documentation that the return value 
is stated

as sum for the multiplication functions?


Yeah, looks like classic copy-paste errors. :)

Ali


I take the token for this ddoc fix:

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


Re: Access violation when calling C DLL from D

2015-11-01 Thread BBasile via Digitalmars-d-learn

On Monday, 2 November 2015 at 01:02:45 UTC, AnoHito wrote:

[...]
the headers are very long and complicated, and porting them 
entirely to D would be a huge project in and of itself.

[...]


You can give a try at h2d, the C header to D interface converter:

http://dlang.org/htod.html


Re: Static constructors in structs.

2015-10-30 Thread BBasile via Digitalmars-d-learn

On Friday, 30 October 2015 at 20:58:37 UTC, anonymous wrote:

On 30.10.2015 21:23, TheFlyingFiddle wrote:

Is this intended to work?

struct A
{
__gshared static this()
{
   //Add some reflection info to some global stuff.
   addReflectionInfo!(typeof(this));
}
}

I just noticed this works in 2.069, is this intended?


static constructors are supposed to work, yes.

The description is on the class page: 
http://dlang.org/class.html#static-constructor


__gshared doesn't do anything there, though. Use `shared static 
this` instead, if you want the constructor to run only once per 
process, and not once per thread.


__gshared is mostly usefull on fields (eg public uint a) because 
it prevents a data to be put on the TLS, which in certain case 
reduces the perfs up to 30%. The byte code using a global 
variable that's not __gshared can be incredibly slower !


Re: Static constructors in structs.

2015-10-30 Thread BBasile via Digitalmars-d-learn

On Friday, 30 October 2015 at 21:29:22 UTC, BBasile wrote:

On Friday, 30 October 2015 at 20:58:37 UTC, anonymous wrote:

On 30.10.2015 21:23, TheFlyingFiddle wrote:

Is this intended to work?

struct A
{
__gshared static this()
{
   //Add some reflection info to some global stuff.
   addReflectionInfo!(typeof(this));
}
}

I just noticed this works in 2.069, is this intended?


static constructors are supposed to work, yes.

The description is on the class page: 
http://dlang.org/class.html#static-constructor


__gshared doesn't do anything there, though. Use `shared 
static this` instead, if you want the constructor to run only 
once per process, and not once per thread.


__gshared is mostly usefull on fields (eg public uint a) 
because it prevents a data to be put on the TLS, which in 
certain case reduces the perfs up to 30%. The byte code using a 
global variable that's not __gshared can be incredibly slower !


Im' talking about DMD win32 BTW. Even if now I've switched to 
full time linux, I have a test on the hold HDD that demonstrates 
this :). That's really uncredible. Avoid TLS as possible on DMD 
with the switch "-vtls".


Re: How to break gdb on D exception ?

2015-10-04 Thread BBasile via Digitalmars-d-learn

On Friday, 2 October 2015 at 09:15:13 UTC, Dmitri wrote:

On Friday, 2 October 2015 at 04:50:59 UTC, BBasile wrote:

On Friday, 2 October 2015 at 04:46:51 UTC, BBasile wrote:
On Friday, 2 October 2015 at 04:24:11 UTC, Adam D. Ruppe 
wrote:

On Friday, 2 October 2015 at 03:58:45 UTC, BBasile wrote:

none of the following GB commands work:


give

break d_throw

or maybe `break d_throwc` a try


unfortunately it doesn't work, i get

---
(gdb) Function "d_throw"/"d_throwc" not defined.


it was almost that actually,
'break _d_throwc


Or you could break on a specific exception class's constructor.


This would be better.

1/ because I could propose a modifiable list of the exception 
kinds to track in the options).
2/ because with _d_trow_c, info stack #1 is really not 
interesting. #2 or #3 is usually where the 'thing' really happens.


How can I do that, for example with FileException class ?


Re: How to break gdb on D exception ?

2015-10-04 Thread BBasile via Digitalmars-d-learn

On Sunday, 4 October 2015 at 14:31:43 UTC, BBasile wrote:

On Friday, 2 October 2015 at 09:15:13 UTC, Dmitri wrote:

On Friday, 2 October 2015 at 04:50:59 UTC, BBasile wrote:

On Friday, 2 October 2015 at 04:46:51 UTC, BBasile wrote:
On Friday, 2 October 2015 at 04:24:11 UTC, Adam D. Ruppe 
wrote:

[...]


unfortunately it doesn't work, i get

---
(gdb) Function "d_throw"/"d_throwc" not defined.


it was almost that actually,
'break _d_throwc


Or you could break on a specific exception class's constructor.


This would be better.

1/ because I could propose a modifiable list of the exception 
kinds to track in the options).
2/ because with _d_trow_c, info stack #1 is really not 
interesting. #2 or #3 is usually where the 'thing' really 
happens.


How can I do that, for example with FileException class ?


Ast visitor -> ThrowStatement -> detect class from token text -> 
break file:line ?
Puting BP manally is not an option. I ask this for GDB 
integration in my IDE ;)


How to break gdb on D exception ?

2015-10-01 Thread BBasile via Digitalmars-d-learn
Currently it works fine when throwing with core.exception 
functions 'on', like explained in the wiki, for example:

---
break onFinalizeError
---

But I can't manage to break when a new Exception instance is 
thrown in the code:


---
throw new Exception("ouch");
---

none of the following GB commands work:

---
catch catch
catch throw
catch signal all
catch signal
---

It looks like there are some tricks, like put a break on the vtbl 
of the base throwable class (no quite sure about this to be 
honest...)


Does anyone manage this ?


Re: How to break gdb on D exception ?

2015-10-01 Thread BBasile via Digitalmars-d-learn

On Friday, 2 October 2015 at 04:24:11 UTC, Adam D. Ruppe wrote:

On Friday, 2 October 2015 at 03:58:45 UTC, BBasile wrote:

none of the following GB commands work:


give

break d_throw

or maybe `break d_throwc` a try


unfortunately it doesn't work, i get

---
(gdb) Function "d_throw"/"d_throwc" not defined.


Re: How to break gdb on D exception ?

2015-10-01 Thread BBasile via Digitalmars-d-learn

On Friday, 2 October 2015 at 04:46:51 UTC, BBasile wrote:

On Friday, 2 October 2015 at 04:24:11 UTC, Adam D. Ruppe wrote:

On Friday, 2 October 2015 at 03:58:45 UTC, BBasile wrote:

none of the following GB commands work:


give

break d_throw

or maybe `break d_throwc` a try


unfortunately it doesn't work, i get

---
(gdb) Function "d_throw"/"d_throwc" not defined.


it was almost that actually,
'break _d_throwc


Re: How to break gdb on D exception ?

2015-10-01 Thread BBasile via Digitalmars-d-learn

On Friday, 2 October 2015 at 03:58:45 UTC, BBasile wrote:

Does anyone manage this ?

I meant: Does anyone master this ?



Re: All these errors running basic Pegged helloworld example.

2015-09-27 Thread BBasile via Digitalmars-d-learn

On Sunday, 27 September 2015 at 06:30:37 UTC, Enjoys Math wrote:

The example is:

import pegged.grammar;

mixin(grammar(`
Arithmetic:
Term < Factor (Add / Sub)*
Add  < "+" Factor
Sub  < "-" Factor
Factor   < Primary (Mul / Div)*
Mul  < "*" Primary
Div  < "/" Primary
Primary  < Parens / Neg / Pos / Number / Variable
Parens   < "(" Term ")"
Neg  < "-" Primary
Pos  < "+" Primary
Number   < ~([0-9]+)

Variable <- identifier
`));

I'm using Visual D and have C:\MyProjects\D\Pegged (the git 
clone of pegged) added to the add'l imports field under project 
properties > compiler.


I'm getting errors like these:

Error	1	Error 42: Symbol Undefined 
_D6pegged7dynamic7grammar7grammarFAyaHAyaDFS6pegged3peg9ParseTreeZS6pegged3peg9ParseTreeZS6pegged7dynamic7grammar14DynamicGrammar (pegged.dynamic.grammar.DynamicGrammar pegged.dynamic.grammar.grammar(immutable(char)[], pegged.peg.ParseTree delegate(pegged.peg.ParseTree)[immutable(char)[]]))	C:\MyProjects\D\PeggedPractice\	
Error	2	Error 42: Symbol Undefined 
_D6pegged7dynamic7grammar12__ModuleInfoZ	C:\MyProjects\D\PeggedPractice\	


The # of errors was greatly reduced when I added the 3 pegged 
source files to my project.   What can be going wrong?  Thanks!


You must also pass the source root with -I:

-IC:\MyProjects\D\Pegged

(and maybe you miss another source since there are 5:

'..\repos\Pegged\pegged\grammar.d'
'..\repos\Pegged\pegged\parser.d'
'..\repos\Pegged\pegged\peg.d'
'..\repos\Pegged\pegged\dynamic\grammar.d'
'..\repos\Pegged\pegged\dynamic\peg.d'
)

By the way with Coedit you wouldn't have this kind of problems 
(Pegged is part of metaD). You can even run some test on Pegged 
without saving the file / without a project (this is called a 
runnable module). This is just what I've done.


At least compile pegged as a static lib, then it's simpler, you 
just have to pass the -I pegged.lib and your custom sources 
files.


Re: Is there a smart way to process a range of range by front ?

2015-09-23 Thread BBasile via Digitalmars-d-learn
On Wednesday, 23 September 2015 at 21:04:44 UTC, Justin Whear 
wrote:

On Wed, 23 Sep 2015 20:48:03 +, BBasile wrote:

I was thinking to a general *interleave()* algorithm for any 
compatible Range of Range but I can't find any smart way to 
process each sub range by front


Can you show a sample input and output to clarify what you mean 
by interleave?  It's possible that what you want is 
std.range.frontTransversal, std.range.transversal, or 
std.range.transposed.


---
auto r0 = [[0,2],[1,3]];
auto r1 = interleave(r0);
assert(r1 = [0,1,2,3]);
auto r2 = [[0,3],[1,4],[2,5]];
auto r3 = interleave(r2);
assert(r3 = [0,1,2,3,4,5]);
---

the fact that the numbers are ordered is just an helper.




Re: Is there a smart way to process a range of range by front ?

2015-09-23 Thread BBasile via Digitalmars-d-learn

On Wednesday, 23 September 2015 at 21:17:29 UTC, BBasile wrote:
On Wednesday, 23 September 2015 at 21:04:44 UTC, Justin Whear 
wrote:

On Wed, 23 Sep 2015 20:48:03 +, BBasile wrote:

I was thinking to a general *interleave()* algorithm for any 
compatible Range of Range but I can't find any smart way to 
process each sub range by front


Can you show a sample input and output to clarify what you 
mean by interleave?  It's possible that what you want is 
std.range.frontTransversal, std.range.transversal, or 
std.range.transposed.


---
auto r0 = [[0,2],[1,3]];
auto r1 = interleave(r0);
assert(r1 = [0,1,2,3]);
auto r2 = [[0,3],[1,4],[2,5]];
auto r3 = interleave(r2);
assert(r3 = [0,1,2,3,4,5]);
---

the fact that the numbers are ordered is just an helper.


just imagine that there are double equal symbols in the 
assertions...


Re: Is there a smart way to process a range of range by front ?

2015-09-23 Thread BBasile via Digitalmars-d-learn
On Wednesday, 23 September 2015 at 21:24:22 UTC, Justin Whear 
wrote:

On Wed, 23 Sep 2015 21:17:27 +, BBasile wrote:

On Wednesday, 23 September 2015 at 21:04:44 UTC, Justin Whear 
wrote:

On Wed, 23 Sep 2015 20:48:03 +, BBasile wrote:

I was thinking to a general *interleave()* algorithm for any 
compatible Range of Range but I can't find any smart way to 
process each sub range by front


Can you show a sample input and output to clarify what you 
mean by interleave?  It's possible that what you want is 
std.range.frontTransversal, std.range.transversal, or 
std.range.transposed.


---
auto r0 = [[0,2],[1,3]];
auto r1 = interleave(r0);
assert(r1 = [0,1,2,3]);
auto r2 = [[0,3],[1,4],[2,5]];
auto r3 = interleave(r2);
assert(r3 = [0,1,2,3,4,5]);
---

the fact that the numbers are ordered is just an helper.


OK, I think what you're after is std.range.roundRobin.


---
import std.range;

auto interleave(RoR)(RoR r)
{
return r.transposed.join;
}

void main()
{
auto r0 = [[0,2],[1,3]];
auto r1 = interleave(r0);
assert(r1 == [0,1,2,3]);
auto r2 = [[0,3],[1,4],[2,5]];
auto r3 = interleave(r2);
assert(r3 == [0,1,2,3,4,5]);
}
--

thx, but as you was suposing initially 'transposed' works.
didn't know this function before. works fine.


Is there a smart way to process a range of range by front ?

2015-09-23 Thread BBasile via Digitalmars-d-learn
I was thinking to a general *interleave()* algorithm for any 
compatible Range of Range but I can't find any smart way to 
process each sub range by front, eg:


---
void interleave(RoR)(RoR r)
{
   r.each!(a => a.writeln);
}

void main()
{
auto r = [[0,2],[1,3]];
interleave(r);
}
---

will print:
[0,2]
[1,3]

while to interleave i need to take the front of each sub range 
before poping each ror element.


Currently I'm here (don't run this ;)) :

---
auto interleave(RoR)(RoR r)
{
alias T = ElementType!r[0];
T[] result;
while (!empty(r[0]))
r.each!(a => (result ~= a.front, a.popFront));
return result;
}

void main()
{
auto r = [[0,2],[1,3]];
interleave(r);
}
---

but it doesn't work because 'a' is not consumed. It looks like 
it's saved from the input parameter at each iteration of the 
while loop hence it never returns.


Is it possible ?


Re: Building basic gtkd,opengl application

2015-09-20 Thread BBasile via Digitalmars-d-learn

On Sunday, 20 September 2015 at 22:30:54 UTC, Michał wrote:

I am trying to make some application using gtkd and opengl.
I have made simple program but it didn't work and I have no 
idea why.


I have never used gtk so maybe I'm doing something stupid : /

The code:
http://pastebin.com/7NfbMqaK

Error:
http://pastebin.com/vaFAP0bu

Some ideas?
Any tips to gtkd/gtk/gl are welcome.


at least one obvious error: line 37, `MyArea glarea = new 
MyArea();`


`Myarea` scope is limited to the __ctor. You should declare it as 
a class private variable and then instantiate it in the _ctor, 
otherwise. With the GC it's probably still alive til next 
collection but this is nevertheless an error.


Re: Building basic gtkd,opengl application

2015-09-20 Thread BBasile via Digitalmars-d-learn

On Monday, 21 September 2015 at 03:26:36 UTC, BBasile wrote:

On Sunday, 20 September 2015 at 22:30:54 UTC, Michał wrote:

I am trying to make some application using gtkd and opengl.
I have made simple program but it didn't work and I have no 
idea why.


I have never used gtk so maybe I'm doing something stupid : /

The code:
http://pastebin.com/7NfbMqaK

Error:
http://pastebin.com/vaFAP0bu

Some ideas?
Any tips to gtkd/gtk/gl are welcome.


at least one obvious error: line 37, `MyArea glarea = new 
MyArea();`


`Myarea` scope is limited to the __ctor. You should declare it 
as a class private variable and then instantiate it in the 
_ctor, otherwise. With the GC it's probably still alive til 
next collection but this is nevertheless an error.


NVM this is totally wrong. You can create an instance without 
keeping trace of it in a variable. This even something common in 
laguages using ownership and if you don't need to manipulate the 
class instance after its construction... :/


Re: Contracts with interface

2015-09-19 Thread BBasile via Digitalmars-d-learn

On Saturday, 19 September 2015 at 10:33:12 UTC, tchaloupka wrote:

This bites me again:

import std.stdio;

interface ITest
{
void test();

void test2()
in { writeln("itest2"); }

void test3()
in { writeln("itest3"); }

void test4()
in { writeln("itest4"); assert(false); }
}

class Test: ITest
{
void test()
in { writeln("ctest"); }
body { }

void test2()
{
}

void test3()
in { writeln("ctest3"); }
body {}

void test4()
in { writeln("ctest4"); }
body {}
}

void main()
{
auto t = new Test();
t.test();
t.test2();
t.test3();
t.test4();
}

What is expected output?

Docs says just:

[...]


and:

[...]


What I expected is, that if there is no contract in interface 
and is in class implementation - it will be called. Or if 
interface has contract and class implementation doesn't, it 
will be called too.


But apparently it works the way that you have to have the same 
IN contract in both interface and class implementation to be 
safe. So it works the same way as with class inheritance per 
docs.
Which seems at least to me a bit strange and not much usable. 
What's the point of defining contract in interface just to 
write it again in the implementation class?
It's simpler to just write it in the class method body and not 
use the IN contracts at all.

At least a warning would be nice.


This a bug:

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

the problem aalso exist for without using an interface but with 
simple base & derived class.


https://issues.dlang.org/show_bug.cgi?id=6856
https://github.com/D-Programming-Language/dmd/pull/4200


Re: Difference between back (`) and double (") quoted strings

2015-09-18 Thread BBasile via Digitalmars-d-learn
On Saturday, 12 September 2015 at 08:13:33 UTC, Bahman Movaqar 
wrote:
Is there any or they are just simply syntactically equivalent? 
Are there any official docs on this?


it's like a raw string (prefixed with a r) so there is escaped 
char:


r"\": correct token for a string, terminal " is not escaped
`\`: correct token for a string, terminal ` is not escaped
"\": invalid token for a string, " is escaped

so it's usefull on Windows for example, if a litteral string 
contains a path, instead of


"C:\\folder\\file"

you can type

`C:\folder\file`



Re: Difference between back (`) and double (") quoted strings

2015-09-18 Thread BBasile via Digitalmars-d-learn

On Friday, 18 September 2015 at 09:34:38 UTC, BBasile wrote:
On Saturday, 12 September 2015 at 08:13:33 UTC, Bahman Movaqar 
wrote:
Is there any or they are just simply syntactically equivalent? 
Are there any official docs on this?


it's like a raw string (prefixed with a r) so there is escaped 
char:


there **NO** escaped chars...godamnit typo.




Re: Difference between back (`) and double (") quoted strings

2015-09-18 Thread BBasile via Digitalmars-d-learn

On Friday, 18 September 2015 at 09:35:53 UTC, BBasile wrote:

On Friday, 18 September 2015 at 09:34:38 UTC, BBasile wrote:
On Saturday, 12 September 2015 at 08:13:33 UTC, Bahman Movaqar 
wrote:
Is there any or they are just simply syntactically 
equivalent? Are there any official docs on this?


it's like a raw string (prefixed with a r) so there is escaped 
char:


there **NO** escaped chars...godamnit typo.


12 September 2015, '6 days ago',

mh haven't seen this initially. That's embarassing.


Re: Anybody use Derelict FreeType recently (successfully)

2015-09-18 Thread BBasile via Digitalmars-d-learn

On Friday, 18 September 2015 at 00:13:41 UTC, BBasile wrote:
On Thursday, 17 September 2015 at 22:22:22 UTC, WhatMeWorry 
wrote:

[...]
After hours of reading existing freetype/derelict documents, 
I'm stuck again.

Any suggestions. Thanks.


Hello, this[1] compiled dll one works fine here on windows:

- inside this folder:
https://github.com/buggins/dlangui/tree/master/libs/windows/x86

- with DerelictFT head @ 
66dd3dd516c4431b627e299c8b4b5074d6096b51


eg:
---
static this()
{
DerelictFT.load();
}

void main(string[] args)
{
FT_Library handle;
int v0,v1,v2;
FT_Init_FreeType();
FT_Library_Version(handle, , , );
writeln(v0," ",v1," ",v2);
}
---

outputs: 2 5 5

so just clone or download the tarball to get the right dll :)


Is it OK now ?

https://www.youtube.com/watch?v=vDgo2xUk9h8


How not to run after a DUB build ?

2015-09-17 Thread BBasile via Digitalmars-d-learn

Each time I execute

`dub.exe --build=release` (or any other the build type)

DUB tries to run the project after the build.

This generates often generates an error when dub process returns 
(and even if the build is OK) but actually I don't want DUB to 
run after building. Is there a switch to avoid the exexution 
after the build ?


Re: How not to run after a DUB build ?

2015-09-17 Thread BBasile via Digitalmars-d-learn

On Thursday, 17 September 2015 at 19:36:10 UTC, BBasile wrote:

Each time I execute

`dub.exe --build=release` (or any other the build type)

DUB tries to run the project after the build.

This generates often generates an error when dub process 
returns (and even if the build is OK) but actually I don't want 
DUB to run after building. Is there a switch to avoid the 
exexution after the build ?


NVM, just get that 'build' and '--build=' are two different 
things.


with  `dub.exe build --build=release` nothing is executed...


Re: Anybody use Derelict FreeType recently (successfully)

2015-09-17 Thread BBasile via Digitalmars-d-learn

On Thursday, 17 September 2015 at 22:22:22 UTC, WhatMeWorry wrote:

[...]
After hours of reading existing freetype/derelict documents, 
I'm stuck again.

Any suggestions. Thanks.


Hello, this[1] compiled dll one works fine here on windows:

- inside this folder:
https://github.com/buggins/dlangui/tree/master/libs/windows/x86

- with DerelictFT head @ 66dd3dd516c4431b627e299c8b4b5074d6096b51

eg:
---
static this()
{
DerelictFT.load();
}

void main(string[] args)
{
FT_Library handle;
int v0,v1,v2;
FT_Init_FreeType();
FT_Library_Version(handle, , , );
writeln(v0," ",v1," ",v2);
}
---

outputs: 2 5 5

so just clone or download the tarball to get the right dll :)


Re: Runtime error when calling a callback in a parallel Task

2015-09-16 Thread BBasile via Digitalmars-d-learn

On Tuesday, 15 September 2015 at 23:49:23 UTC, BBasile wrote:
Under Windows this works fine but under Linux I got a runtime 
error.


this could be reduced to :
[...]
If it can help to understand the problem, here is the unreducted 
case:


https://github.com/BBasile/Coedit/blob/master/cedast/src/ast.d#L343


Re: Runtime error when calling a callback in a parallel Task

2015-09-16 Thread BBasile via Digitalmars-d-learn
On Wednesday, 16 September 2015 at 18:19:07 UTC, Ali Çehreli 
wrote:

On 09/15/2015 04:49 PM, BBasile wrote:
Under Windows this works fine but under Linux I got a runtime 
error.


Can it be because 'param' is invalid at the time clbck is 
called?


No the callback and its user parameter are set at the same time.

The following program works under Linux. However, removing 
thread_joinAll() is a bug:


I got to try `thread_joinAll`.

The main thread is not a D program so i cant call 
`thread_joinAll` that simply. Maybe as an additonal dll export 
but in this case if `thread_joinAll` does something with the 
Runtime (?) it's quite probable that it won't have an effect. :/


Re: Runtime error when calling a callback in a parallel Task

2015-09-16 Thread BBasile via Digitalmars-d-learn
On Wednesday, 16 September 2015 at 22:30:26 UTC, Ali Çehreli 
wrote:

On 09/16/2015 02:01 PM, BBasile wrote:
> On Wednesday, 16 September 2015 at 18:19:07 UTC, Ali Çehreli
wrote:
>> On 09/15/2015 04:49 PM, BBasile wrote:
>>> Under Windows this works fine but under Linux I got a
runtime error.
>>
>> Can it be because 'param' is invalid at the time clbck is
called?
>
> No the callback and its user parameter are set at the same
time.

I don't want to sound like insisting on my idea but I was more 
concerned about the time when param's life ended. The callback 
is just a function pointer. Functions never die, so there is no 
concern with that. However, the actual variable that 'param' is 
pointing at may have been gone before the callback is executed.


>> The following program works under Linux. However, removing
>> thread_joinAll() is a bug:
>
> I got to try `thread_joinAll`.
>
> The main thread is not a D program so i cant call
`thread_joinAll` that
> simply. Maybe as an additonal dll export but in this case if
> `thread_joinAll` does something with the Runtime (?) it's
quite probable
> that it won't have an effect. :/

In my code, thread_joinAll() simply made main() wait until the 
thread finished. Otherwise, if main() ended before the thread, 
the int data would be invalid when the callback was using a 
pointer to its (old) location.


Ali


No, the param is fine. As said initially:


If i don't use a Task then the program works **fine**.


There is a synchronization problem and only under Linux.
Here is a small program that illustrates better the pattern 
(based on your previous sample):


---
import std.parallelism;

alias CallBack = void function(void*);

class Foreground
{
private Background back;
bool dataAvailable;
this()
{
back = new Background;
back.clbck = 
back.param = cast(void*) this;
}

public void something()
{
dataAvailable = false;
back.call;
}

private static void backgroundFinished(void* param)
{
with (cast(Foreground) param) dataAvailable = true;
}

// lock the access until the background thread notifies that
// interestingData is ready.
Background access()
{
if (dataAvailable)
return back;
else
return null;
}
}

class Background
{
CallBack clbck;
void* param;
private void dotask()
{
// processing on interestingData
if(clbck) clbck(param);  // debugger breaks HERE
}

void call()
{
task().executeInNewThread;
}

public uint interestingData;
}

void main()
{
auto fore = new Foreground();
import std.random;
while (true) // you'll have to kill by hand !
{
// maybe access will be locked
if (uniform(0,100) > 95)
fore.something;
// try to see if access is readable
if (uniform(0,100) > 20)
if (fore.access) {/*can use fore.access.interesting 
data*/}

}
}
---

a class 'A' operating in the main thread is linked to a 
background class 'B' that makes some threaded updates. Other 
classes operating in the main thread can also have an access to 
the backgound class B but only through 'A' and if 'A' doesn't 
lock the access. The access is locked when 'B' is updating in a 
Thread and until 'B' notifies 'A' that the data are ready.


I use a notification because I'm afraid of the results that other 
classes could get when exploiting the 'B' interstingData. They 
only **read** them.


Runtime error when calling a callback in a parallel Task

2015-09-15 Thread BBasile via Digitalmars-d-learn
Under Windows this works fine but under Linux I got a runtime 
error.


this could be reduced to :

---
import std.parallelism;

alias CallBack = void function(void*);

class Foo
{
CallBack clbck;
void* param;
void dotask()
{
// some heavy processing
// tells the caller that some fresh data are available
if(clbck) clbck(param);  // debugger breaks HERE
}

void call()
{
task().executeInNewThread;
// returns directly but the caller will get a notif when 
finished

}
}
---

more info about the environment:
- linux i386
- the D program is actually a .so and the main thread is the exe 
that loads this .so.

- If i don't use a Task then the program works **fine**.

Is it possible to achieve this in a cross platform-way ?
How can i get in phase with the main big thread at the end of my 
task ?


Re: how do I check if a member of a T has a member ?

2015-09-13 Thread BBasile via Digitalmars-d-learn

On Sunday, 13 September 2015 at 17:24:20 UTC, Laeeth Isharc wrote:

On Sunday, 13 September 2015 at 17:09:57 UTC, wobbles wrote:

Use __traits(compiles, date.second)?



Thanks.

This works:

static if (__traits(compiles, { T bar; bar.date.hour;}))
pragma(msg,"hour");
else
pragma(msg,"nohour");



can't you use 'hasMember' (either with __traits() or 
std.traits.hasMember)? It's more idiomatic than checking if it's 
compilable.


Re: private selective import not so private ?

2015-09-10 Thread BBasile via Digitalmars-d-learn

On Friday, 11 September 2015 at 00:55:41 UTC, Adam D. Ruppe wrote:

On Friday, 11 September 2015 at 00:52:00 UTC, BBasile wrote:
While trying to get why some call to memmove without the right 
import didn't lead to a compilation failure i've found that 
imported symbols are not private ! Is that a bug ? The specs 
don't say that a selective import is public !


Yes, it is one of the oldest, most infamous bugs D has, the 
dreaded #314:


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


Damn, you break my joy...


private selective import not so private ?

2015-09-10 Thread BBasile via Digitalmars-d-learn
While trying to get why some call to memmove without the right 
import didn't lead to a compilation failure i've found that 
imported symbols are not private ! Is that a bug ? The specs 
don't say that a selective import is public !


-- other.d --
module other;
private import core.stdc.string: memmove;
-

-- main.d --
module main;
import other;
void main()
{
void* a,b;
memmove(a,b,0);
}


command `dmd main.d other.d: ok compiles without error.
win32, tested with latest beta, and 2 previous versions.


Re: Is D suitable for my latest project?

2015-09-08 Thread BBasile via Digitalmars-d-learn

On Tuesday, 8 September 2015 at 19:30:16 UTC, chris stevens wrote:

On Sunday, 6 September 2015 at 14:45:45 UTC, BBasile wrote:
You have Object.factory for this. You can also use a custom 
factory based on string comparison. (with some: static 
if(condition) return new This; else static if(otherCondition) 
return new That; etc).


I just had a look at Object.factory and this isn't actually 
what I wanted. I was looking for something that would allow me 
to create new (previously undefined) classes in D at runtime 
that I could then use with Object.factory to create instances 
of.


I think I can do this with Variants and dynamic, is this 
possible? Or is there another way?


No, it's not possible with variants. What you want to do is 
actually complex and won't be solved here.


To create a new class instance, the runtime needs the TypeInfo 
class for the class type. Why ? because for example if in a class 
declaration you declare an int initially equal to 1, the TypeInfo 
class provide the memory layout that matches to this initital 
value.


For example this is how class instances are creates in D:

https://github.com/D-Programming-Language/druntime/blob/master/src/rt/lifetime.d#L71

---
extern (C) Object _d_newclass(const ClassInfo ci)
---

without the 'ClassInfo' parameter, you can't get the initial 
state of a class.

This is what the runtime needs to create a class instance.


Re: Are there any Phobos functions to check file permissions on Windows and Posix?

2015-09-07 Thread BBasile via Digitalmars-d-learn
On Sunday, 6 September 2015 at 23:05:29 UTC, Jonathan M Davis 
wrote:
[...] which makes treating some of this stuff in a 
cross-platform fashion quite difficult.


And even more with ACLs that it could be:

On windows, to know properly if something is readable or writable 
the attributes are not enough. One should also check the ACL:


https://msdn.microsoft.com/en-us/library/windows/desktop/aa446659(v=vs.85).aspx

For example you can retieve the flags: 
archive/readonly/hidden/system/indexable(?) and even if it looks 
writable or readable, the file won't be open at all because the 
ACL for the file don't include the current user account.





Re: Is D suitable for my latest project?

2015-09-06 Thread BBasile via Digitalmars-d-learn

On Sunday, 6 September 2015 at 14:36:53 UTC, chris stevens wrote:

- dynamic creation of classes/structs at runtime.


You have Object.factory for this. You can also use a custom 
factory based on string comparison. (with some: static 
if(condition) return new This; else static if(otherCondition) 
return new That; etc).



- dynamic compilation of code files at runtime


use std.process to call a compiler.


- some basic code creation tools


if you mean to generate code as string, writing them to a file, 
of course it will work in D.


Re: Windows Resources

2015-09-05 Thread BBasile via Digitalmars-d-learn

On Saturday, 5 September 2015 at 19:06:15 UTC, Prudence wrote:

[...]


Check this file 
https://github.com/D-Programming-Language/dmd/blob/master/samples/winsamp.d ,it's distributed with your D setup.


Re: Create a delegate function

2015-09-05 Thread BBasile via Digitalmars-d-learn

On Saturday, 5 September 2015 at 18:00:53 UTC, Prudence wrote:
I have code setup in such a way that I call a user defined 
function, e.g.,


void myFunc(Data d)
{

}

myFunc has to be passed to the main code using something like

void SetFunc(void function(Data) func) { ... func(myData); }

What I would like to do is, instead of having to pass data to 
myFunc(and use the type Data in all the function types), is to 
sort of create a delegate:


what I want to do:

void myFunc()
{
  this.d;  // Ok, because somehow this = Data;
}

then, of course,

void SetFunc(void delegate() func) { func.context = myData; 
func(); }





void delegate() dg =
{
auto t = this;
return;
};

doesn't even work because this is not defined.


My guess this is impossible without compiler support.

effectively though, I don't see why we can't use this(because 
myFunc is being executed in a context, I simply want to set it 
to the right one so that the user can take advantage of it... 
instead of having to pass an argument instead.



Any ideas how to do this? It seems we can't actually create 
"delegate objects" but only delegate pointers? (simply because 
of the restrictions the compiler places on *this*. (can't be 
used outside of a context, even though we can always guarantee 
it is in a context)


How bout a new syntax for such concepts?

void delegate!T(...) dg
{

}

// identical to

void dg(T this, ...)
{

}


Hence, to call dg, we have to pass it a "this" object... hence 
it has a context. They can be called just like functions. 
dg(myData, ...);


Wow, it's hard to get what you mean. It's a bit confuse.
But, IIUC you want to link the parameter value to the delegate 
type ?
If so then it's time for you to lean 'std.typecons.Tuple' and 
'std.typecons.tuple'.


For example, is this what you meant ?

---
module runnable;

import std.stdio;
import std.typecons;
import std.traits;

alias Fun = void function(int);
alias FunAndData = Tuple!(Fun, ParameterTypeTuple!Fun);

struct MainCode
{
int myData;
void setFunc(FunAndData funAndData)
{
funAndData[0](funAndData[1..$]);
}
}

void test(int param)
{
writeln(param);
}

void main(string[] args)
{
MainCode mainCode;
mainCode.setFunc(tuple(,46));
}
---


Re: Working Windows GUI library?

2015-09-03 Thread BBasile via Digitalmars-d-learn
On Thursday, 3 September 2015 at 15:46:28 UTC, Andre Polykanine 
wrote:

[...]


Hello, there this one: https://github.com/nomad-software/tkd


[...]


I don't know what you meant by 'accessible' but the two 
respective runtimes exist for windows.


Re: Prefer Signed or Unsigned in D?

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

On Tuesday, 1 September 2015 at 23:06:50 UTC, John Carter wrote:

C/C++ discussion here

   http://blog.robertelder.org/signed-or-unsigned-part-2/

D rules here...

   http://dlang.org/type.html#integer-promotions


It depends on the context.

You should take care of blending signed and unsigned:
comparison error, a is > b but...
---
uint a = 1;
int b = -1;
assert(a < b); // does not throw
---

You should take care to the index type in a loop:
loop that doesn't run at all because of an infered unsigned 
index...

---
auto array = new int[](8);
for (auto i = array.length - 1; i > -1; i--)
array[i] = 8;
assert(array[0] == 0); // does not throw
---


Re: Error Compiling with -debug swtich

2015-08-30 Thread BBasile via Digitalmars-d-learn

On Thursday, 27 August 2015 at 22:09:07 UTC, Jordan Wilson wrote:

Hello,

Just wondering why compiling the following fails with the 
-debug switch, but appears to compile and execute fine without 
it:


import std.stdio;
import std.algorithm;
import std.container;

int main(string[] args) {
Array!string letters = [b,a,c];
sort(letters[]);
writeln (letters[]); // [a,b,c]
return 0;
}

With the -debug switch, I get:
src\phobos\std\range\package.d(7180): Error: 
'std.range.SortedRange!(RangeT!(Array!string), a  
b).SortedRange.dbgVerifySorted' is not nothrow
src\phobos\std\algorithm\sorting.d(982): Error: template 
instance std.range.assumeSorted!(a  b, 
RangeT!(Array!string)) error instantiating


Without the switch, everything seems to work fine...(I'm using 
DMD 2.068.0)


Thanks,

Jordan


filed a BR: https://issues.dlang.org/show_bug.cgi?id=14981


Re: observation: D getting a bit complex

2015-08-30 Thread BBasile via Digitalmars-d-learn

On Sunday, 30 August 2015 at 10:42:24 UTC, Spacen Jasset wrote:

On Sunday, 30 August 2015 at 07:36:55 UTC, BBasile wrote:

On Sunday, 30 August 2015 at 02:42:30 UTC, Spacen Jasset wrote:
immutable(ElementEncodingType!(ElementType!Range))[] 
buildPath(Range)(Range segments) if (isInputRange!Range  
isSomeString!(ElementType!Range));
pure nothrow @safe immutable(C)[] buildPath(C)(const(C)[][] 
paths...) if (isSomeChar!C);


this is stodgy, particularly in a console with line wrapping 
at 80 chars.



To be fair it was the docs page I was reading not a compiler 
diagnostic, but I did get something a bit shorter from the 
compiler once.


Oh i see. Then i don't agree. Doc is very nice. The problem is 
that you have to know std.traits and std.range to understand the 
constraints. It's not always obvious but i'd say it's about 30 or 
40 functions.





Re: observation: D getting a bit complex

2015-08-30 Thread BBasile via Digitalmars-d-learn

On Sunday, 30 August 2015 at 02:42:30 UTC, Spacen Jasset wrote:
immutable(ElementEncodingType!(ElementType!Range))[] 
buildPath(Range)(Range segments) if (isInputRange!Range  
isSomeString!(ElementType!Range));
pure nothrow @safe immutable(C)[] buildPath(C)(const(C)[][] 
paths...) if (isSomeChar!C);


this is stodgy, particularly in a console with line wrapping at 
80 chars.




Re: stuck on opDiv / opBinary

2015-08-30 Thread BBasile via Digitalmars-d-learn

On Sunday, 30 August 2015 at 17:02:58 UTC, Spacen Jasset wrote:
I have just added an opDiv to this class, but it doesn't seem 
to pick it up.
math/vector.d(30): Error: 'this /= mag' is not a scalar, it is 
a Vector3


I can't see why that is, becuase my opMul works in the same 
place. Can anyone point out what I have done wrong?


Class Matrix {

void normalise()
{
const float mag = magnitude();
if (mag) {
//this.scalarDivide(mag);
this /= mag; // Not work
this *= 1/mag; // Does work.

}
}

//Vector3 opBinary(string op)(Vector3 rhs) if (op=='/')
Vector3 opDiv(float scalar)
{
Vector3 v = this;
v.scalarDivide(scalar);
return v;
}

}


try

---
Vector3 opBinary(string op)(Vector3 rhs)
{
static if (op ==/){}
else static assert(0, op ~  not implemented);
}
---

you used the char litteral delims ('') instead of the strings 
ones ().


Re: Arrays of structs

2015-08-27 Thread BBasile via Digitalmars-d-learn

On Thursday, 27 August 2015 at 11:45:14 UTC, anonymous wrote:

On Thursday 27 August 2015 13:15, BBasile wrote:


https://github.com/BBasile/iz/blob/master/import/iz/types.d#L125 
https://github.com/BBasile/iz/blob/master/import/iz/types.d#L150 
https://github.com/BBasile/iz/blob/master/import/iz/types.d#L191


Your use of @trusted is wrong and dangerous. @trusted functions 
are supposed to be memory-safe, but you're marking unsafe 
functions with it.


Things like a @trusted `free` [1] are just plain wrong. `free` 
isn't memory- safe.


The problems with @trusted templates can be more subtle. Even 
if the template body itself doesn't do anything unsafe, the 
template arguments are being trusted, too. So if the template 
ever calls any code from the arguments (including constructors, 
destructors, postblits, ...), then it cannot be marked @trusted.



[1] 
https://github.com/BBasile/iz/blob/master/import/iz/types.d#L112


the pointer is checked before the call. Yes it can be dangling 
but free goes in pair with the newPtr funct. I plan to do better 
when Andrei's allocators will be released:

https://github.com/BBasile/phobos/blob/showcase-construct/std/experimental/allocator/showcase.d#L105

Anyway. I cheat a bit with attributes but as long as it's only 
for me...I know this kinds of functions are not phobos-level.


Re: Arrays of structs

2015-08-27 Thread BBasile via Digitalmars-d-learn

On Thursday, 27 August 2015 at 12:56:26 UTC, anonymous wrote:

On Thursday 27 August 2015 14:35, BBasile wrote:

Anyway. I cheat a bit with attributes but as long as it's only 
for me...I know this kinds of functions are not phobos-level.


Sure, as long as you're cautious and regard those functions as 
unsafe, you may be fine. You still risk accidentally writing 
unsafe code that's marked @safe, but that's up to you.


But when you show such code in the learn group, I think it's 
important to point out that this usage of @trusted is wrong. If 
only to warn newbies about it.


:handshake:


Re: Arrays of structs

2015-08-27 Thread BBasile via Digitalmars-d-learn

On Thursday, 27 August 2015 at 10:05:31 UTC, John Burton wrote:
I'm a c++ programmer trying to understand how memory allocation 
works in D.


I created a struct and added a destructor to it. My 
understanding is that structs have deterministic destructors - 
they are called when the struct goes out of scope (unless it is 
allocated with new).


Now if I put instances of the struct in a fixed size array

data[6] d;
d[3] = data(1, 2, 3);

then the destructor on all the contents is called when the 
array goes out of scope.


However if I add them to a dynamic array...

data[] d;
d ~= data(1, 2, 3)

Then the destructor appears to be called at some random time 
later. So it looks like it's the garbage collection that is 
doing this. That seems to go against the specification of how 
struct works... I'm not creating the item with new and as far 
as I can tell the array is storing instances of objects, not 
pointers to objects?


Is my understanding correct?
Is it documented anywhere how memory allocation works for this?

Is a dynamic array in fact storing an array of GC'd pointers to 
the structs? Or something else...


With a local scope,
- a static array  of data will have the destructors called on 
exit because memory for the memebers is not allocated on the 
GC-hep but on the stack frame.
- a dynamic array  of data will have the destructors called on 
next GC collection because the memory for the memebers is 
allocated on the GC-heap.
- a dynamic array of pointer to data will have the destructors 
called on next GC collection because the memory for the memebers 
is allocated on the GC-heap.


you can see this in this small program. deactivate to commented 
GC.collect to see the difference:


---
struct Foo {
long v0, v1;
~this(){writeln(typeof(this).stringof);}
}

void localteststatic(){
Foo[1] fl;
}

void localtestdynamic1(){
Foo[] fl;
fl.length = 1;
fl.length = 0;
}

void localtestdynamic2(){
Foo* [] fl;
fl ~= new Foo(1);
}

void localtestdynamic3(){
Foo[] fl;
fl.length = 1;
fl.length = 0;
}

void main(string[] args)
{
import core.memory;
localteststatic; writeln(done local test static);
localtestdynamic3; writeln(done local test dynamic 3);
//GC.collect;
localtestdynamic1; writeln(done local test dynamic 1);
//GC.collect;
localtestdynamic2;  writeln(done local test dynamic 2);
//GC.collect;
}
---

Also for the second question:
* fl[]: each element has a .sizeof 16 (long .size_of * 2)
* fl* []: each element has a .sizeof size_t.sizeof (this a 
pointer so 4 or 8).


Re: Arrays of structs

2015-08-27 Thread BBasile via Digitalmars-d-learn

On Thursday, 27 August 2015 at 10:49:02 UTC, John Burton wrote:
Thanks again for the updates. I've experimented some more and 
believe I understand.


To be honest I'm finding it very hard to find the right idioms 
in D for safe and efficient programming when I'm so used to C++ 
/ RAII everywhere. I'll adapt though :P


You can also do explicit
* memory allocation/deallocation
* class construction/destruction
* struct/union construction/destruction

Personally my background is Object-Pascal/Delphi which use 
similar memory managment to C++ (though more RAII with ownership 
than RAII with refcounting). For example I have those routines in 
my home-cooked general library:


https://github.com/BBasile/iz/blob/master/import/iz/types.d#L125
https://github.com/BBasile/iz/blob/master/import/iz/types.d#L150
https://github.com/BBasile/iz/blob/master/import/iz/types.d#L191

they allow to do manual memory managment and you'll find similar 
routines in several other user libraries, for example

* https://github.com/etcimon/memutils
* https://github.com/Dgame/m3
* etc...




Re: linking-in libs under linux needed and not under windows

2015-08-27 Thread BBasile via Digitalmars-d-learn

On Thursday, 27 August 2015 at 04:57:14 UTC, Adam D. Ruppe wrote:

On Thursday, 27 August 2015 at 02:50:58 UTC, BBasile wrote:

So the Q: Is this difference normal ?


Yes, it is a feature the Windows format supports but the Linux 
one doesn't. On Linux, you need to list the libraries on the 
command line again.


This is a bit what i wanted to hear, so I hope that your answer 
is not pernicious.


Strangely, I've forgot to tell that in the original post, if I 
use the procedure that works for Linux but on Windows, I get some 
multiple definition of ... error messages. Because in this case 
the *.lib are really linked at each step.


Re: linking-in libs under linux needed and not under windows

2015-08-26 Thread BBasile via Digitalmars-d-learn

On Thursday, 27 August 2015 at 02:50:58 UTC, BBasile wrote:

So the Q: Is this difference normal ?

the win OMF  linux COFF thing maybe ?





linking-in libs under linux needed and not under windows

2015-08-26 Thread BBasile via Digitalmars-d-learn

let's say i have 'libA', 'libB' and 'Project'
- libB uses libA
- Project uses libB

under Windows (32 bit, OMF objects, Digital Mars linker, so the 
standard setup):

-

* libA is compiled with: dmd sourceA.d -lib
* libB is compiled with: dmd sourceB.d -lib -IpathToSourceA
* Project is compiled with: dmd sourceProject.d libA.lib libB.lib 
-IpathToSourceA -IpathToSourceB


and it just works fine

under Linux (64 bit, also the standard setup):
---

The same procedure fails with some messages (undefined this and 
that...) but

if i link incrementaly (so i link libA in libB) it works:

* libA is compiled with: dmd sourceA.d -lib
* libB is compiled with: dmd sourceB.d libA.a -lib 
-IpathToSourceA
* Project is compiled with: dmd sourceProject.d libA.a libB.a 
-IpathToSourceA -IpathToSourceB



So the Q: Is this difference normal ?


Why I ask this ?
The problem is that I've made a change to Coedit recently that is 
based on the way it works on Windows:

https://github.com/BBasile/Coedit/blob/master/src/ce_nativeproject.pas#L373
That does that: libraries files are only passed when the output 
binary must contain everything (so an executable). The problem is 
verified with a lib which uses two Derelict libs that use 
themselves DerelictUtil...I could just put a compiler switch in 
the .pas source to have the right behaviour according to the 
platform but i'd like an explanation...this difference looks 
weird.


Re: Trying to compile weather program

2015-08-23 Thread BBasile via Digitalmars-d-learn

On Sunday, 23 August 2015 at 09:54:37 UTC, Tony wrote:
I found this weather program on the main page (it seems to 
rotate what it here):


[...]


try with `center()` or update the compiler. centerJustifier() was 
added on 25 Apr 2015 so after 2.066.1 release:


https://github.com/D-Programming-Language/phobos/commit/f85101eea1b875311e5716143cd6346fe4655f02


Re: Appender at CTFE?

2015-08-22 Thread BBasile via Digitalmars-d-learn

On Friday, 21 August 2015 at 23:51:16 UTC, cym13 wrote:
On Friday, 21 August 2015 at 22:39:29 UTC, Nick Sabalausky 
wrote:
Not at a pc, so can't test right now, but does Appender work 
at compile time? If not, does ~= still blow up CTFE memory 
usage like it used to? Any other best practice / trick for 
building strings in CTFE?


I did two experiments:

[...]

Each make use of CTFE but the f (appender) variant blew my RAM 
(old computer)


Excepted any error from my part, shouldn't you call '.reserve' in 
order to make the appender efficient ?






Re: most elegant functional way to make a histogram

2015-08-21 Thread BBasile via Digitalmars-d-learn

On Friday, 21 August 2015 at 20:09:22 UTC, Laeeth Isharc wrote:
I have four arrays of ints, each array representing a kind of 
event associated with that int (they all map to the same 
space).  Each array might have the same number multiple times 
and each array will be of different length.


So I would like to plot the int line on x axis and show number 
of times that the number occurs for each array (4 bars for each 
int).


It's easy to do with loops, but what's best 
functional/algorithmic way, please?  Brain tired today.  I am 
trying to use these opportunities to learn the algorithmic way 
even if loop is more natural.


I could just make four new arrays of ints and use each instead 
of a loop.  Any better way?


Also, for bucketizing, any thoughts on best way to do using 
phobos?  (Cos probably I have too many ints and need to bracket 
them to plot a histogram).


Sorry if this is unclear.


Laeeth.


loop-less approach, it consumes an InputRange in a recursive 
function.

Assuming histogramData is a custom InputRange:

---
void upperLevel()
{
//histogramData = ...
proc(histogramData);
// continue once the range is consumed
}

void proc(ref histogramData)
{
//something with front
histogramData.popFront;
if (!histogramData.empty)
proc(histogramData);
}
---

I don't know if this approach can be used but this is an 
alternative to loops.
Not necessarily the best because local variables in proc() can 
lead to a stack overflow.


Re: Real OOP with D

2015-08-18 Thread BBasile via Digitalmars-d-learn

On Tuesday, 18 August 2015 at 06:27:53 UTC, Ozan wrote:

On Monday, 17 August 2015 at 06:59:51 UTC, BBasile wrote:

On Monday, 17 August 2015 at 05:57:52 UTC, Ozan wrote:

Hi

[...]


Is there any way to get real OOP with D?

Regards,  Ozan


Can you name an OOP oriented language that allows this ? Your 
example is eroneous OOP.
The 2 other answers you 've got (the first using an interface 
and the second using an abstract class) are valid OOP.


One of the fundamental concept OOP is that a function defined 
in a class exists also  in its subclasses. So how do you 
expect `greeting()` to exist in Family if it's only defined in 
its sub-classes ?


You can verify that with the 'Liskov substitution principle' 
(https://en.wikipedia.org/wiki/Liskov_substitution_principle).

Actually your sample violates this principle.


Languages like Groovy or JavaScript (with the help of 
frameworks ;-)
And I believe many more the newer ones.  But that's not the 
point.


And... This was not a criticism against D (... bad D, has no 
understanding of OOP. Boahh  ;-)
It was only a question about handling of a typical OOP problem 
in a class-typed implementation of OOP like D has. Thanks to 
every existing or new creative programming language, today we 
have so many other ways to solve our programming problems.


Regards Ozan


You example is not valid strongly-typed OOP. In D you could do 
something similar but not with the OO paradigm but rather with 
compile-time refexion (introspection):


---
import std.stdio;

static bool isFamilyMember(T)()
{
import std.traits: isCallable;
return __traits(hasMember, T, greeting);
}

void FamilyMemberSayHello(T)(ref T t)
{
static if (isFamilyMember!T)
t.greeting;
}

struct Dad{
void greeting(){hello from a Dad.writeln;}
}

struct Boy{
void greeting(){hello from a Boy.writeln;}
}

struct IdiotDuBled{}

void main()
{
auto dad = new Dad;
auto boy = new Boy;
auto idiotDuBled = new IdiotDuBled;

FamilyMemberSayHello(dad);
FamilyMemberSayHello(boy);
FamilyMemberSayHello(idiotDuBled);
}
---

The idea is rather to check at compile time if a variable will 
have the trait which characterizes a FamilyMember, without 
using inheritence.


Re: Real OOP with D

2015-08-17 Thread BBasile via Digitalmars-d-learn

On Monday, 17 August 2015 at 05:57:52 UTC, Ozan wrote:

Hi

Working with objectoriented concepts results often in large 
trees of related classes. Every instance of a class knows his 
methods and data.  An example like following would work:


import std.stdio;
class Family { }
class Dad : Family { void greeting() { writeln(I'm dad); } }
class Boy : Family { void greeting() { writeln(I'm daddy's 
boy); } }

void main() {
writeln(Father and son);
Dad father = new Dad;
Family son = new Boy;
father.greeting;
son.greeting;
}

The critical point is using a variable of type Family for an 
instance of Boy. Class Family covers the greeting method of 
Boy. In real OOP that would not be a problem, because the 
access point of view starts with the object. In D, it starts 
with the class definition.


Is there any way to get real OOP with D?

Regards,  Ozan


Can you name an OOP oriented language that allows this ? Your 
example is eroneous OOP.
The 2 other answers you 've got (the first using an interface and 
the second using an abstract class) are valid OOP.


One of the fundamental concept OOP is that a function defined in 
a class exists also  in its subclasses. So how do you expect 
`greeting()` to exist in Family if it's only defined in its 
sub-classes ?


You can verify that with the 'Liskov substitution principle' 
(https://en.wikipedia.org/wiki/Liskov_substitution_principle).

Actually your sample violates this principle.


Re: pragma(mangle, on a template)

2015-08-16 Thread BBasile via Digitalmars-d-learn

On Monday, 17 August 2015 at 02:46:02 UTC, Freddy wrote:

I can't get pragma(mangle) to work on templates(or structs).
[...]


I don't know why but it looks like it only works on functions. 
Even if a struct is not a template the custom symbol mangle won't 
be handled:


---
import std.stdio;

pragma(mangle, a0) class MyClass{}
pragma(mangle, a1) struct MyStruct{}
pragma(mangle, a2) void body_func();
pragma(mangle, a3) struct MyStructh
{ pragma(mangle, a4) void foo(){}}

void main()
{
writeln(MyClass.mangleof);
writeln(MyStruct.mangleof);
writeln(body_func.mangleof);
writeln(MyStructh.mangleof);
writeln(MyStructh.foo.mangleof);
}
---

which outputs:

---
C13temp_019455687MyClass
S13temp_019455688MyStruct
a2
S13temp_019455689MyStructh
a4
---

'a4' being printed and not 'a3' is interesting BTW ;)
I think that the manual is not clear enough about this pragma:

http://dlang.org/pragma.html#mangle

Unless the spec. are more detailed this could be considered as a 
bug.




Re: Weird error message.

2015-08-16 Thread BBasile via Digitalmars-d-learn

On Monday, 17 August 2015 at 00:00:11 UTC, Jonathan M Davis wrote:
On Sunday, August 16, 2015 21:32:08 Warwick via 
Digitalmars-d-learn wrote:
Dont know what to make of this, I pretty much get it every 
other time I call rdmd. It'll alternate between running fine 
and then giving me this error...


C:\Program Files (x86)\Notepad++rdmd J:\Code\statproc.d
std.process.ProcessException@std\process.d(550): Failed to 
spawn

new process (The process cannot access the file because
  it is being used by another process.)
[...]
Any ideas?


Well, Windows has file locks, so tyically, if one program has a 
[...]

Personally, I wish that Windows didn't have file locks... :(


It's locked unless it's specified during the call to 
`CreateFile()` that the file can be shared for reading/writing 
(FILE_SHARE_READ / FILE_SHARE_WRITE).






Re: Template Collections of Different Types

2015-08-15 Thread BBasile via Digitalmars-d-learn

On Sunday, 16 August 2015 at 01:39:54 UTC, DarthCthulhu wrote:

Say I want to do something like:

Propertery!int pi = 42;
PropertyCollection pc;

pc.attach(Life_and_Everything, pi);

assert(pc.Life_and_Everything == 42);

Property!string ps = Hello World;

pc.attach(text, ps);

assert(pc.text == Hello World);

How would one store the Property objects in the 
PropertyCollection? You can't use something like an array 
because the two Properties are of different types. Do you 
really need to do something like make a member of 
PropertyCollection for every type of Property you are 
interested in storing and using static ifs to determine which 
variable it goes into?


I feel like there is an obvious solution here that I'm missing.


You would need a kind of type info system:

---
enum Ti {tibyte, tiubyte, ...}
Ti getTypeInfo(T)(T t){statif is(t == ubyte) return Ti.tibyte; 
else...}


pc.attach(Life_and_Everything, pi, getTypeInfo(pi));
pc.attach(BlaBlaBla, pi, getTypeInfo(pi));
pc.attach(zkfozekf, 42, getTypeInfo(42));
---

internally the container would store 3 infos (string, pointer to 
data and a Ti) and when you query a property from its identifier, 
it looks for the attached type info so that you can cast the 
result (let's say it would return a pointer).


---
TypeInfo getTypeInfo(string identifier);
void* getValue(string identifier);
---

These kind of mechanism are really common in languages that have 
a poor/none compile time reflection features, but in D you would 
have to build your own run time type info system. My example is a 
bit shitty but you should get the idea.


Re: Associative array literal. Why doesn't it compile?

2015-08-14 Thread BBasile via Digitalmars-d-learn

On Friday, 14 August 2015 at 06:48:27 UTC, Adel Mamin wrote:

Compiler dmd_2.068.0-0_amd64.deb on Ubuntu 12.04 Linux:

auto lookup = [ one:1, two:2 ];

The dmd error:
Error: non-constant expression [one:1, two:2]

Why doesn't it compile?
As a workaround I could do the assignment one element at a time 
in a loop. It would be uglier though.


It's because of the key type (string is a library type). You have 
to initialize it by hand. Explanation here:


http://stackoverflow.com/a/26862994/3661500

see the comment of Adam D. Ruppe. Although this case was 'a bit' 
different since the AA had to be immutable (in this case it was 
only possible to initialize it in a static module constructor or 
in class/struct constructor). But it's almost the same problem.


Re: Derelict, SDL, and OpenGL3: Triangle Tribulations

2015-08-12 Thread BBasile via Digitalmars-d-learn

On Wednesday, 12 August 2015 at 05:46:27 UTC, Mike Parker wrote:

On Wednesday, 12 August 2015 at 05:34:22 UTC, BBasile wrote:

[...]



It seems to me that your driver is doing things it isn't 
actually supposed to do. This code is binding a vertex buffer 
object with a function which is supposed to bind a vertex array 
object. The only reason the vbo is bound at all is because of 
the call to glBindBuffer in the misnamed initVAO -- a function 
which never even initializes a vao. The spec actually requires 
a vao to be created and a shader program to be bound, so I 
would expect a conforming driver to show nothing.


I expect a couple of calls to glError will not come up empty.


Right, the triangle is well drawn but glGetError returns 1282. 
Maybe the OP has a different OGL implementation. At least NVidia 
driver renders a triangle for this code.


Re: Derelict, SDL, and OpenGL3: Triangle Tribulations

2015-08-11 Thread BBasile via Digitalmars-d-learn

On Wednesday, 12 August 2015 at 03:32:47 UTC, DarthCthulhu wrote:
So I decided to try some OGL3 stuff in D utilizing the Derelict 
bindings and SDL. Creating an SDL-OGL window worked fine, but 
I'm having trouble with doing the most basic thing of rendering 
a triangle. I get the window just fine and the screen is being 
properly cleared and buffered, but no triangle.


So, any ideas what I'm doing wrong?


For me the following code works:

---
import derelict.sdl2.sdl;
import derelict.opengl3.gl3;
import derelict.opengl3.gl;

import std.stdio;

static this()
{
DerelictGL3.load;
DerelictGL.load;
DerelictSDL2.load;
SDL_Init(SDL_INIT_VIDEO);
}

static ~this()
{
SDL_Quit();
DerelictGL3.unload;
DerelictSDL2.unload;
}

GLuint initVAO () {

// An array of 3 vectors which represents 3 vertices
static const GLfloat[] g_vertex_buffer_data = [
  -1.0f, -1.0f, 0.0f,
   1.0f, -1.0f, 0.0f,
   0.0f, 1.0f, 0.0f,
];

// This will identify our vertex buffer
GLuint vertexbuffer;

	// Generate 1 buffer, put the resulting identifier in 
vertexbuffer

glGenBuffers(1, vertexbuffer);

	// The following commands will talk about our 'vertexbuffer' 
buffer

glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);

// Give our vertices to OpenGL.
	glBufferData(GL_ARRAY_BUFFER, g_vertex_buffer_data.length * 
GL_FLOAT.sizeof, g_vertex_buffer_data.ptr, GL_STATIC_DRAW);


glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0,  null);  

glBindBuffer(GL_ARRAY_BUFFER, 0);

return vertexbuffer;
}

void main(string[] args)
{

auto flags =  SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | 
SDL_WINDOW_RESIZABLE;

auto win = SDL_CreateWindow( null, 50, 50, 800, 600, flags);
auto ctxt = SDL_GL_CreateContext(win);

DerelictGL3.reload;

GLuint vertexbuffer = initVAO();

SDL_Event ev;
while (true)
{
if (SDL_WaitEvent(ev))
{
glClear(GL_COLOR_BUFFER_BIT);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glBindVertexArray(vertexbuffer);

// Draw the triangle
glDrawArrays(GL_TRIANGLES, 0, 3);

glDisableVertexAttribArray(vertexbuffer);
glBindVertexArray(0);

SDL_GL_SwapWindow(SDL_GL_GetCurrentWindow());
}
if (ev.type == SDL_QUIT)
break;
}

SDL_DestroyWindow(win);
SDL_GL_DeleteContext(ctxt);
}
---

It looks like it's the window/context creation that fail for you 
because the OpenGL code is 100% the same.


Re: Import template in phobos

2015-08-01 Thread BBasile via Digitalmars-d-learn

On Saturday, 1 August 2015 at 14:42:47 UTC, vit wrote:

Exist in phobos something like Import template?

public import std.traits;

template Import(alias Module){
mixin(import  ~ moduleName!Module ~ ;);
}

class C;

struct Test{
Import!(std.typecons).Rebindable!C test;//symbols
}


Not very clear. from your '//symbols' comment I deduce that you 
want to turn a template into a local symbol.


To do so use an 'alias expression':

---
import std.typecons: Rebindable;
alias symbolIdentifier = Rebindable!C;
---

see http://dlang.org/declaration.html#alias for full spec.


Re: Static arrays inside struct and class - bug?

2015-08-01 Thread BBasile via Digitalmars-d-learn

On Saturday, 1 August 2015 at 17:22:40 UTC, NX wrote:

I wonder if the followings are compiler bugs:

class stuff_class
{
   byte[1024*1024*16] arr; // Error: index 16777216 overflow 
for static array

}

struct stuff
{
   byte[1024*1024*16] arr; // Error: index 16777216 overflow 
for static array

}

My project has just stopped for this reason, I was trying to 
hack into another process memory with something similar to this:

   stuff data;
   ReadProcessMemory(Proc, (void*)0xA970F4, data, 
stuff.sizeof, null);
Target program is written in C++ and because of this limitation 
I'm not able to write equivalent code and here I'm stuck.


There a limit for static array size. This limits is exactly 16MB 
so 1024*1024*16.

Remove one element:

byte[1024*1024*16-1] arr;