my own directx tutorials

2012-08-31 Thread ElfQT
Hi there again D people!

I've ported the first six DirectX tutorials back in 2005 august to D,
and lost almost but the basic code for that...
Cannot find it on my machines or the internet...
One file was dx_vertices.zip, but all of the C++
SDKSamples\C++\Direct3D\Tutorials\ been ported to D by me.

If anyone have the old code, I would appreciate to send it to me.

Thanks,
ElfQT


Re: my own directx tutorials

2012-08-31 Thread ElfQT
OK, nevermind I found them. ;)


Trait to get function parameter names

2012-08-31 Thread mist

Subject.
Is that possible? I see only parameter type tuple stuff out 
there. I'm looking into iterating over own parameter name list 
inside of function.


Assigning global and static associative arrays

2012-08-31 Thread ixid

Why does this not work:

int[string] dayNumbers =
[ Monday   : 0, Tuesday : 1, Wednesday : 2,
  Thursday : 3, Friday  : 4, Saturday  : 5,
  Sunday   : 6 ];

void main() {
//Stuff
}

With the error 'non-constant expression'? This error also seems 
to prevent me making static associative arrays in functions 
elegantly.


popFront with input variables

2012-08-31 Thread Joseph Rushton Wakeling

Hello all,

Is it considered legit in any circumstances for popFront to take an input 
variable (e.g. a random number generator)?  Or is it required always to have no 
input variables?


Thanks  best wishes,

-- Joe


Re: popFront with input variables

2012-08-31 Thread bearophile

Joseph Rushton Wakeling:

Is it considered legit in any circumstances for popFront to 
take an input variable (e.g. a random number generator)?  Or is 
it required always to have no input variables?


popFront is meant to be called by foreach, or to be verified by
the isSomething compile-time tests of std.range. In both cases if
popFront takes an argument, it doesn't work. So I think it's not
a good idea.

struct Foo {
 enum bool empty = false;
 @property int front() { return 1; }
 void popFront(int x) {}
 //void popFront() {}
}
void main() {
 import std.stdio;
 foreach (i; Foo())
 writeln(i);
}


temp.d(9): Error: function temp.Foo.popFront (int x) is not
callable using argument types ()
temp.d(9): Error: expected 1 function arguments, not 0

Bye,
bearophile


Re: Use .get() in MultiD Assoc Array?

2012-08-31 Thread Paul
You're welcome. Note that your need of having a structure which 
is
both associative and ordered is, if not unheard-of, at least 
somewhat

uncommon.


I'm parsing program blocks from a proprietary HW/SW system.  They 
provide the data in the form of:


Somegroupname/Someblockname
   someparam=value
   anotherparam=value
   ...
   otherparam=value
end

Somegroupname/Somediffblockname
   someparam=value
   anotherparam=value
   ...
   otherparam=value
end

Someothergroupname/Someotherblockname
   p1=value
   p2=value
   ...
   px=value
end

The data is in an ascii text file.
I need to be able to search it by group/block/parameter.
I need to be able to maintain group/block order.
There are ~hundred diff block types where the params and order of 
params are known...though I would rather not create all of these 
structures or lists ahead of time.


My greatest need at this point is to compare two files block by 
block.  The blocks may be in diff orders between the files but 
the params of each block type would always be the same in the 
same order.


So compare groups, blocks within groups, and the values of each 
param for matching group/block names.


Re: popFront with input variables

2012-08-31 Thread Simen Kjaeraas
On Fri, 31 Aug 2012 16:56:32 +0200, Joseph Rushton Wakeling  
joseph.wakel...@webdrake.net wrote:



Hello all,

Is it considered legit in any circumstances for popFront to take an  
input variable (e.g. a random number generator)?  Or is it required  
always to have no input variables?


No parameters, or at least it should be callable with no parameters.

Might I ask why you'd want this?

--
Simen


Re: Assigning global and static associative arrays

2012-08-31 Thread Mike Parker

On 8/31/2012 11:38 PM, ixid wrote:

Why does this not work:

int[string] dayNumbers =
 [ Monday   : 0, Tuesday : 1, Wednesday : 2,
   Thursday : 3, Friday  : 4, Saturday  : 5,
   Sunday   : 6 ];

void main() {
 //Stuff
}

With the error 'non-constant expression'? This error also seems to
prevent me making static associative arrays in functions elegantly.


Non-const variables cannot be initialized at module-scope. If you don't 
need to modify the aa, declaring it immutable should allow the 
initialization to work. Otherwise, you can initialize it using a static 
module constructor.


int[string] dayNumbers;

static this()
{
   dayNumbers = ...;
}

void main() {...}


Re: Assigning global and static associative arrays

2012-08-31 Thread Mike Parker

On 9/1/2012 1:31 AM, Mike Parker wrote:

On 8/31/2012 11:38 PM, ixid wrote:

Why does this not work:

int[string] dayNumbers =
 [ Monday   : 0, Tuesday : 1, Wednesday : 2,
   Thursday : 3, Friday  : 4, Saturday  : 5,
   Sunday   : 6 ];

void main() {
 //Stuff
}

With the error 'non-constant expression'? This error also seems to
prevent me making static associative arrays in functions elegantly.


Non-const variables cannot be initialized at module-scope. If you don't
need to modify the aa, declaring it immutable should allow the
initialization to work. Otherwise, you can initialize it using a static
module constructor.

int[string] dayNumbers;

static this()
{
dayNumbers = ...;
}

void main() {...}


Nevermind. I spoke too soon. It's the literal [Monday : 0, ...] that's 
not constant. You'll have to use the module constructor.




Re: popFront with input variables

2012-08-31 Thread Jonathan M Davis
On Friday, August 31, 2012 15:56:32 Joseph Rushton Wakeling wrote:
 Hello all,
 
 Is it considered legit in any circumstances for popFront to take an input
 variable (e.g. a random number generator)? Or is it required always to have
 no input variables?

Don't do it. Technically speaking, as long as it's callable with no arguments, 
you should be able to do it. isInputRange just checks that it's callable with 
no arguments:

template isInputRange(R)
{
 enum bool isInputRange = is(typeof(
 (inout int _dummy=0)
 {
 R r = void; // can define a range object
 if (r.empty) {} // can test for empty
 r.popFront(); // can invoke popFront()
 auto h = r.front; // can get the front of the range
 }));
}

but no range-based anything is going to call popFront with any arguments, and 
it goes against how popFront works. If you want a function which takes an 
argument and pops of the front as well, then create a new one. Don't use 
popFront for that. I have no idea why you'd ever _want_ to do that though. You 
have a highly abnormal use case if it makes any sense for you to be declaring 
a popFront which takes an argument.

- Jonathan M Davis


Re: Assigning global and static associative arrays

2012-08-31 Thread Jonathan M Davis
On Friday, August 31, 2012 16:38:13 ixid wrote:
 Why does this not work:
 
 int[string] dayNumbers =
 [ Monday : 0, Tuesday : 1, Wednesday : 2,
 Thursday : 3, Friday : 4, Saturday : 5,
 Sunday : 6 ];
 
 void main() {
 //Stuff
 }
 
 With the error 'non-constant expression'? This error also seems
 to prevent me making static associative arrays in functions
 elegantly.

Because they can't be declared at runtime like that. For that to work, they'd 
have to be constructable at compile time and then have the structure persist 
to runtime, and with all of the pointers and whatnot in an AA, that's far from 
trivial. The same occurs with classes. While you can use some of them in CTFE, 
you can't use them to directly initialize any variables whose values need to 
be known at compile time and persist until runtime.

You have to use static constructor to initialize the variable at runtime.

static this()
{
 //initialization code here...
}

- Jonathan M Davis


Re: Assigning global and static associative arrays

2012-08-31 Thread ixid

Thank you, that certainly makes sense.


Re: rdmd exception def multiple files

2012-08-31 Thread Charles Hixson

On 08/30/2012 10:46 PM, cal wrote:

On Friday, 31 August 2012 at 04:00:34 UTC, Charles Hixson wrote:

Perhaps I don't know enough to file a decent bug report...at least
when I can't reduce the test case that shows it significantly.


Dustmite refers to this tool: https://github.com/CyberShadow/DustMite

Basically it tries to compile your program, and while compilation
continues to fail, it repeatedly tries to strip away parts of the
program until your are left with the minimal amount of code required for
compilation to fail. It is rather neat.

You could throw your code up on http://dpaste.dzfl.pl/new or something
and someone could take a look, it is just hard to speculate without
seeing any code...


Thank you for the pointer to DustMite.  It looks like it might be quite 
useful in other cases.  But...


So I tried to use DustMite.  This just got weirder.  Apparently if the 
name of the containing folder isn't Parser (I was working with a copy), 
then the error doesn't occur.  If I ran DustMite on the original, the 
program got reduced down to void main () { } (with some extra whitespace).


N.B.:  dmd doesn't have a problem with the code, only rdmd.



Re: Assigning global and static associative arrays

2012-08-31 Thread Philippe Sigaud
On Fri, Aug 31, 2012 at 7:04 PM, ixid nuacco...@gmail.com wrote:
 Thank you, that certainly makes sense.

If you're certain you won't need to modify it, you can make it a
compile-time constant:

enum int[string] dayNumbers =
[ Monday   : 0, Tuesday : 1, Wednesday : 2,
  Thursday : 3, Friday  : 4, Saturday  : 5,
  Sunday   : 6 ];

void main() {
//Stuff
}


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: Use .get() in MultiD Assoc Array?

2012-08-31 Thread Philippe Sigaud
On Fri, Aug 31, 2012 at 5:56 PM, Paul phshaf...@gmail.com wrote:

 The data is in an ascii text file.
 I need to be able to search it by group/block/parameter.
 I need to be able to maintain group/block order.
 There are ~hundred diff block types where the params and order of params are
 known...though I would rather not create all of these structures or lists
 ahead of time.

 My greatest need at this point is to compare two files block by block.  The
 blocks may be in diff orders between the files but the params of each block
 type would always be the same in the same order.

 So compare groups, blocks within groups, and the values of each param for
 matching group/block names.

I see. In that case, your original idea of having a three-tier
associative array (AA in AA in AA) is better than my tuple-key
suggestion, since you want to look into all three levels. Does the
provider ensure that no two groups have the same name and no two
blocks in a group have the same name?

If the blocks are in a different order, you don't care about order,
right? Then use an AA. As params of each block always have the same
order, you can use a dynamic array.

So:

struct Param
{
string name, value;
}

struct Block
{
string name;
Param[] params;
}

struct Group
{
string name;
Block[string] blocks;
}

alias Group[string] InputFile;

InputFile file1, file2;


Maybe someone here will have a better idea?


Re: Use .get() in MultiD Assoc Array?

2012-08-31 Thread Ali Çehreli

On 08/31/2012 08:56 AM, Paul wrote:
 You're welcome. Note that your need of having a structure which is
 both associative and ordered is, if not unheard-of, at least somewhat
 uncommon.

 I'm parsing program blocks from a proprietary HW/SW system. They provide
 the data in the form of:

 Somegroupname/Someblockname
 someparam=value
 anotherparam=value
 ...
 otherparam=value
 end

 Somegroupname/Somediffblockname
 someparam=value
 anotherparam=value
 ...
 otherparam=value
 end

 Someothergroupname/Someotherblockname
 p1=value
 p2=value
 ...
 px=value
 end

 The data is in an ascii text file.
 I need to be able to search it by group/block/parameter.
 I need to be able to maintain group/block order.
 There are ~hundred diff block types where the params and order of params
 are known...though I would rather not create all of these structures or
 lists ahead of time.

 My greatest need at this point is to compare two files block by block.
 The blocks may be in diff orders between the files but the params of
 each block type would always be the same in the same order.

 So compare groups, blocks within groups, and the values of each param
 for matching group/block names.

Wrap your string[string][string][string] in a user-defined type that 
provides the 'in' operator as well as opIndex and friends. I have 
started writing this but could not finish it yet:


import std.exception;

class MyTable
{
string[string][string][string] elements;

struct Index
{
string i0;
string i1;
string i2;
}

// Enables the 'auto element = myIndex in myTable' syntax
// (Note: I should have called it Key, not Index.)
string * opBinary(string op)(Index index)
if (op == in)
{
string * result = null;

if (auto table0 = index.i0 in elements) {
if (auto table1 = index.i1 in *table0) {
if (auto element = index.i2 in *table1) {
result = element;
}
}
}

return result;
}

// Enables 'auto value = myTable[myIndex]'
ref string opIndex(Index index)
{
string * result = this.opBinary!in(index);
enforce(result);

return *result;
}

// Enables 'myTable[myIndex] = value'
void opIndexAssign(string value, Index index)
{
auto existing = this.opIndex(index);

if (existing) {
existing = value;

} else {
// TODO: ensure that this Index exists
}
}

// TODO: Look up oopIndexUnary and opIndexOpAssign

string get(Index index, string defaultValue)
{
string * result = this.opBinary!in(index);
return result ? *result : defaultValue;
}
}

void main()
{}

Ali



Re: Trait to get function parameter names

2012-08-31 Thread Jacob Carlborg

On 2012-08-31 16:24, mist wrote:

Subject.
Is that possible? I see only parameter type tuple stuff out there. I'm
looking into iterating over own parameter name list inside of function.


Here: http://dlang.org/traits.html#parameterNames

--
/Jacob Carlborg


Re: Trait to get function parameter names

2012-08-31 Thread mist

On Friday, 31 August 2012 at 19:15:14 UTC, Jacob Carlborg wrote:

On 2012-08-31 16:24, mist wrote:

Subject.
Is that possible? I see only parameter type tuple stuff out 
there. I'm
looking into iterating over own parameter name list inside of 
function.


Here: http://dlang.org/traits.html#parameterNames


Thank you.


Re: Assigning global and static associative arrays

2012-08-31 Thread Jonathan M Davis
On Friday, August 31, 2012 20:24:27 Philippe Sigaud wrote:
 On Fri, Aug 31, 2012 at 7:04 PM, ixid nuacco...@gmail.com wrote:
  Thank you, that certainly makes sense.
 
 If you're certain you won't need to modify it, you can make it a
 compile-time constant:
 
 enum int[string] dayNumbers =
 [ Monday : 0, Tuesday : 1, Wednesday : 2,
 Thursday : 3, Friday : 4, Saturday : 5,
 Sunday : 6 ];
 
 void main() {
 //Stuff
 }

Except that that allocates a new AA every time that you use dayNumbers. So, 
that's probably a bad idea.

- Jonathan M Davis


Re: rdmd exception def multiple files

2012-08-31 Thread Charles Hixson

On 08/31/2012 11:28 AM, cal wrote:

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?

No.  But there were even more complex versions in which it also didn't 
fail.  For instance I could import utils.d (the addition of which caused 
the original to stop working) and throw a LogicError (defined in 
utils.d) and it didn't crash.


So I only have the large case...and even there, I've been working on the 
project, as dmd doesn't give any problems, and so I can't guarantee 
without checking again that it still fails.  But since nobody wants a 
500 line test case (and I don't blame them...particularly since it 
appears that if I move it into a folder with a different name it stops 
failing), I haven't been preserving the case.  Last time I checked it 
still failed with rdmd in the Parser folder, but that was hours ago. 
There haven't been many changes, but there've been some.  And I can't 
even preserve it by copying it into another folder, because then it 
stops failing.


Re: Assigning global and static associative arrays

2012-08-31 Thread ixid

Philippe suggested enum allowing this:

enum dayNumbers = [ Monday : 0, Tuesday : 1, Wednesday : 2,
 Thursday : 3, Friday : 4, Saturday : 5,
 Sunday : 6 ];

Why does this seem to avoid pointer issues? Is it creating a 
compile-time associated array or run-time?


Re: Assigning global and static associative arrays

2012-08-31 Thread Philippe Sigaud
On Fri, Aug 31, 2012 at 9:56 PM, Jonathan M Davis jmdavisp...@gmx.com wrote:

 Except that that allocates a new AA every time that you use dayNumbers. So,
 that's probably a bad idea.

Oh! I keep forgetting that enums are replaced by their values. Then I
think I know where some problem I had came from.

Damn, just tested using a static this and my code runs 40% faster!

Benchmarking time, thanks Jonathan.


Re: Assigning global and static associative arrays

2012-08-31 Thread Philippe Sigaud
On Fri, Aug 31, 2012 at 10:34 PM, ixid nuacco...@gmail.com wrote:
 Philippe suggested enum allowing this:

 enum dayNumbers = [ Monday : 0, Tuesday : 1, Wednesday : 2,

  Thursday : 3, Friday : 4, Saturday : 5,
  Sunday : 6 ];

 Why does this seem to avoid pointer issues? Is it creating a compile-time
 associated array or run-time?

It defines an AA literal that's used directly in lieu of dayNumbers
every time dayNumbers appears in your code, I think.


Re: Assigning global and static associative arrays

2012-08-31 Thread ixid
Yep, I am aware of that, for my use it happens to be perfect but 
I understand that having a bunch of copies all over the place 
wouldn't be smart.


segfault

2012-08-31 Thread Ellery Newcomer

hey, is anyone else getting a segfault from dmd on this code?

struct a{
static if(i) {
}elseenum z = ;
}


2.060 x64 linux

and if they do, I call dibs on the bug report


Re: Assigning global and static associative arrays

2012-08-31 Thread ixid
Hmm, you mean if you call the same function it creates a new copy 
every time? I misunderstood you to mean it creates it once at 
each site in the code it's called.




Re: segfault

2012-08-31 Thread Andrej Mitrovic
On 8/31/12, Ellery Newcomer ellery-newco...@utulsa.edu wrote:
 hey, is anyone else getting a segfault from dmd on this code?

Yep on win32.


Re: Assigning global and static associative arrays

2012-08-31 Thread Jonathan M Davis
On Saturday, September 01, 2012 00:12:06 ixid wrote:
 Hmm, you mean if you call the same function it creates a new copy
 every time? I misunderstood you to mean it creates it once at
 each site in the code it's called.

enum values are basically copy-pasted everywhere that they're used. So, if you 
have something like

enum arr = [1, 2, 3, 4 5];

auto a = arr;
auto b = arr;
auto c = arr;

it's effectively identical to

auto a = [1, 2, 3, 4, 5];
auto b = [1, 2, 3, 4, 5];
auto c = [1, 2, 3, 4, 5];

as opposed to actual variable such as

auto arr = [1, 2, 3, 4, 5];

auto a = arr;
auto b = arr;
auto c = arr;

In this case, each variable is actually a slice of the same array rather than 
duplicating the value.

Using an enum is particularly bad for an AA, since it's not exactly a simple 
data type, and there's definitely some cost to constructing them.

- Jonathan M Davis


Re: rdmd exception def multiple files

2012-08-31 Thread anonymous

On Friday, 31 August 2012 at 20:20:42 UTC, Charles Hixson wrote:
So I only have the large case...and even there, I've been 
working on the project, as dmd doesn't give any problems, and 
so I can't guarantee without checking again that it still 
fails.  But since nobody wants a 500 line test case (and I 
don't blame them...particularly since it appears that if I move 
it into a folder with a different name it stops failing), I 
haven't been preserving the case.  Last time I checked it still 
failed with rdmd in the Parser folder, but that was hours ago. 
There haven't been many changes, but there've been some.  And I 
can't even preserve it by copying it into another folder, 
because then it stops failing.


A big test is worse than a small one, but still better than no 
test case whatsoever. If you provide your 500 lines, someone 
might be able to spot an already known issue (e.g. you may be 
hitting issue 7016 [1]), or someone is willing to reduce it 
further. At the very least, it's in the database and can be dealt 
with sooner or later.


[1] local import does not create -deps dependency - 
http://d.puremagic.com/issues/show_bug.cgi?id=7016


import std.random fails

2012-08-31 Thread deed


import std.random

void main() {}
---

results in:

Error 42: Symbol Undefined
_D4core6memory2GC6qallocFkkZS4core6memory8BLkInfo_
Error 42: Symbol Undefined _D4core6memory2GC6extendFPvkkZk
Error 42: Symbol Undefined _D4core5bitop3bsrFNaNbkZi
--- errorlevel 3


What is wrong?


Re: import std.random fails

2012-08-31 Thread ixid

You're missing the semi-colon after import std.random.


import std.random;

void main() {}


Re: import std.random fails

2012-08-31 Thread deed

On Friday, 31 August 2012 at 22:44:11 UTC, ixid wrote:

You're missing the semi-colon after import std.random.


Sorry, typo. Semicolon is included in the file. DMD 2.060.




Re: import std.random fails

2012-08-31 Thread Jonathan M Davis
On Saturday, September 01, 2012 00:40:25 deed wrote:
 
 import std.random
 
 void main() {}
 ---
 
 results in:
 
 Error 42: Symbol Undefined
 _D4core6memory2GC6qallocFkkZS4core6memory8BLkInfo_
 Error 42: Symbol Undefined _D4core6memory2GC6extendFPvkkZk
 Error 42: Symbol Undefined _D4core5bitop3bsrFNaNbkZi
 --- errorlevel 3
 
 
 What is wrong?

You druntime installation is bad due to some cruft left from a previous 
install (the installer obviously needs some work). If you used an installer, 
then uninstall dmd, make sure that it's completely removed, and then reinstall 
it.

If you installed it manually, then make sure that you blow away druntime's 
import directory and then restore it with the current version of those files.

- Jonathan M Davis


Re: import std.random fails

2012-08-31 Thread deed
You druntime installation is bad due to some cruft left from a 
previous
install (the installer obviously needs some work). If you used 
an installer,
then uninstall dmd, make sure that it's completely removed, and 
then reinstall

it.

If you installed it manually, then make sure that you blow away 
druntime's
import directory and then restore it with the current version 
of those files.


- Jonathan M Davis



Thanks. Had not tried that and it sounds as a probable reason.


Re: import std.random fails

2012-08-31 Thread deed

Reinstallation solved the case. Thanks for your prompt reply.




Re: segfault

2012-08-31 Thread Ellery Newcomer

On 08/31/2012 03:18 PM, Andrej Mitrovic wrote:

On 8/31/12, Ellery Newcomer ellery-newco...@utulsa.edu wrote:

hey, is anyone else getting a segfault from dmd on this code?


Yep on win32.



thanks


Re: Use .get() in MultiD Assoc Array?

2012-08-31 Thread Ali Çehreli

On 08/31/2012 11:55 AM, Ali Çehreli wrote:

 class MyTable

[...]

 // Enables the 'auto element = myIndex in myTable' syntax

That's wrong. For that syntax to work, the operator below should have 
been opBinaryRight.


 string * opBinary(string op)(Index index)

Yeah, that should have been opBinaryRight.

(And the badly designed Thunderbird removes the indentation in quoted 
text. Smart application or stupid designer?)


 // Enables 'auto value = myTable[myIndex]'
 ref string opIndex(Index index)
 {
 string * result = this.opBinary!in(index);

If I had defined opBinaryRight as I should have, then I could simply use 
the 'in' operator on the right-hand side:


string * result = index in this;

 Ali

Ali
too