Re: [dub] specify dependency configuration

2015-01-18 Thread cal via Digitalmars-d-learn
On Monday, 19 January 2015 at 02:10:41 UTC, Rikki Cattermole 
wrote:
I just want to verify, you are using configurations only to 
determine if its being built a certain way?

And not lets say as a subpackage?


Some dependency (that I don't control) might define for example 
two configurations, a sourceLibrary type and a library type (my 
own app does not define it's own configurations). I'm just 
wondering if there is a way to tell dub i'm only interested in 
using that dependency as a sourceLibrary for example.


Re: [dub] specify dependency configuration

2015-01-18 Thread cal via Digitalmars-d-learn
On Monday, 19 January 2015 at 02:10:41 UTC, Rikki Cattermole 
wrote:

subConfigurations: {
somepackage: glut-app
}
}


Ahh I guess this is it, thanks for that!




[dub] specify dependency configuration

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

Given myapp and a dependency, specified by dub.json's:

myapp: dub.json
{
  ...
  dependencies: {
dependency_a: =0.6.0
  }
  ...
}

dependency_a: dub.json
{
  ...
  configurations: [
  {
name: config_a,
targetType: library,
...
  },
  {
name: config_b,
targetType: executable,
...
  },
  ...
}

How do I specify (in myapp: dub.json) that I want the config_a 
configuration of dependency_a?


Re: Working on a library: request for code review

2014-06-11 Thread cal via Digitalmars-d-learn

On Wednesday, 11 June 2014 at 18:29:27 UTC, Mike wrote:

Hello.
Here's the link to the repo: http://bit.ly/1mIuGhv


Hi, sorry didn't read through your code yet, but while ago I 
wrote some encoders/decoders for jpeg and png 
(https://github.com/callumenator/imaged, haven't compiled it in a 
while). Might it be worth stitching things together into a proper 
image processing package?


Cheers,
cal


Arrays as template parameters

2014-06-04 Thread cal via Digitalmars-d-learn
I have the following code (on dpaste, 
http://dpaste.dzfl.pl/636c04430a33):


enum : uint { a, b, c }
enum list = [a, b];

void foo(T...)()
{
  pragma(msg, T[0].length); // fine
  pragma(msg, T[0][0]); // fine
  pragma(msg, T[0][1]); // fine

  foreach(i; Iota!(0,T[0].length)) // fine
pragma(msg, T[0][i]);

  //foreach(c; T[0]) // not fine
  //pragma(msg, c);
}

template Iota(size_t i, size_t n)
{
  import std.typetuple : TypeTuple;
  static if (n == 0) alias TypeTuple!() Iota;
else alias TypeTuple!(i, Iota!(i + 1, n - 1)) Iota;
}

void main()
{
  foo!list;
}

Just trying to pass a statically known array as a template 
parameter. The foreach marked 'not fine' doesn't work, saying c 
cannot be read at compile time, despite the length and all values 
being known at compile time. The foreach above it uses a template 
to generate a static tuple of indices, which are used to index 
into the array, which works but seems unnecessary.


Is there a better way to do this?


alias declaration spec

2014-02-25 Thread cal
Grammar spec (http://dlang.org/grammar.html#AliasDeclaration) 
allows:


AliasDeclaration:
alias BasicType Declarator

DMD allows:

alias ref int MyRefInt;

Is the ref storage class allowed by the current grammar spec?


Re: alias declaration spec

2014-02-25 Thread cal
On Tuesday, 25 February 2014 at 23:09:43 UTC, Jonathan M Davis 
wrote:

On Tuesday, February 25, 2014 22:32:44 cal wrote:

Grammar spec (http://dlang.org/grammar.html#AliasDeclaration)
allows:

AliasDeclaration:
 alias BasicType Declarator

DMD allows:

alias ref int MyRefInt;

Is the ref storage class allowed by the current grammar spec?


No. ref is not part of the BasicType grammar rule. ref is only 
legal on
function parameters, return types, and the variable in a 
foreach loop and is

not part of the type.

- Jonathan M Davis


Thanks, I'll file this a grammar bug.


Re: Dynamic library loading gives error about importing a module

2014-02-19 Thread cal
On Wednesday, 19 February 2014 at 09:45:41 UTC, Tolga Cakiroglu 
wrote:
I have written a programme and a library under Linux. When 
programme is run, it tries to load the library. Both the 
programme code and the library imports a module as 
apps.common.lib.config. Now, when I run the programme, 
following error is seen:


Fatal Error while loading 'dll/lib.so':
	The module 'apps.common.lib.config' is already defined in 
'./bin/app'.

make: *** [debug] Error 139


Why am I not allowed to import same module in to different code 
files? Shouldn't they be separate?


Could be this?
https://d.puremagic.com/issues/show_bug.cgi?id=11543
Workaround - compile with -release


Re: std.json tree navigation help

2014-01-27 Thread cal

On Monday, 27 January 2014 at 06:51:57 UTC, dennis wrote:
I am having trouble understanding how to navigate the tree 
returned by std.json.  I am new to D programming, I have tried 
reading the std.json source code but I am still stumped.


I usually end up doing something like this when dealing with 
std.json:


http://dpaste.dzfl.pl/bcb14d6a;


Re: Runtime.unloadLibrary does not return

2014-01-03 Thread cal

On Friday, 3 January 2014 at 19:37:04 UTC, Colden Cullen wrote:
I'm using 2.064.2, and I'm having a very similar issue. For me, 
the program doesn't crash until after my main has finished 
executing. Does anyone have any idea what might be going on?


For me the problem was related to this:
https://d.puremagic.com/issues/show_bug.cgi?id=1550

using the workaround in there, loading and unloading DLL's on 
windows works OK for me now.




Re: Struct with opDispatch doesn't dispatch. Is this a bug?

2013-07-04 Thread cal

On Friday, 5 July 2013 at 03:12:44 UTC, Meta wrote:

I wasn't 100% sure the following is a bug, so I figured I'd ask.

struct Fail
{
void opDispatch(string s)()
{
static assert(false, Tried to call a method on Fail);
}
}

void main()
{
auto fail = Fail();
fail.s(); //Error: no property 's' for type 'Fail'
}


Are you asking why the compiler doesn't halt at the static assert 
(and instead gives a 'no property' error)? (If you just want the 
code to compile and trigger a runtime assert due to the method 
call, remove the static from the assert line, and the dispatch 
will occur.)


Re: opDispatch and UFCS

2013-07-02 Thread cal

On Tuesday, 2 July 2013 at 11:04:20 UTC, Artur Skawina wrote:

To avoid this kind of issues:

   struct S {
   template opDispatch(string s) if (s.startsWith(foo)) {
   void opDispatch(T...)(T t) {
   writeln(s);
   }
   }
   }


That's a handy workaround, thank you.


Re: Stop to! rounding?

2013-07-02 Thread cal

On Wednesday, 3 July 2013 at 04:32:15 UTC, Jonathan M Davis wrote:

On Wednesday, July 03, 2013 06:23:12 Josh wrote:

writeln(to!double(151.42499));//prints 151.425

Is there any way to stop this rounding?


No. double can't hold the value 151.42499. There are _tons_ of 
values that it
can't hold exactly. The same goes for float and real. Floating 
point values are

rounded all the time. Note that

double d = 151.42499;
writeln(d);

prints exactly the same thing as your example.

- Jonathan M Davis



void main()
{
   double d = 151.42499;
   assert(d == 151.42499);
}

The rounding occurs in writeln surely.


Re: Stop to! rounding?

2013-07-02 Thread cal

On Wednesday, 3 July 2013 at 05:10:03 UTC, Jonathan M Davis wrote:

On Wednesday, July 03, 2013 07:04:47 cal wrote:
On Wednesday, 3 July 2013 at 04:32:15 UTC, Jonathan M Davis 
wrote:

 On Wednesday, July 03, 2013 06:23:12 Josh wrote:
 writeln(to!double(151.42499));//prints 151.425
 
 Is there any way to stop this rounding?
 
 No. double can't hold the value 151.42499. There are _tons_ 
 of

 values that it
 can't hold exactly. The same goes for float and real. 
 Floating

 point values are
 rounded all the time. Note that
 
 double d = 151.42499;

 writeln(d);
 
 prints exactly the same thing as your example.
 
 - Jonathan M Davis


void main()
{
double d = 151.42499;
assert(d == 151.42499);
}

The rounding occurs in writeln surely.


That's true because _both_ of the floating point values there 
get rounded to
151.425, and 151.425 is equal to 151.425. writeln is not doing 
anything wrong.

I highly suggest that you read this:

http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

- Jonathan M Davis


import std.stdio;
void main()
{
double d = 151.42499;
writefln(%.10f, d);
}


opDispatch and UFCS

2013-07-01 Thread cal

import std.conv, std.stdio, std.algorithm;

struct S {
void opDispatch(string s, T...)(T t) if (s.startsWith(foo)) 
{

writeln(s);
}
}

void main() {
S s;
s.foo();
auto p = s.to!string(); // Error: s.opDispatch!(to) isn't a 
template

}

Should the constraint on opDispatch allow the UFCS to call on S?


Re: typeof map

2013-06-25 Thread cal

On Tuesday, 25 June 2013 at 06:58:33 UTC, monarch_dodra wrote:

On Tuesday, 25 June 2013 at 04:26:00 UTC, Timothee Cour wrote:

I think it's because each lambda litteral is treated unique.
can dmd be changed to recognize identical lambda litterals as 
identical? Is

there any particular issue making that difficult?
it already recognizes identical string literals as identical


I could be wrong, but the difference might be that it *can* 
recognize string literals as idential, but it doesn't actually 
guarantee it as spec. This is not an issue for strings, but...


I also thought it was to do with identical lambda literals being 
unique, and that the code should have compiled, but I've changed 
my mind after seeing your argument.





Re: Overload of ! operator

2013-06-25 Thread cal

On Wednesday, 26 June 2013 at 02:50:51 UTC, Eric wrote:


Is there a way to overload the ! operator?  I can't seem to get
it to work with the standard unaryOp method.  I need this 
because

I am making a wrapper for a C++ API that has ! overloaded.

-Eric


According to http://dlang.org/operatoroverloading.html#Cast, the 
following are rewritten:


if (e) = if (e.opCast!(bool))
if (!e) = if (!e.opCast!(bool))

So perhaps you need to override opCast!(bool).


Re: Overload of ! operator

2013-06-25 Thread cal
On Wednesday, 26 June 2013 at 04:06:05 UTC, Jonathan M Davis 
wrote:
Yeah, that should work for the conditions in if, while, and for 
loops but
won't work for anything else (_maybe_ ternary operators, but 
I'm not sure).
So, if you need to be able to do !obj in the general case, 
that's not going to

work

...

import std.stdio;

struct S {
  int x;
  bool opCast(T)() if (is(T == bool)) {
return x == 0;
  }
}

void main() {   
  auto s = S(1);
  auto b = !s;
  writeln(b);   // true
}

Is this not supposed to work?


Re: Overload of ! operator

2013-06-25 Thread cal
On Wednesday, 26 June 2013 at 05:08:07 UTC, Jonathan M Davis 
wrote:

On Wednesday, June 26, 2013 06:59:14 cal wrote:

On Wednesday, 26 June 2013 at 04:06:05 UTC, Jonathan M Davis

wrote:
 Yeah, that should work for the conditions in if, while, and 
 for

 loops but
 won't work for anything else (_maybe_ ternary operators, but
 I'm not sure).
 So, if you need to be able to do !obj in the general case,
 that's not going to
 work

...

import std.stdio;

struct S {
   int x;
   bool opCast(T)() if (is(T == bool)) {
 return x == 0;
   }
}

void main() {
   auto s = S(1);
   auto b = !s;
   writeln(b);  // true
}

Is this not supposed to work?


No, it's not. That would require an implicit cast (which 
requires using alias
this). opCast gives you an explicit cast only. Where that 
becomes confusing is
the fact that the compiler inserts explicitly casts to bool in 
conditions for

if statements, loops, and the ternary operator. e.g.

if(foo) {...}

becomes

if(cast(bool)foo) {...}

So, if you've overloaded opCast to bool, then it'll get used in 
the conditions
for if statements, loops, and the ternary operator. But no 
explicit cast is
added just for putting ! in front of a variable. It works with 
something like


if(!foo) {...}

simply because that becomes

if(!cast(bool)foo) {...}

But nothing special is done for !, and !a will not call opCast.

- Jonathan M Davis


But that code I posted does work, and gives the output shown. Am 
I misunderstanding?


Re: indexing a tuple containing a struct strange result

2013-06-24 Thread cal

On Monday, 24 June 2013 at 05:31:29 UTC, Ali Çehreli wrote:

On 06/23/2013 10:07 PM, Ali Çehreli wrote:

 I think it is a compiler bug.

Make that a Phobos bug. :)

The following is a reduced program that exhibits the problem. 
The presence or absence of the unused member function makes a 
difference:


import std.typecons;

struct S
{
int x;

// Bizarre: Comment-out this function to pass the assert in 
main.

Tuple!(S) unused()
{
return tuple(S(7));
}
}

void main()
{
auto s = S(8);

assert(tuple(s).expand[0] == S(8));
}

Ali


Actually I hadn't tried with free functions, but this test 
captures my problem. I'll file it now. Thanks!


typeof map

2013-06-24 Thread cal

Is it by design that the code below does not compile?

import std.algorithm, std.range;

void main() {
   typeof(iota(10).map!(a=a)) x = iota(10).map!(a=a);   
}

Error message (DMD git-latest on DPaste):
Error: constructor f755.main.MapResult!(__lambda2, 
Result).MapResult.this (Result input) is not callable using 
argument types (MapResult!(__lambda4, Result))
Error: cannot implicitly convert expression (map(iota(10))) of 
type MapResult!(__lambda4, Result) to Result


indexing a tuple containing a struct strange result

2013-06-23 Thread cal

What is going on here?

import std.stdio, std.typecons;

struct S
{
int x;
Tuple!(S) foo() { return tuple(this); }
}

void main()
{
S s;
s.x = 8;
writeln((s.foo())); //output: Tuple!(S)(S(8))
writeln((s.foo())[0]);  //output: S(0)
}


Only partial type info for templated classes

2013-04-07 Thread cal


class C(T){}
class CC(T){}

struct S(T){}
struct SS(T){}

void main()
{
   import std.stdio;
   writeln(typeid(S!(SS!int)).name); // S!(SS!(int)).S
   writeln(typeid(C!(CC!int)).name); // C!(CC).C
}

Is there a way to get the full type info in the name for a 
templated class (i.e. like the struct)?


map with void fun

2013-04-06 Thread cal
Should the code below print anything (it currently doesn't)? I'm 
not sure I understand map:


import std.stdio, std.algorithm;

void main() {
int[] a = [1,2,3,4,5];
auto r = a.map!( i = writeln(i) );
while(!r.empty) r.popFront();
}


Re: map with void fun

2013-04-06 Thread cal

On Saturday, 6 April 2013 at 21:40:37 UTC, bearophile wrote:

First, to see the side effects you have also to call front:


Ah thank you, I did not realize a call to front was required.

But this is wrong still. map() is a higher order function, it's 
meant to take a function and an iterable and produce a new lazy 
iterable that contains the ordered results of applying the 
given function on each item. writeln() returns nothing (void, 
it's a type with just one value, void itself).


Yes, I understand, the example was just a reduced bit of code.

Thanks again


detect anonymous union at compile time

2013-03-28 Thread cal

Given:

struct S {
  union {
int i;
float f;
  }
}

is there any way to detect the fact that fields i and f will have 
the same offset from S? (Creating an instance of S and getting 
the relative addresses only works if the union is public).


Re: detect anonymous union at compile time

2013-03-28 Thread cal

On Thursday, 28 March 2013 at 20:18:45 UTC, Andrej Mitrovic wrote:

.offsetof will also require access rights to the fields.


Yeh this is the problem. I can map data layout of complex 
aggregates, even if the members are private, but unions mess that 
up. Restricting to public fields is an option, but i'd like to be 
able to get it all.


Re: detect anonymous union at compile time

2013-03-28 Thread cal

On Thursday, 28 March 2013 at 20:18:45 UTC, Andrej Mitrovic wrote:

On Thursday, 28 March 2013 at 20:02:18 UTC, cal wrote:
.offsetof will also require access rights to the fields.


Just realized that format.d is able to figure it out, since it 
prints #{overlap...} for unions. I can use that code, which works 
regardless of protection. Thanks




Re: enum type changes according to context ?

2013-03-28 Thread cal

On Thursday, 28 March 2013 at 23:02:31 UTC, Timothee Cour wrote:

In code below, does transTable have a well defined type?
it seems to change from line 9 (string[char])
to line 10 (string[dchar])...


My guess:
The enum version is like saying this:

auto s = translate([, ['[' : `\[`]);

here the literal gets implicitly converted to string[dchar]. The 
auto version is inferred as string[char], so compilation fails.


Re: isExpression with bool template parameter

2013-03-26 Thread cal

On Tuesday, 26 March 2013 at 05:28:22 UTC, Ali Çehreli wrote:
I am not sure that I understand but usually the test is done in 
a context like foo() below:


struct S(A, bool B) {}

void foo(T)()
{
static assert(is(T == S!(U, false), U));
}

void main()
{
foo!(S!(int, false))();
}

Ali


Maybe I gave a bad example, I guess I wonder why line A passes 
but line B fails:


struct S(A, bool B) {}

static assert(is(S!(int, false) _ == S!(U, false), U)); // line 
A, pass
static assert(is(S!(int, false) _ == S!(U, V), U, V));  // line 
B, fail


void main(){}

I.e., why I can't match on some generic second parameter - what 
if the second parameter was an int:


struct S(A, int B) {}
static assert(is(S!(int, 5627) _ == S!(U, ??), U, ??));

how to match that in the isExpression?

cheers,
cal



Re: isExpression with bool template parameter

2013-03-26 Thread cal

On Tuesday, 26 March 2013 at 06:03:55 UTC, cal wrote:
I.e., why I can't match on some generic second parameter - what 
if the second parameter was an int:


struct S(A, int B) {}
static assert(is(S!(int, 5627) _ == S!(U, ??), U, ??));

how to match that in the isExpression?

cheers,
cal


However this does work (and solves my problem):

struct S(A, int B){}

static if (is(S!(int, 5) _  : S!(U), U...))  // line B, fail
   pragma(msg, U.stringof); // tuple(int, 5);

But it seems like is(S!(int, 5) _  : S!(U, V), U, V) should work 
to me.




Re: isExpression with bool template parameter

2013-03-26 Thread cal

On Tuesday, 26 March 2013 at 06:15:54 UTC, cal wrote:

static if (is(S!(int, 5) _  : S!(U), U...))  // line B, fail
   pragma(msg, U.stringof); // tuple(int, 5);


oops the '// line B, fail' should not be there


Re: isExpression with bool template parameter

2013-03-26 Thread cal

On Tuesday, 26 March 2013 at 13:45:52 UTC, Ali Çehreli wrote:
There are three kinds of template parameters: type, value, and 
alias.


That syntax does not work because you are trying to match 5 to 
V, where 5 is a value and V is a type.


Ali


Thanks Ali,

I guess the tuple version is fine, it is just surprising that 
only one of the three parameter types can be directly matched. It 
is also surprising that this example from the docs works:


alias Tuple!(int, string) Tup;
static if (is(Tup : TX!TL, alias TX, TL...))

(matching an alias) but the alias can't be directly matched when 
it appears as a parameter of the type.


Re: Named Tuple Names

2013-03-26 Thread cal
On Tuesday, 26 March 2013 at 16:31:51 UTC, Jonathan Crapuchettes 
wrote:
but I wish there was a cleaner way to do it. If the FieldSpec 
template
was moved into the public section, it would allow for the name 
member to

be accessed.



Not sure this qualifies as clean, but it's an option:

import std.typecons, std.stdio, std.traits, std.conv;

string[] tupleNames(T)()
{
string[] names;
uint count = 0;
bool matchNext = false;
foreach(m; __traits(allMembers,T))
{
if (matchNext)
{
names ~= m;
matchNext = false;
count ++;
}

if (m == _ ~ count.to!string)
matchNext = true;
}
return names;

}

pragma(msg, tupleNames!(Tuple!(int,a,float,b,string,c)));

void main(){ }


Re: how to demangle a string ending __ModuleInfoZ ?

2013-03-22 Thread cal

On Friday, 22 March 2013 at 11:23:30 UTC, timotheecour wrote:

void main(){
import std.demangle;
import std.stdio;
writeln(demangle(_D5tango4text7convert6Format12__ModuleInfoZ));
//_D5tango4text7convert6Format12__ModuleInfoZ
writeln(demangle(_D5tango4text7Unicode6toFoldFAxaAaZAa));
//char[] tango.text.Unicode.toFold(const(char)[], char[])
}


Last time I tried to use demangle it didn't work on types, only 
functions. Your first symbol is a type, so looks like the same 
problem.


Re: getChar() vs. getChar!true()

2013-03-20 Thread cal
On Wednesday, 20 March 2013 at 20:11:47 UTC, Peter Sommerfeld 
wrote:

In std.json is a function getchar() with this signature:

dchar getChar(bool SkipWhitespace = false);


It looks like the signature (line 115) is:
dchar getChar(bool SkipWhitespace = false)()

Note the extra set of parens at the end, making the bool a 
template parameter.


Re: initializing const(Date)

2013-03-19 Thread cal

On Tuesday, 19 March 2013 at 16:35:22 UTC, Dan wrote:

This used to work but now in 2.062 it causes ctfe error.
Any suggested workaround?


This seems to work:

Date defDate() pure { return Date(1929, 10, 29); }
const(Date) DefaultDate = defDate();

Assuming you wanted to avoid a initializing inside a static 
this().


Re: initializing const(Date)

2013-03-19 Thread cal

On Tuesday, 19 March 2013 at 17:04:01 UTC, cal wrote:

On Tuesday, 19 March 2013 at 16:35:22 UTC, Dan wrote:

This used to work but now in 2.062 it causes ctfe error.
Any suggested workaround?


This seems to work:


Or:
const(Date) DefaultDate = { return Date(1929,10,10); }();
although this is getting cryptic.


Re: Variant confusion

2013-03-11 Thread cal

On Monday, 11 March 2013 at 15:25:55 UTC, Peter Sommerfeld wrote:
Seems I have to dig into the implementation for a workaround  
or use

my own union to integrate the types.

Thanks, Peter


To get the held type of a Variant, use .type():

if(value.type() == typeid(Map))
   writeln(value == map);
else if(value.type() == typeid(Value))
   writeln(value == Value); // Is still Value!

prints map.




traits allMembers and imported modules

2013-03-11 Thread cal


DMD 2.062:

//-- module other.d, same dir as main --
module other;
int j;
//--

//-- module dir/other.d, subdir of main --
module dir.other;
int j;
//--


//-- module main.d --
module main;

import other;
pragma(msg, [__traits(allMembers, (other))]);

import dir.other;
pragma(msg, [__traits(allMembers, dir.other)]);

void main(){}
//--

When the module name I use inside __traits is in the same dir as 
the main module, I need the extra parenthesis to satisfy the 
compiler. Is this a bug, or unavoidable?


Re: traits allMembers and imported modules

2013-03-11 Thread cal

On Monday, 11 March 2013 at 23:10:58 UTC, Andrej Mitrovic wrote:

On 3/11/13, cal callumena...@gmail.com wrote:
When the module name I use inside __traits is in the same dir 
as

the main module, I need the extra parenthesis to satisfy the
compiler. Is this a bug, or unavoidable?


I can't reproduce this. How are you compiling the modules?


Both rdmd and separate compilation give the error:
Import other has no members.

if i remove the parenthesis around 'other'.


Re: traits allMembers and imported modules

2013-03-11 Thread cal

On Monday, 11 March 2013 at 23:19:18 UTC, cal wrote:

On Monday, 11 March 2013 at 23:10:58 UTC, Andrej Mitrovic wrote:

On 3/11/13, cal callumena...@gmail.com wrote:
When the module name I use inside __traits is in the same dir 
as

the main module, I need the extra parenthesis to satisfy the
compiler. Is this a bug, or unavoidable?


I can't reproduce this. How are you compiling the modules?


Both rdmd and separate compilation give the error:
Import other has no members.

if i remove the parenthesis around 'other'.


Actually it prints out:
[false]
[object, j]
first, and then fails with the above error message.


Re: traits allMembers and imported modules

2013-03-11 Thread cal

On Monday, 11 March 2013 at 23:22:42 UTC, cal wrote:

On Monday, 11 March 2013 at 23:19:18 UTC, cal wrote:

On Monday, 11 March 2013 at 23:10:58 UTC, Andrej Mitrovic


I can't reproduce this. How are you compiling the modules?


Specifically:

dmd main.d other.d dir/other.d

produces:
Error: import other has no members
[false]
[object, j]


Re: traits allMembers and imported modules

2013-03-11 Thread cal

On Monday, 11 March 2013 at 23:38:20 UTC, Andrej Mitrovic wrote:

On 3/12/13, cal callumena...@gmail.com wrote:

if i remove the parenthesis around 'other'.


Ah yes, I can recreate it now. Can you file this as a bug?


Sure thanks for checking it


Re: typeof([2,2]) !=? int[2]

2013-03-08 Thread cal

On Friday, 8 March 2013 at 23:03:47 UTC, Zhenya wrote:

Your constraint could be:

if(is(typeof(size) _ == int[])  size.length  0)

Also it looks like you are passing 1 too many template args?

static if(n  1)
  NDimensionalArray!(T,n - 1,size[1..$]) m_array[size[0]];
 ^^


Re: typeof([2,2]) !=? int[2]

2013-03-08 Thread cal

On Friday, 8 March 2013 at 23:15:30 UTC, Zhenya wrote:
Yes,it's a typo.But it seems to be ugly pass dynamically 
allocated array through
a template parameter,because it's size should be compile-time 
constant.


Its size is a compile-time constant because it is an array 
literal. The size is known inside the constraint.




Re: __traits(compiles) + mixin

2013-03-05 Thread cal

On Tuesday, 5 March 2013 at 08:04:12 UTC, Andrej Mitrovic wrote:
You can't test declarations inside of __traits(compiles), only 
expressions. It's in the docs: 
http://dlang.org/traits.html#compiles


So why does this work:

import std.conv;

void main()
{
enum s = `1`.to!int;;
enum c = __traits(compiles, mixin({auto x = ~s~;})); // 
true

}


Re: __traits(compiles) + mixin

2013-03-05 Thread cal

On Tuesday, 5 March 2013 at 08:14:58 UTC, simendsjo wrote:

Hmm.. And this also works:
enum c = __traits(compiles, mixin({auto a = new 1;}));

Something to do with CTFE combined with mixins?


But it gets this right, in that c is false. I had thought that by 
wrapping the declaration in braces, making it a function, that 
got around the 'no declarations' limitation.




Re: __traits(compiles) + mixin

2013-03-05 Thread cal

On Tuesday, 5 March 2013 at 12:58:57 UTC, Timon Gehr wrote:
Compiles as expected with DMD 2.060. It is probably a 
regression.


Ah you're right, also with 2.061. I'll file.


__traits(compiles) + mixin

2013-03-04 Thread cal

I'm confused about this:

import std.conv;

void main()
{
enum s = `1`.to!int;;
enum c = __traits(compiles, mixin({auto a = new ~s~;})); 
// line 1
mixin(auto a = ~s~;);
// line 2

}

This does not compile, giving errors about instantiating 
std.conv.to!(int).to!(string). If I switch the order of lines 1 
and 2 it compiles. Is this a bug or something I don't understand 
about __traits(compiles)?


Re: std.signal woes :/

2013-02-24 Thread cal

On Sunday, 24 February 2013 at 17:30:14 UTC, Damian wrote:
That solution is ok for 1 argument but for many arguments it 
wont suffice.


This is issue 5028.


What is the problem with many arguments? I'm probably 
misunderstanding, but e.g. this works:


struct MySignal(T...)
{
mixin Signal!T _signal;
alias _signal this;
}

class A
{
MySignal!(float, int[]) sigA;
}

class B : A
{
MySignal!(int, string, char) sigB;
}

void main()
{
auto a = new A;
auto b = new B;
a.sigA.emit(1.4, [1,2,3]);
b.sigA.emit(1, [4,5,6]);
b.sigB.emit(1, hello, 'x');
}


Re: collectException range violation

2013-02-20 Thread cal
On Wednesday, 20 February 2013 at 07:54:19 UTC, monarch_dodra 
wrote:
Note that an Error is not an Exception, and an Exception is not 
an Error. Both, however, are Throwable's. If you want to catch 
an *anything*, then catch a Throwable.


As already mentioned though, catching an Error is not something 
you usually do, as their existence implies an already 
catastrophic state. At best, they can be used to 
semi-gracefully die.


Yeah I am trying to catch a range violations thrown inside D 
Dlls, which if not trapped somehow manually, crash very 
ungracefully :).


Make struct transparent to std.algorithm.sort

2013-02-19 Thread cal

Is there a way to make this sort of thing work?

import std.algorithm;

struct S
{
int[] arr;
alias arr this;
}

void main()
{
auto s = S([1,2,3]);
sort(s);  // error: template std.algorithm.sort does not 
match any function

  // template declaration. Candidates are...
}


collectException range violation

2013-02-19 Thread cal

Is this example from the docs still meant to work?

int[] a = new int[3];
int b;
assert(collectException(a[4], b));


Re: collectException range violation

2013-02-19 Thread cal

On Wednesday, 20 February 2013 at 01:19:54 UTC, Ali Çehreli wrote:
The example is wrong. a[4] throws an Error (not Exception) but 
collectException catches Exception by default.


Additionally, the example is doing something that is 
recommended against: Catching Error or a descendent of it.


Still, it can be told to catch by Error:

assert(collectException!Error(a[4], b));

Ali


Ah right I didn't realize it could be made to collect an Error. 
Thanks!




Mixin template function

2013-02-13 Thread cal

Should the following work?

import std.traits;

mixin template Foo()
{
void foo(T)(T t) if (isSomeString!T) {}
}

class A
{
void foo()(int i){}
mixin Foo;
}

void main()
{
auto a = new A;
a.foo(hello);
}

Error: template hello.A.foo does not match any function template 
declaration. Candidates are:

hello.A.foo()(int i)

If i give the mixin an identifier (mixin Foo _foo) and call it 
like a._foo.foo(hello) then it works. I thought it should work 
without that though.


Re: Mixin template function

2013-02-13 Thread cal

And a related question:

class A
{
void foo(int i){}
void foo(Tuple!(int) i){}
}

class B: A
{
override void foo(int i){}
}


int main()
{

auto b = new B;
b.foo(tuple(5));
}

This fails to compile. Why can't B use A's tuple overload of 
foo()? If I do this:


class B: A
{
override void foo(int i){}
void foo(Tuple!(int) i){} // no override keyword is deprecated
}

The compiler warns about not using the override keyword, so it 
must be seeing the function?


Re: Delegate type inferred as pure

2013-01-28 Thread cal

On Monday, 28 January 2013 at 10:44:22 UTC, qznc wrote:

On Monday, 28 January 2013 at 03:16:24 UTC, cal wrote:

Is the 'typeof((int a){return z;})' getting it wrong here?


Do you really need the type? You could just use auto.

auto dg = (int a) {return z;};


Yeah this is reduced from something I'd like to use typeof for, 
usually auto would be fine like you say.


Delegate type inferred as pure

2013-01-27 Thread cal

This fails:

void main() {
int z;
typeof((int a){return z;}) dg;
dg = (int a) {return z;};
}

Error: cannot implicitly convert expression (__lambda2) of type 
int delegate(int a) nothrow @safe to int delegate(int a) pure 
nothrow @safe


But I can't make the delegate pure:
dg = (int a) pure {return z;};
because it references z.

Is the 'typeof((int a){return z;})' getting it wrong here?


Re: Win32 api with 2.061

2013-01-23 Thread cal
On Wednesday, 23 January 2013 at 02:40:55 UTC, Andrej Mitrovic 
wrote:

Try making these changes:
https://github.com/AndrejMitrovic/WindowsAPI/commit/6d8ef98508063c5a4741c72eda68aa485d3b25fa

WindowsAPI should really be moved to Github..


Thanks this fixed another error i was getting, compiler is happy 
again. A github WinApi would be great, I use it a lot.


Re: Atomic updates

2013-01-22 Thread cal

On Tuesday, 22 January 2013 at 08:12:03 UTC, qznc wrote:

On Tuesday, 22 January 2013 at 00:10:22 UTC, bearophile wrote:
I suggest to put your code on Rosettacode now, and then we'll 
do the changes there... As you see in other answers, both me 
and monarch_dodra have other ideas for improvements.


Ok, posted it.

http://rosettacode.org/wiki/Atomic_updates#D

I incorporated some of your and monarch_dodra's suggestions.


Just curious: in the transfer function, why do you lock/unlock 
the lower bucket number first? Why does the order matter?


Re: Atomic updates

2013-01-22 Thread cal

On Tuesday, 22 January 2013 at 09:47:25 UTC, monarch_dodra wrote:

Avoids deadlock.

imagine 2 threads:
a: from 2 to 5.
b: from 5 to 2.

If both threads acquire their first lock, then you have a dead 
lock, and your program is basically dead.


By always locking low first, you avoid the deadlock in a rather 
simple but elegant way.


Ah neat. And what about the case from = to? Why doesn' that 
deadlock in this code? (Concurrency is rather new to me)


Re: Address of return value.

2012-12-11 Thread cal

On Tuesday, 11 December 2012 at 15:38:38 UTC, monarch_dodra wrote:
On Tuesday, 11 December 2012 at 14:57:27 UTC, monarch_dodra 
wrote:

:/


I got it to work with a cast, which removes the ambiguity:

auto p = cast(int)s.front;

But it feels hackish. Any other way?


auto p = (s.front());

Not sure if this is intended though, maybe some property 
weirdness?


Windgb debug a dll

2012-11-26 Thread cal

Trying to debug a D dll, using Windgb.

The dll is built using:
dmd -c -g filename.d
dmd -g filename.obj filename.def

with a def file*. I can load the dll from a D program manually, 
and call functions within it. But I now need to debug some of 
those functions, by stepping into them from the main program.


So: can I do this with Windbg, and step through the source as 
though the dll were an exe? And if so, what info do I need to 
give windbg to let it do that? Are there things I need to add to 
the .def file, or linker switches?


The .def file contains:
LIBRARY mydll
DESCRIPTION 'mydll'
EXETYPE  NT
CODE PRELOAD DISCARDABLE
DATA PRELOAD MULTIPLE

Thanks!




Pointer to string allows assigning int[]?

2012-11-12 Thread cal

Is the following a bug?

import std.c.string, core.memory;

void* makeNew(T)()
{
T t = T.init;
void* ptr = GC.malloc(T.sizeof);
memcpy(ptr, t, T.sizeof);
return ptr;
}

void main()
{
alias string T;
T* iptr = cast(T*)makeNew!(T);
(*iptr) = [1,2,3]; // this is allowed
}


Re: Pointer to string allows assigning int[]?

2012-11-12 Thread cal

On Monday, 12 November 2012 at 21:08:43 UTC, simendsjo wrote:

It's not a bug.

string is an alias for immutable(char)[].
ubyte can be implicitly converted to char.
All your numbers are less than 256, so dmd is able to convert 
them to char.

If you try this, it fails.
string s = [256]; // 256 is  char.max


Ah right of course, thank you.


no size for type nothrow extern (Windows) int()

2012-11-10 Thread cal
I want to call Windows api function VirtualAlloc. I include 
std.c.windows.windows but get the following error from dmd 2.061 
(and 2.060):


Error: no size for type nothrow extern (Windows) int()

What does this message mean? If I provide my own prototype of the 
function, same error.





Re: no size for type nothrow extern (Windows) int()

2012-11-10 Thread cal
On Sunday, 11 November 2012 at 02:55:09 UTC, Alex Rønne Petersen 
wrote:
Can you give a self-contained repro that illustrates the 
problem?


Also, please use core.sys.windows.windows instead. The std.c.* 
package is going to be deprecated soon-ish.


import core.sys.windows.windows;

void main()
{
  FARPROC addr1, addr2;
  auto ptr = VirtualAlloc(null, addr2-addr1, 0x1000, 0x40);
}

I just discovered while reducing it what the error message means: 
FARPROC is not void* like I thought, but (int function()), so it 
can't be used like I tried to do above. The compiler message was 
a little cryptic, but obvious in hindsight. Thanks!


Re: no size for type nothrow extern (Windows) int()

2012-11-10 Thread cal
On Sunday, 11 November 2012 at 02:55:09 UTC, Alex Rønne Petersen 
wrote:
Can you give a self-contained repro that illustrates the 
problem?


Also, please use core.sys.windows.windows instead. The std.c.* 
package is going to be deprecated soon-ish.


import core.sys.windows.windows;

void main()
{
  FARPROC addr1, addr2;
  auto ptr = VirtualAlloc(null, addr2-addr1, 0x1000, 0x40);
}

I just discovered while reducing it what the error message means: 
FARPROC is not void* like I thought, but (int function()), so it 
can't be used like I tried to do above. The compiler message was 
a little cryptic, but obvious in hindsight. Thanks!


Re: removing element from DList

2012-11-05 Thread cal

On Monday, 5 November 2012 at 16:41:16 UTC, Jack Applegame wrote:

How to get range for single just inserted element?

DList!int list;
...
list.insertBack(5);
auto r = ??? // get range for single last element
...
list.insertBack(something);
...
list.remove(r);


http://forum.dlang.org/thread/cfkllwgfushidyuwz...@forum.dlang.org


Runtime.unloadLibrary does not return

2012-11-03 Thread cal
Following the D win32 dll example (http://dlang.org/dll.html), I 
created a d dll with a simple exported function, which i then 
dynamically load and call (just like the example). This works 
fine, however Runtime.unloadLibrary does not return. I do however 
get the DLL_PROCESS_DETACH message, so it gets at least that 
far.


In fact, if I have code after the Runtime.unloadLibrary call, the 
program crashes (without code following the call, it just hangs).


Has anyone else seen this problem? I get this with both dmd 2.060 
and 2.061.





Reading results from dmd -profile

2012-10-28 Thread cal
I am trying to read the text file (trace.log) created by running 
the dmd profiler on some code, so that I can use demangle to make 
the output a bit more readable. I can read it in as a char[], but 
the whenever I try any string ops I get an exception because 
there are invalid UTF-8 sequences in the text.


So two questions: why does the output contain invalid UTF-8 
sequences, and what would be a good way to handle the invalid 
sequences, since I guess I need them for proper demangling?


Cheers


Re: Proxy addition

2012-10-26 Thread cal

On Friday, 26 October 2012 at 15:14:56 UTC, Dan wrote:
Still trying to understand this. I found that if I change the 
following in Proxy it this example (r1 + r2) works fine. Plus 
the unit tests that are there still work. But, honestly I don't 
understand why...yet.


Thanks,
Dan

- From typecons.Proxy -
auto ref opBinary (string op, this X, B)(auto ref B b) 
{ return mixin(a ~op~ b); }

- To -
auto ref opBinary (string op, this X, B)(auto ref B b) 
if(!is(X == B)) { return mixin(a ~op~ b); }

-


From http://dlang.org/operatoroverloading.html, it is an error 
for both overloads of opBinary (opBinary and opBinaryRight) to 
match. Since the signatures for the two overloads in std.typecons 
are identical, this looks like a bug to me.


Your modified version works (far as I can see) because it 
excludes one of the overloads from being matched, allowing the 
other to be used (opBinaryRight).


Re: Slices and array appending

2012-10-22 Thread cal
On Monday, 22 October 2012 at 04:59:41 UTC, Jonathan M Davis 
wrote:
Blocks of memory are allocated and freed as a whole. When an 
array is forced
to be reallocated, then a new block of memory is allocated for 
it, and any
existing slices continue to refer to the original block of 
memory. The
original block will not be freed until there are no more slices 
which refer to
it. You really should read this article if you want to know how 
arrays work in

D:

http://dlang.org/d-array-article.html

- Jonathan M Davis


Ah thanks, I didn't realize the _entire_ original array would 
hang around. That makes my current approach really dumb. Cheers





Re: class opBinary overloading. value + null and null + value

2012-10-21 Thread cal

On Sunday, 21 October 2012 at 20:34:51 UTC, ref2401 wrote:

what should i do to make my binary operation commutative?


You can overload opBinaryRight:

MyClass opBinaryRight(string op: +)(MyClass rhs)
{
   if (rhs is null)
   {
 return null;
   }
   MyClass result = new MyClass(value + rhs.value);
   return result;
}

http://dlang.org/operatoroverloading.html


Re: class opBinary overloading. value + null and null + value

2012-10-21 Thread cal

On Sunday, 21 October 2012 at 20:54:15 UTC, ref2401 wrote:

On Sunday, 21 October 2012 at 20:42:08 UTC, cal wrote:

On Sunday, 21 October 2012 at 20:34:51 UTC, ref2401 wrote:

what should i do to make my binary operation commutative?



in the following case

auto v5 = v1 + v2;

there will be compile time error:
overloads pure @safe MyClass(MyClass rhs) and pure @safe 
MyClass(MyClass lhs) both match argument list for opBinary		


Oh right, sorry. Well if all you want to do is catch the null on 
either side of the '+', you could use this overload of 
opBinaryRight:


MyClass opBinaryRight(string op: +, T)(T rhs) if (!is(T == 
MyClass))

{   
  return null;  
}

I'm not sure if this is what you are trying to do though...


Slices and array appending

2012-10-21 Thread cal

Just want to make sure I understand this properly:

I have a large dynamic array (whose elements are immutable) which 
only ever grows. I also have a whole lot of small slices into 
this array, the slices never change, and they don't span the 
entire contents of the array (they are just pieces).


Now if I append to the large array, and the runtime needs to 
re-allocate to accommodate the change in size, none of the pieces 
of the original array which are referred to by the slices can be 
freed, right? So I end up basically with two copies of the 
original large array, however the first version will now have 
little pieces missing from it (wherever the slices don't refer).


Is that correct?


Re: std.concurrency msg passing

2012-10-18 Thread cal

On Thursday, 18 October 2012 at 06:30:08 UTC, Joshua Niehus wrote:

Is the following snippet a bug?

---
import core.thread;
import std.stdio, std.concurrency;

void foo(Tid tid) {
send(tid, true);
}

void main() {
auto fooTid = spawn(foo, thisTid);
auto receiveInt = receiveTimeout(dur!seconds(10), (int 
isInt) {

writeln(I should not be here);
});
}
// output: I should not be here
---

If not, is there some way I could achieve 
receiveOnlyTimeout!(int)(dur, fun); ?


Thanks,
Josh


I can't see the bug? The receiver accepts a bool as an int, same 
way a normal function does. The timeout is long enough that foo 
gets a chance to send.  If you want to stop the int receiver 
getting a bool, you could add another receiver with (bool) { // 
do nothing } or whatever before the (int) one, which will be a 
better match for the send.




Re: std.concurrency msg passing

2012-10-18 Thread cal

On Thursday, 18 October 2012 at 18:31:09 UTC, Sean Kelly wrote:

On Oct 17, 2012, at 11:29 PM, Joshua Niehus

void foo(Tid tid) {
   send(tid, true);
}

/* snip */
spawn() shouldn't allow you to spawn a delegate.  Last I 
checked (which was admittedly a while ago), there were some 
compiler issues around actually verifying the function 
signature sent to spawn() though.


Why is foo a delegate here?




std.range.chunks for char[]

2012-10-17 Thread cal


Is there an equivalent to std.range.chunks that will work on a 
char array? As in, it will return a range iterating over chunks 
of code points?


Assign to element of DList

2012-10-07 Thread cal

The docs for std.container suggest I should be able to do this:

import std.container;

void main()
{
  auto list = DList!int([1,2,3,4,5]);
  list.front = 3;
}

But this does not compile (not a property list.front). I can't 
figure out why this doesn't work though - the source for struct 
DList(T) contains this:


static if(isAssignable!(T,T))
{
  @property void front(T value)
  {
assert(!empty, DList.front: List is empty);
move(value, _first._payload);
  }
}

but that does not seem to be getting compiled in.



Re: Assign to element of DList

2012-10-07 Thread cal

On Sunday, 7 October 2012 at 19:42:18 UTC, Ali Çehreli wrote:
What version of Phobos are you using? The source code of Phobos 
that comes with dmd 2.060 does not have the definition that you 
have shown.


In any case, according to the docs, it is SList that allows 
setting the front element, not DList:


import std.container;

void main()
{
  auto list = SList!int([1,2,3,4,5]);
  list.front = 3;
}

Ali


Ah you're right, I was looking at my git head version, which I 
don't use when I build dmd head. So the functionality is there 
already. Thanks!





Re: Remove element from DList

2012-10-06 Thread cal

On Sunday, 7 October 2012 at 01:14:48 UTC, Jonathan M Davis wrote:
The correct way is to use find combined with take (which is 
what you're doing,
except that you're not using find). So, something like this 
should work


void main()
{
auto list = DList!int([1,2,3,4]);
list.remove(find(list[], 3).take(1));
}


However, for some reason, this is indeed not working right now. 
It's a bug.

Please report it.


SList doesn't implement remove, so perhaps DList can only 
guarantee the required complexity when given the range defined in 
DList, and for other types of ranges, it can only guarantee 
linear complexity?


Re: Remove element from DList

2012-10-06 Thread cal

On Sunday, 7 October 2012 at 02:54:44 UTC, Jonathan M Davis wrote:

On Sunday, October 07, 2012 04:14:58 cal wrote:
On Sunday, 7 October 2012 at 01:14:48 UTC, Jonathan M Davis 
wrote:

 The correct way is to use find combined with take (which is
 what you're doing,
 except that you're not using find). So, something like this
 should work
 
 void main()

 {
 
 auto list = DList!int([1,2,3,4]);

 list.remove(find(list[], 3).take(1));
 
 }
 
 
 However, for some reason, this is indeed not working right 
 now.

 It's a bug.
 Please report it.

SList doesn't implement remove, so perhaps DList can only
guarantee the required complexity when given the range defined 
in

DList, and for other types of ranges, it can only guarantee
linear complexity?


singly-linked lists and doubly-linked lists are completely 
different beasts. A
singly-linked list can't do it sanely, because it has to 
traverse the list to
find the previous node so that it adjust the links. A node in a 
doubly-linked
list has a link to the previous node in the list instead of 
just the next
node, so it doesn't have that problem. You can add and remove 
elements from
anywhere in a doubly-linked list in O(1). And if you're dealing 
with
iterators, it won't affect any iterators except if they point 
at the element
being removed (so it's a stable remove). With ranges, it would 
affect the
elements in the range, but unless you're removing an element 
which is at the
front or end of a range, it shouldn't invalidate the range at 
all. And that
can be gotten around by letting that node continue to exist and 
point to what
was the next node in the list (in which case, it would go away 
once no more

ranges referred to it - the GC makes doing that fairly easy).

So, I don't see any reason why remove wouldn't be stable or 
non-linear. It's
actually kind of hard to make it _un_stable in this case. And 
actually,
looking at the code, stableLinearRemove (and linearRemove is an 
alias for
stableLinearRemove in this case) calls remove, so overall, this 
is a bit
bizarre. Regardless, it's a bug that normal remove doesn't work 
with the

result of take.

- Jonathan M Davis


Righto, i'll put in a ticket, thanks for the help.




Re: Remove element from DList

2012-10-06 Thread cal
On Sunday, 7 October 2012 at 01:14:48 UTC, Jonathan M Davis 
wrote:
Regardless, it's a bug that normal remove doesn't work with the 
result of take.


I guess this is also true of insertAfter and co? Should they 
accept the result of take? (Currently they don't)


Variant opArithmetic

2012-09-18 Thread cal
Variant tries to mimic D's built-in rules for arithmetic 
conversions but:


import std.variant, std.stdio;
void main()
{
  auto v1 = Variant(4.5f);
  auto v2 = Variant(3.5f);
  writeln((v1+v2).type()); // double
}

The reason is Variant doesn't try to convert to float in 
opArithmetic (it's is easily fixed). But is it intentional?


Re: Variant opArithmetic

2012-09-18 Thread cal
On Tuesday, 18 September 2012 at 19:02:33 UTC, Andrei 
Alexandrescu wrote:

On 9/18/12 1:36 PM, cal wrote:
Variant tries to mimic D's built-in rules for arithmetic 
conversions but:


import std.variant, std.stdio;
void main()
{
auto v1 = Variant(4.5f);
auto v2 = Variant(3.5f);
writeln((v1+v2).type()); // double
}

The reason is Variant doesn't try to convert to float in 
opArithmetic

(it's is easily fixed). But is it intentional?


I wrote this:

writeln(typeof(4.5f + 3.5f).stringof);

To my surprise, the reported type was float, not double. Well 
that means it's a bug in Variant, could you please make a bug 
report (and hopefully a pull request fixing it)?



Thanks,

Andrei


Sure thing




Re: Error: WndProc - nothrow

2012-09-16 Thread cal

On Sunday, 16 September 2012 at 17:38:35 UTC, deed wrote:

What does the nothrow stems from? Is this something new?


Isn't the real question why the wndProc function is expected to 
be nothrow?


The change is from this commit 4 months ago: 
2886846a92c45d92308756cf4c077ae13f0f8460







Re: Error: WndProc - nothrow

2012-09-16 Thread cal

On Sunday, 16 September 2012 at 22:08:53 UTC, deed wrote:

Exactly. I couldn't remember seeing this error before.


I've only used the dsource Win32 bindings, because there is often 
stuff missing from the phobos ones:


http://www.dsource.org/projects/bindings/wiki/WindowsApi

But I don't understand the reason for the change to the phobos 
bindings. Like someone above said, the easiest solution is to 
wrap your wndProc body in a try/catch.


Using traits to detect alias declaration

2012-09-09 Thread cal
When using __traits(allMembers), I'd like to be able to detect if 
a given member is an alias (and get the member that is aliased). 
Is there a way to do this currently?


Re: Using traits to detect alias declaration

2012-09-09 Thread cal
On Monday, 10 September 2012 at 03:30:25 UTC, Jonathan M Davis 
wrote:

On Monday, September 10, 2012 05:01:05 cal wrote:
__traits(allMembers), I'd like to be able to detect if a given 
member is an alias (and get the member that is aliased). Is 
there a way to do this currently?


No. As far as the compiler is concerned, there is no difference 
between an

alias and what it's aliased from.


Played around a bit, and this _seems_ to work:

// Detect alias
foreach(member; __traits(allMembers, l.main))
{
   static if (__traits(compiles, __traits(identifier, 
mixin(member

   {
  string ident = __traits(identifier, mixin(member));
  if (ident != member)
/// Detected an alias
   }
}

But I wonder if this is reliable.




Linking with LLVM on Windows

2012-09-05 Thread cal
I'm trying to link with a recent build of LLVM on windows. I 
built LLVM 3.1 as a DLL using mingw, converted DLL to LIB with 
implib, however the link fails with the error


C:\cal\D\dmd2\windows\bin\..\lib\snn.lib(printf)  Offset FFAB9H 
Record Type 00C3

 Error 1: Previous Definition Different : _fprintf

Has anyone tried linking with LLVM under Windows? I can't seem to 
find where LLVM redefines or pulls-in fprintf, although I can see 
where it is in the LIB.


Appreciate any suggestions.



Re: DerelictGL program draw nothing

2012-09-03 Thread cal

On Monday, 3 September 2012 at 15:21:59 UTC, Zhenya wrote:

Why this simple program don't show white square?
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2d(0,0);
glVertex2d(0,height);
glVertex2d(width,height);
glVertex2d(height,0); glVertex2d(width, 0)
glEnd();
}


If that doesn't work, maybe you need to wind the vertices the 
other way to avoid backface culling, ie:


glVertex2d(0, 0)
glVertex2d(width, 0)
glVertex2d(width, height)
glVertex2d(0, height)



Re: DerelictGL program draw nothing

2012-09-03 Thread cal

On Monday, 3 September 2012 at 17:02:46 UTC, Zhenya wrote:

that dosn't work


How large is your window?

glViewport(0,0,width,height);

should really be setting to the window size - so if you make your 
window 800,800, this should be


glViewport(0,0,800,800);



Re: DerelictGL program draw nothing

2012-09-03 Thread cal

On Monday, 3 September 2012 at 17:08:55 UTC, cal wrote:

On Monday, 3 September 2012 at 17:02:46 UTC, Zhenya wrote:

that dosn't work


How large is your window?

glViewport(0,0,width,height);

should really be setting to the window size - so if you make 
your window 800,800, this should be


glViewport(0,0,800,800);


Just saw it, never mind. Also, I think before you draw, you need 
to set the matrix mode to modelview, and load identity...


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
display();



Re: DerelictGL program draw nothing

2012-09-03 Thread cal

On Monday, 3 September 2012 at 17:16:54 UTC, Zhenya wrote:

I added it to this code,but nothing changed(


Its a puzzler then, FWIW the following code works for me (I don't 
use GLFW, I have my own window routines, but the opengl-specific 
calls are the same).


Window(window1, WindowState(0,0,200,200), Flag!Create.yes, 
Flag!Show.yes);

Window.makeCurrent(window1);

glViewport(0,0,200,200);
glClearColor(0,0,0,1);

bool finish = false;
while (!finish)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-200, 200, -200, 200, -1, 1);
glClear( GL_COLOR_BUFFER_BIT );
glBegin(GL_POLYGON);
glVertex2d(0, 0);
glVertex2d(0, 200);
glVertex2d(200, 200);
glVertex2d(200, 0);
glEnd();
Window().swapBuffers();

if (Window().keyState().keys[KEY.KC_ESCAPE])
finish = true;
}

Perhaps something in the GLFW init is modyfying some OpenGL 
defaults or something, you might like to ask on their forum.


Re: Derelict3+SFML2

2012-09-01 Thread cal

On Saturday, 1 September 2012 at 15:53:20 UTC, Zhenya wrote:
Hello, I've got a little problem with DerelictSFML2. Despite 
the fact that I downloaded from the official website binaries 
CSFML2, this little application closes with the message: 
Failed to load symbol sfWindow_setSize from shared library 
csfml-window-2.dll


I just had a look at the windows sfml2 binary folder, and the 
setSize symbol is not included in the csfml-window-2.dll exports 
(although getSize is). You might have to rebuild from source. 
(There are quite a few symbols missing from the prebuilt 
binaries, based on what should be there from the docs on the 
website).




Re: rdmd exception def multiple files

2012-08-31 Thread cal

On Friday, 31 August 2012 at 17:14:25 UTC, Charles Hixson wrote:
If I ran DustMite on the original, the program got reduced down 
to void main () { } (with some extra whitespace).


And does rdmd compilation still fail with the reduced case?



Re: CTFE toUpper/toLower

2012-08-30 Thread cal
On Thursday, 30 August 2012 at 05:26:52 UTC, Philippe Sigaud 
wrote:

And with no UFCS ? Did you try s ~= toUpper(field) ~ , ;


Yeah with or without UFCS, the second one fails.



Re: CTFE toUpper/toLower

2012-08-30 Thread cal

On Thursday, 30 August 2012 at 06:30:50 UTC, Jacob Carlborg wrote:

On 2012-08-30 08:28, Jacob Carlborg wrote:


It works for me. DMD 2.060 Mac OS X.


Oh, it does not. If I replace:

enum string[] fields = [EnumMembers!E].to!(string[]);

With:

enum string[] fields = [one, two];

It works.


Yeah its weird because:

enum string[] literalFields = [one, two];
enum string[] enumFields = [EnumMembers!E].to!(string[]);

pragma(msg, literalFields[0] == enumFields[0]);

prints true, but toUpper works on the first and not the second


  1   2   >