Re: Weird array setting behaviour on Windows(-m64)

2016-04-13 Thread ref2401 via Digitalmars-d-learn
On Wednesday, 13 April 2016 at 15:07:09 UTC, rikki cattermole 
wrote:



Verified that it is a codegen problem for Win64 and not *nix.
Please file a bug report.


https://issues.dlang.org/show_bug.cgi?id=15921
Done, Thanks



Weird array setting behaviour on Windows(-m64)

2016-04-13 Thread ref2401 via Digitalmars-d-learn

Hello,

I got stuck with a weird array setting behaviour and I need help. 
Just have a look at the example.


OS: Win 8.1 Pro
DMD: v2.071.0
Build-cmd: dmd main.d -ofconsole-app.exe -debug -unittest -g -wi 
-m64


module dmain;
import std.stdio;

struct Vec {
float a;
}

void main(string[] args) {
Vec[] array = new Vec[4];

	writeln("before: ", array); //  prints [Vec(nan), Vec(nan), 
Vec(nan), Vec(nan)]


array[] = Vec(24);

	writeln("after: ", array); // prints [Vec(0), Vec(0), Vec(0), 
Vec(0)]

}

Seems like slicing is broken in general. All the following 
variations produce different results but they are all wrong.

array[] = Vec(24);
array[0 .. 1] = Vec(24);
array[0 .. $] = Vec(24);

It works as expected if I do one of the following things:
1. Get rid of -m64. If I compile with -m32 flag then I cannot 
replicate the issue.


2. Changing the type of the Vec.a field from float to real, int, 
uint, long, ulong fixes the issue. Double still causes the issues.


3. Adding new fields to the Vec struct.

3.1. Vec {float a, b; } still does not work but the result is 
slightly different.

array[] = Vec(24, 5);
writeln("after: ", array); // [Vec(5, 0), Vec(5, 0), Vec(5, 0), 
Vec(5, 0)]


3.2. Vec { float a, b, c; } works fine.

4. Using index operator: array[0] = Vec(24) works fine



Re: Error: template instance does not match template declaration

2016-03-30 Thread ref2401 via Digitalmars-d-learn

On Tuesday, 29 March 2016 at 18:29:27 UTC, Ali Çehreli wrote:
So, dict is a template value parameter of type T[string]. I 
don't think you can use an associative array as a template 
value parameter. (Can we?)


Found this in D language reference:
https://dlang.org/spec/template.html#template_value_parameter
Template value arguments can be integer values, floating point 
values, nulls, string values,
array literals of template value arguments, associative array 
literals of template value arguments...


So yes, associative arrays as template parameters are supposed to 
work.





Re: Error: template instance does not match template declaration

2016-03-29 Thread ref2401 via Digitalmars-d-learn

On Tuesday, 29 March 2016 at 18:29:27 UTC, Ali Çehreli wrote:

On 03/29/2016 11:21 AM, ref2401 wrote:

So, dict is a template value parameter of type T[string]. I 
don't think you can use an associative array as a template 
value parameter. (Can we?)


However, it is possible to use anything as an alias template 
parameter.


If it's acceptable in your case, the following works:

private void impl(S, T, alias dict)(S arg)
if (is (typeof(dict) == T[S])) {

(Or T[string]).

Ali


alias works for me, thank you.


Error: template instance does not match template declaration

2016-03-29 Thread ref2401 via Digitalmars-d-learn

OS: Win 8.1 Pro
DMD: v2.070.0
cmd: dmd main.d -ofconsole-app.exe -debug -unittest -wi

Code is successfully compiled until I uncomment test1 function 
call in the main.

If it's uncommented I get the following compile-time error:

main.d(58): Error: template instance impl!(string, bool, 
["y":true, "n":false]) does not match template declaration 
impl(S, T, Color[string] dict)(S arg)
main.d(62): Error: template instance mainentry.test1!string error 
instantiating


What have I done wrong?
Thank you.

import std.stdio;

enum Color { RED, GREEN }

private void impl(S, T, T[string] dict)(S arg) {
writeln("S: ", S.stringof);
writeln("T: ", T.stringof);
writeln("dict: ", dict);
}

unittest {
enum COLOR_MAP = [
"r": Color.RED,
"g": Color.GREEN
];

void test0(S)(S arg) {
impl!(S, Color, COLOR_MAP)(arg);
}

test0("000");
}

void test1(S)(S arg) {
impl!(S, bool, ["y": true, "n": false])(arg);
}

void main(string[] args) {
	// test1("111"); // if you uncomment this line you'll get a 
compile-time error

}


pass a struct by value/ref and size of the struct

2016-03-21 Thread ref2401 via Digitalmars-d-learn
I have got a plenty of structs in my project. Their size varies 
from 12 bytes to 128 bytes.
Is there a rule of thumb that states which structs I pass by 
value and which I should pass by reference due to their size?


Thanks.


Re: Link error 42 (WinApi)

2016-02-15 Thread ref2401 via Digitalmars-d-learn
On Tuesday, 16 February 2016 at 06:22:33 UTC, Rikki Cattermole 
wrote:

Found the problem, you haven't linked against gdi.


Thank you It works. I should have done this:

set filesToUse=main.d gdi32.lib
dmd @filesToUse -ofconsole-app.exe -debug -unittest -wi


Re: Link error 42 (WinApi)

2016-02-15 Thread ref2401 via Digitalmars-d-learn
On Tuesday, 16 February 2016 at 05:39:26 UTC, Rikki Cattermole 
wrote:

Try compiling with 64bit.
If it works, its just the import libs not containing the symbol.


dmd main.d -ofconsole-app.exe -debug -unittest -wi -m64

That's what I'm getting now:

console-app.obj : error LNK2019: unresolved external symbol 
ChoosePixelFormat referenced in function _Dmain

console-app.exe : fatal error LNK1120: 1 unresolved externals


Re: Region allocator strage error

2016-02-01 Thread ref2401 via Digitalmars-d-learn

On Sunday, 31 January 2016 at 14:48:34 UTC, ref2401 wrote:
I am getting runtime error: 
core.exception.AssertError@std\experimental\allocator\building_blocks\region.d(235): Assertion failure


At least tell me can anyone replicate it?


Region allocator strage error

2016-01-31 Thread ref2401 via Digitalmars-d-learn
I am getting runtime error: 
core.exception.AssertError@std\experimental\allocator\building_blocks\region.d(235): Assertion failure


if LEN equals to 3, 5, 7, 9, ...

void main(string[] args) {
ubyte[1024] memory;
auto stackAlloc = Region!NullAllocator(memory);
IAllocator alloc = allocatorObject();

enum LEN = 11;
float[] arr = alloc.makeArray!float(LEN);
alloc.expandArray(arr, LEN);
}

OS: win 8.1 Enterprise x64
DMD: 2070.0
platformAlignment: 8

Any thoughts?
Thank you.


InSituRegion + allocatorObject compile time error

2016-01-29 Thread ref2401 via Digitalmars-d-learn

Getting this error, could someone explain why?

void main(string[] args) {
InSituRegion!(1024) stackAlloc;
IAllocator alloc = allocatorObject(stackAlloc);
}

..\src\phobos\std\conv.d(5055):
Error: static assert  "Don't know how to initialize an object of 
type CAllocatorImpl!(InSituRegion!(1024u, 8u), cast(Flag)false) 
with arguments (InSituRegion!(1024u, 8u))"


..\src\phobos\std\experimental\allocator\package.d(1175):
instantiated from here: 
emplace!(CAllocatorImpl!(InSituRegion!(1024u, 8u), 
cast(Flag)false), InSituRegion!(1024u, 8u))


main.d(15):
instantiated from here: allocatorObject!(InSituRegion!(1024u, 8u))

Thank you


Re: Make function nothrow

2016-01-28 Thread ref2401 via Digitalmars-d-learn

On Thursday, 28 January 2016 at 16:22:23 UTC, Ali Çehreli wrote:
There is assumeWontThrow which terminates if an exception is 
indeed thrown:


  http://dlang.org/library/std/exception/assume_wont_throw.html

Ali


nice one, thx



Re: std.experimental.yesnogc

2016-01-14 Thread ref2401 via Digitalmars-d

On Thursday, 14 January 2016 at 02:13:20 UTC, Ilya wrote:


std.memory --Ilya


That's a good one.


Re: Wishlist for D

2015-12-16 Thread ref2401 via Digitalmars-d

On Tuesday, 1 December 2015 at 16:48:00 UTC, Suliman wrote:

Right place is write here


My wish:
New `std.io` package that includes `std.file`, `std.path` and 
`std.stdio` modules.


static array crashes my program

2015-12-05 Thread ref2401 via Digitalmars-d-learn
I want to create a static array large enough to store 1MB of 
float values.

What am I doing wrong?
Here is a sample code with notes:

void main(string[] args) {
enum size_t COUNT = 1024 * 512 / float.sizeof; // works OK :)
	//enum size_t COUNT = 1024 * 512 * 2 / float.sizeof; // 
constantly crashes :(

float[COUNT] arr;
writeln(arr.length);
}

DMD: 2069.2
OS: Win 8.1 Pro


Which type it better to use for array's indices?

2015-12-04 Thread ref2401 via Digitalmars-d-learn

Which type it better to use for array's indices?

float[] arr = new float[10];
int i;
long j; 
size_t k;
// which one is better arr[i], a[j]or arr[k] ?

It seem like `size_t` suites well because 'is large enough to 
represent an offset into all addressible memory.' 
(http://dlang.org/spec/type.html#size_t)
However sometimes I want index to be less the 0 to represent a 
particular case.
For instance `find(float[] arr, float v)` may return -1 if `v` 
has not been found.


Again which type is better or put it into another words which 
type should I pick as default?


Thank you.


Re: Complexity nomenclature

2015-12-04 Thread ref2401 via Digitalmars-d
On Friday, 4 December 2015 at 16:06:25 UTC, Andrei Alexandrescu 
wrote:

Well look at what the cat dragged in:

http://dpaste.dzfl.pl/711aecacc450

That's quite promising. The code is very preliminary and uses 
strings for typical complexity values (e.g. "constant", 
"linear", and later "loglinear" etc). I need to see how to 
integrate this whole idea.


Also an unpleasant problem is overloading - when present, user 
code needs to specify which overload they're referring to.


Anyhow, this is really interesting. Thanks Tofu.


Andrei


Wow! It looks really great.



having problem with `std.algorithm.each`

2015-11-30 Thread ref2401 via Digitalmars-d-learn
It seems like `std.algorithm.each` is not executed in the example 
below.

Could anyone tell why?
Thank you.


import std.algorithm;

void main(string[] args) {
int[] arr = [1, 2, 3, 4, 5];

arr.each!((ref e) => {
writeln(e); // does not print
++e;
})();

writeln(arr); // prints [1, 2, 3, 4, 5]
}


Re: having problem with `std.algorithm.each`

2015-11-30 Thread ref2401 via Digitalmars-d-learn

DMD 2.069.1
OS Win8.1 Enterprise


Re: having problem with `std.algorithm.each`

2015-11-30 Thread ref2401 via Digitalmars-d-learn

On Monday, 30 November 2015 at 12:03:08 UTC, anonymous wrote:

On 30.11.2015 11:50, visitor wrote:

though i don"t understand why it fails silently ??


ref2491's original code is valid, but doesn't have the intended 
meaning. `e => {foo(e);}` is the same as `(e) {return () 
{foo(e);};}`, i.e. a (unary) function that returns a (nullary) 
delegate. Calling it does not run foo. In contrast, calling 
this runs foo: `e => foo(e)`.


Got it. Thank you)


Re: std.experimental.allocator optlink error

2015-11-10 Thread ref2401 via Digitalmars-d-learn

On Tuesday, 10 November 2015 at 08:48:37 UTC, ref2401 wrote:

On Tuesday, 10 November 2015 at 01:04:16 UTC, uiop wrote:
Can you find the sources in your setup ? Any chance that that 
phobos.lib is still the the one distributed with dmd 2.068 ?


How can I do that?


When you setup dmd 2.069, did you use the 7z or installer ?


Installer always

btw. Thanks for response. I started thinking nobody cares.


I downloaded the `dmd.2.069.0.windows.7z` file and replaced 
`phobos.lib` with one from the 7z package. Still getting the 
error.


Re: std.experimental.allocator optlink error

2015-11-10 Thread ref2401 via Digitalmars-d-learn

On Tuesday, 10 November 2015 at 01:04:16 UTC, uiop wrote:
Can you find the sources in your setup ? Any chance that that 
phobos.lib is still the the one distributed with dmd 2.068 ?


How can I do that?


When you setup dmd 2.069, did you use the 7z or installer ?


Installer always

btw. Thanks for response. I started thinking nobody cares.


std.experimental.allocator optlink error

2015-11-09 Thread ref2401 via Digitalmars-d-learn

Hello

I wrote a small hello world app and imported the 
`std.experimental.allocator` module.

I'm getting the following optlink error:
---
OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
console-app.obj(console-app)
Error 42: Symbol Undefined 
_D3std12experimental9allocator12__ModuleInfoZ

--- errorlevel 1
---
os: Windows 8.1 Enterprise
dmd:2.069.0
build sript:dmd main.d -ofconsole-app.exe -debug -unittest -wi

Thank you.


Re: std.experimental.allocator optlink error

2015-11-09 Thread ref2401 via Digitalmars-d-learn

On Monday, 9 November 2015 at 14:42:01 UTC, ref2401 wrote:

Hello

I wrote a small hello world app and imported the 
`std.experimental.allocator` module.

I'm getting the following optlink error:
---
OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
console-app.obj(console-app)
Error 42: Symbol Undefined 
_D3std12experimental9allocator12__ModuleInfoZ

--- errorlevel 1
---
os: Windows 8.1 Enterprise
dmd:2.069.0
build sript:dmd main.d -ofconsole-app.exe -debug -unittest -wi

Thank you.


I tested it with my home laptop(Win 8.1 Pro). Same error.
If I change `std.experimental.allocator` to 
`std.experimental.logger` then it builds fine.


Re: Allocation strategies question

2015-11-01 Thread ref2401 via Digitalmars-d-learn
On Friday, 30 October 2015 at 05:21:17 UTC, Rikki Cattermole 
wrote:

What I normally do for memory to be owned by the thread is:

auto foo(IAllocator alloc=theAllocator()) {...}

Where as for if it is global to the process:

auto foo(IAllocator alloc=processAllocator()) {...}

Basically it is the difference between a screenshot of a 
display and a window instance.


What do other think?


Re: good reasons not to use D?

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

On Friday, 30 October 2015 at 10:35:03 UTC, Laeeth Isharc wrote:

I'm writing a talk for codemesh on the use of D in finance.

I want to start by addressing the good reasons not to use D.  
(We all know what the bad ones are).  I don't want to get into 
a discussion here on them, but just wanted to make sure I cover 
them so I represent the state of affairs correctly.


So far what comes to mind: heavy GUI stuff (so far user 
interface code is not what it could be); cases where you want 
to write quick one-off scripts that need to use a bunch of 
different libraries not yet available in D and where it doesn't 
make sense to wrap or port them; where you have a lot of code 
in another language (especially non C, non Python) and defining 
an interface is not so easy; where you have many inexperienced 
programmers and they need to be productive very quickly.


Any other thoughts?


I'd suggest enterprise software because many necessary libraries 
and tools do not exist in D ecosystem. Though you've already 
named these reasons.


Allocation strategies question

2015-10-29 Thread ref2401 via Digitalmars-d-learn
As I understand the `std.experimental.allocator` package will be 
included in the upcoming DMD 2.069 release. I like the idea of 
composable allocators. Though I've got a question which I can not 
answer myself.


Let's assume a team which is developing an application that can 
benefit from usage of different allocation strategies. When a 
programmer implements a function/struct/class he may use whatever 
allocator he thinks fits his needs best. At some point the source 
code is going to be a mess because there will be so many places 
where different allocation strategies are used.
The question. Could you suggest robust practices, how to avoid 
designing such messy code?


Any information is appreciated.
Thank you.


Re: Allocation strategies question

2015-10-29 Thread ref2401 via Digitalmars-d-learn
On Friday, 30 October 2015 at 01:26:17 UTC, Rikki Cattermole 
wrote:

Take a look at the functions theAllocator and processAllocator.


It would be greate if compiler were able to use `theAllocator` 
and `processAllocator` but they don't seem much helpfull. 
Terrible naming by the way.


Re: Allocation strategies question

2015-10-29 Thread ref2401 via Digitalmars-d-learn

On Friday, 30 October 2015 at 04:11:05 UTC, ref2401 wrote:
It would be greate if compiler were able to use `theAllocator` 
and `processAllocator` but they don't seem much helpfull. 
Terrible naming by the way.


I should have suggested different names if don't like present 
ones.
if `processAllocator` stands for the whole process then there 
must be `threadAllocator` as well. But that's not the question.
I would like to know about usage strategies of various allocators 
within the same code.


final class & final methods

2015-09-25 Thread ref2401 via Digitalmars-d-learn
If I declare a class as `final` do I  have to mark all methods of 
the class as `final` too?


Re: Moving back to .NET

2015-09-22 Thread ref2401 via Digitalmars-d

On Tuesday, 22 September 2015 at 13:38:33 UTC, Chris wrote:
it's only from D that users expect perfection, other languages 
are accepted as they are, warts and all.

it's true



Re: any way to initialize an array of structs to void?

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

On Wednesday, 16 September 2015 at 14:48:59 UTC, Meta wrote:

Don't do this with a dynamic array, though, as they work a bit 
differently from static arrays.


Unfortunately I have to deal with dynamic arrays.


any way to initialize an array of structs to void?

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

struct MyStruct {
@disable this();

this(int a, string b) {
this.a = a;
this.b = b;
}

int a;
string b;
}

I know there is a way to create one instance of `MyStruct` and 
initialize it to void.

  MyStruct s = void;
  s = MyStruct(5, "abcdef");

How can initialize an array of `MyStruct` instances to void?
  auto arr = new MyStruct[10]; // compile-time Error: default 
construction is disabled for type MyStruct.


Re: any way to initialize an array of structs to void?

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

On Wednesday, 16 September 2015 at 14:57:49 UTC, Meta wrote:


In that case, you can use std.array.uninitializedArray or 
std.array.minimallyInitializedArray as needed.


http://dlang.org/phobos/std_array.html#uninitializedArray
http://dlang.org/phobos/std_array.html#.minimallyInitializedArray


Thanks)


D fund

2015-08-09 Thread ref2401 via Digitalmars-d

Does the fund exist?
Are there sponsors?
How can one donate some money to D?


Re: D fund

2015-08-09 Thread ref2401 via Digitalmars-d
I don't have much experience and time to contribute to code-base 
directly. But I'd like to donate some money every month. I think 
(hope) there are several guys who would like to donate to. There 
must be the way to do it.


Re: D for Game Development

2015-08-04 Thread ref2401 via Digitalmars-d

On Thursday, 30 July 2015 at 13:43:35 UTC, karabuta wrote:
D is really cool and makes a good candidate for developing a 
game. Are there any guys out there using D for indie games?


For some time I have been seeing some cool game engine being 
developed in the DUB repo. What more is happening? I don't see 
derelictSDl and derelictSFML activities much. Whatup?


You should have a look at this engine 
http://dash.circularstudios.com/


Re: D for Game Development

2015-08-04 Thread ref2401 via Digitalmars-d

On Tuesday, 4 August 2015 at 19:13:44 UTC, Rikki Cattermole wrote:

On 5/08/2015 6:59 a.m., develop32 wrote:

On Thursday, 30 July 2015 at 13:43:35 UTC, karabuta wrote:
D is really cool and makes a good candidate for developing a 
game. Are

there any guys out there using D for indie games?


Not an indie game, but Remedy is making Quantum Break using D.


Got a source for that? As I can't find it.


http://remedygames.com/job_offer/senior-tools-programmer/


D array to void* and back

2015-08-03 Thread ref2401 via Digitalmars-d-learn

Hello everyone,

I pass a D array as void* into a function.

When I'm trying to cast a void* parameter to a D array I get 
'Access Violation' error.
However if I define ArrayLike struct which looks like D array 
then casting will succeed.
What should I do? Should I stick to ArrayLike wrapper and just 
live? :)


struct ArrayLike(T) {
this(T[] arr) {
ptr = arr.ptr;
length = arr.length;
}

T* ptr;
size_t length;

T[] asArray() {
return ptr[0 .. length];
}
}

void funcLibC_Array(void* data) {
int[] arr = *cast(int[]*)data;
writeln(funcLibC_Array: , arr);
}

void funcLibC_ArrayLike(void* data) {
ArrayLike!int arrLike = *cast(ArrayLike!int*)data;
writeln(funcLibC_ArrayLike: , arrLike.asArray());
}

void main(string[] args) {
int[] arr = [1, 2, 3];
auto arrLike = ArrayLike!int(arr);


funcLibC_ArrayLike(arrLike);
	funcLibC_Array(arr.ptr); // 'Access Violation error' is thrown 
here.

}



Re: D array to void* and back

2015-08-03 Thread ref2401 via Digitalmars-d-learn

On Monday, 3 August 2015 at 21:28:29 UTC, Ali Çehreli wrote:

But you still need to communicate how many elements there are 
in the array. (I used literal 3).


Yes I do. I hope there is a neat way to pass array's length too.




Re: Negation of attributes (DIP 79)

2015-06-02 Thread ref2401 via Digitalmars-d

On Tuesday, 2 June 2015 at 10:29:35 UTC, Daniel Kozak wrote:
I am working on dip which will try to addressed negation of 
attributes issue.

http://wiki.dlang.org/DIP79


You propose to add extra difficulty to the language and the only 
reason is If you need add few methods which are virtual or 
variables, you are forced to put them before final:. This is too 
limiting..

I think it's a bad idea.


Re: Negation of attributes (DIP 79)

2015-06-02 Thread ref2401 via Digitalmars-d
This is by far not the only reason. It is just as well useful 
for all other attributes: const, pure, @safe/@system, @nogc, 
and maybe UDAs.


It's long been recognized that a mechanism to switch off a 
scope-wide attribute would be useful.


Switching attributes on and off will make your code more 
complicated. If one doesn't use scope-wide attributes much then 
he won't need to switch them off.


'const' and 'in' parameter storage classes

2015-05-15 Thread ref2401 via Digitalmars-d-learn
What is the difference between 'const' and 'in' parameter storage 
classes?

When should I use 'const' or 'in'?

The documentation says 'in' is the same as 'const scope' but I 
can't write 'const scope ref' though it's legal to write 'in ref'.


Thank you


Re: 'const' and 'in' parameter storage classes

2015-05-15 Thread ref2401 via Digitalmars-d-learn
On Friday, 15 May 2015 at 16:30:29 UTC, Steven Schveighoffer 
wrote:

On 5/15/15 12:04 PM, ref2401 wrote:
What is the difference between 'const' and 'in' parameter 
storage classes?

When should I use 'const' or 'in'?

The documentation says 'in' is the same as 'const scope' but I 
can't

write 'const scope ref' though it's legal to write 'in ref'.


scope ref const

-Steve


still getting the error: Error: scope cannot be ref or out


Re: 'const' and 'in' parameter storage classes

2015-05-15 Thread ref2401 via Digitalmars-d-learn

On Friday, 15 May 2015 at 16:08:31 UTC, Adam D. Ruppe wrote:
The scope storage class means you promise not to escape any 
reference to the data. This isn't enforced but it is similar in 
concept to Rust's borrowed pointers - it may someday be 
implemented to be an error to store them in an outside variable.


Only use 'in' if you are looking at the data, but not modifying 
or storing copies of pointers/references to it anywhere in any 
way.


I expected the compiler forbids 'in' params escaping.

struct MyStruct {
this(int a) {
this.a = a;
}

int a;
}


const(MyStruct)* globalPtr;

void main(string[] args) {
MyStruct ms = MyStruct(10);

foo(ms);
ms.a = 12;

writeln(global: , *globalPtr); // prints const(MyStruct)(12)
}

void foo(in ref MyStruct ms) {
globalPtr = ms; // is it legal?
}


Error: cannot modify struct arr[0] MyStruct with immutable members

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

struct MyStruct {
this(int a, int b) {
this.a = a;
this.b = b;
}

immutable int a;
immutable int b;
}

void main(string[] args) {
MyStruct[] arr = new MyStruct[3];

arr[0] = MyStruct(5, 7);
}   

Why does it happen?


Re: Error: cannot modify struct arr[0] MyStruct with immutable members

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

On Monday, 11 May 2015 at 13:44:14 UTC, Adam D. Ruppe wrote:

On Monday, 11 May 2015 at 13:37:27 UTC, ref2401 wrote:

Why does it happen?


You'd just be writing to the immutable memory through a 
different name.


Consider if someone took a reference to one of those immutable 
ints, expecting it to never change. Then you wrote a new struct 
over the same location with different values. Then the ints 
pointed to by that reference suddenly change, despite allegedly 
being immutable!


Assigning a struct in-place is the same as assigning all its 
members.


Got it. Thank you.


Delegate type deduction compile error

2015-04-25 Thread ref2401 via Digitalmars-d-learn

struct MyStruct {}

void main(string[] args) {
string str = blah-blah;

auto d1 = (MyStruct) { writeln(delegate-str: , str); };

writeln(typeid(typeof(d1)));
}



dmd: 2067
os: Win8.1
build script: dmd main.d -ofconsole-app.exe -debug -unittest -wi

- if delegate has no params or param is declared as 
int/char/float then the code compiles successfully.

auto d1 = (int) { writeln(delegate-str: , str); };

- if I declare named param as string or MyStruct then the code 
compiles successfully too.

auto d1 = (MyStruct ms)  { writeln(delegate-str: , str); };

- if I declare anonymous parameter as string or MyStruct then the 
error compile occurs:

auto d1 = (MyStruct)  { writeln(delegate-str: , str); };

main.d(21): Error: variable main.main.d1 type void is inferred 
from initializer (MyStruct)


{

writeln(delegate-str: , str);

}

, and variables cannot be of type void
main.d(21): Error: template lambda has no value

Why does it happen?


function ref param vs pointer param

2015-04-24 Thread ref2401 via Digitalmars-d-learn

What advantages do ref params give over pointer params?

struct MyStruct {
string str;

this(string str) { this.str = str; }
}

void processRef(ref MyStruct ms) {
writeln(processRef: , ms);
}

void processPointer(MyStruct* ms) {
writeln(processPointer: , *ms);
}

void main(string[] args) {
	auto ms = MyStruct(the ultimate answer to everythin is the 
number 42);


processRef(ms);
processPointer(ms);
}


Re: function ref param vs pointer param

2015-04-24 Thread ref2401 via Digitalmars-d-learn

Thank you


Re: function ref param vs pointer param

2015-04-24 Thread ref2401 via Digitalmars-d-learn

processPointer(ms);
I think doing this way is more descriptive.
Now all readers know that ms might be changed inside the function.


Re: Fibers and async io stuff for beginners

2015-04-23 Thread ref2401 via Digitalmars-d-learn

Awesome!


Fibers and async io stuff for beginners

2015-04-23 Thread ref2401 via Digitalmars-d-learn

I'm intrested in fibers and async io.
Could anyone suggest articles, books or tutorials about the 
subject?


Thank you


Re: Invalid Floating Point Operation (DMD 2067)

2015-04-16 Thread ref2401 via Digitalmars-d-learn

Builds and runs fine for me. What is your OS and build command?

-Steve


Win 8.1

dmd main.d -ofmain.exe -debug -unittest -wi
if %errorLevel% equ 0 (main.exe)


Invalid Floating Point Operation (DMD 2067)

2015-04-16 Thread ref2401 via Digitalmars-d-learn

Hi Everyone,

After I switched to DMD 2067 my code that previously worked began 
crashing.

If I change the return statement in the matrixOrtho function

from:
return Matrix(...);
to:
Matrix m = Matrix(...);
return m;

then the error won't occur anymore. What is going on?

Thank you.

import std.math;
import std.stdio;

struct Matrix {
float m00, m01, m02, m03;
float m10, m11, m12, m13;
float m20, m21, m22, m23;
float m30, m31, m32, m33;

this(float m00, float m01, float m02, float m03,
 float m10, float m11, float m12, float m13,
 float m20, float m21, float m22, float m23,
		 float m30, float m31, float m32, float m33) nothrow pure @nogc 
{


 this.m00 = m00; this.m01 = m01; this.m02 = m02; this.m03 = m03;
 this.m10 = m10; this.m11 = m11; this.m12 = m12; this.m13 = m13;
 this.m20 = m20; this.m21 = m21; this.m22 = m22; this.m23 = m23;
 this.m30 = m30; this.m31 = m31; this.m32 = m32; this.m33 = m33;
 }
}

void main(string[] args) {

float width = 800f;
float height = 600f;
float near = -5f;
float far = 10f;

float hw = width / 2f;
float hh = height / 2f;

Matrix ortho = matrixOrtho(-hw, hw, -hh, hh, near, far);
}

Matrix matrixOrtho(float left, float right, float bottom, float 
top, float near, float far) /* pure @nogc */ {

debug {
FloatingPointControl fpCtrl;
fpCtrl.enableExceptions(FloatingPointControl.severeExceptions);
}

float doubledNear = near*2f;
float farMinusNear = far - near;
float rightMinusLeft = right - left;
float topMinusBottom = top - bottom;


	return Matrix(2f / rightMinusLeft, 0f, 0f, -(right + 
left)/rightMinusLeft,

0f, 2f / topMinusBottom, 0f, -(top + bottom)/topMinusBottom,
0f, 0f, -2f / farMinusNear, -(far + near)/farMinusNear,
0f, 0f, 0f, 1f);

	//Matrix m = Matrix(2f / rightMinusLeft, 0f, 0f, -(right + 
left)/rightMinusLeft,

//  0f, 2f / topMinusBottom, 0f, -(top + bottom)/topMinusBottom,
//  0f, 0f, -2f / farMinusNear, -(far + near)/farMinusNear,
//  0f, 0f, 0f, 1f);

//return m;
}


Error report:

object.Error@(0): Invalid Floating Point Operation

0x00402340
0x004020E2
0x004029E2
0x004029B7
0x004028CF
0x004022D7
0x758D7C04 in BaseThreadInitThunk
0x77ADB54F in RtlInitializeExceptionChain
0x77ADB51A in RtlInitializeExceptionChain
object.Error@(0): Invalid Floating Point Operation

0x00402340
0x004020E2
0x004029E2
0x004029B7
0x004028CF
0x004022D7
0x758D7C04 in BaseThreadInitThunk
0x77ADB54F in RtlInitializeExceptionChain
0x77ADB51A in RtlInitializeExceptionChain
object.Error@(0): Invalid Floating Point Operation

0x00406E5B
0x004029C5
0x004028CF
0x004022D7
0x758D7C04 in BaseThreadInitThunk
0x77ADB54F in RtlInitializeExceptionChain
0x77ADB51A in RtlInitializeExceptionChain


An input range iteration question

2015-04-08 Thread ref2401 via Digitalmars-d-learn
If Iterator is a struct then Iterator.input won't be adjusted 
properly when the foreach loop ends.

Iterator.input still holds abcde value.
If i mark Iterator as class then Iterator.input will be an empty 
string after the foreach loop.

Could anyone explain me the difference please?
Thank you.


struct Iterator {
string input;

this(string input) {
this.input = input;
}


bool empty() { return input.empty; }

dchar front() { return input.front; }

void popFront() {
if (empty) {
return;
}

input.popFront();
writeln((iterator.popFront), input);
}
}

void main(string[] args) {
Iterator iterator = Iterator(abcde);

foreach (dchar c; iterator) {
writefln(%s, c);
}

writefln((the end): %s, iterator.input);
}


struct variable initialized with void.

2015-03-31 Thread ref2401 via Digitalmars-d-learn

struct MyStruct {
// stuff
}

void main(string[] args) {
MyStruct s1 = void;
}

Could anyone describe me what this initialization does, please?
When do I need to use the void initialization?


Re: struct variable initialized with void.

2015-03-31 Thread ref2401 via Digitalmars-d-learn

Thank you.


final methods by default

2015-03-20 Thread ref2401 via Digitalmars-d-learn

Why aren't methods of class final by default?


Explicit Interface Implementation

2015-02-14 Thread ref2401 via Digitalmars-d-learn

Does D provide a way for explicit interface implementation?
[C#] https://msdn.microsoft.com/en-us/library/ms173157.aspx


Re: spawn/executeInNewThread and module this/~this

2015-01-29 Thread ref2401 via Digitalmars-d-learn

It's written here:
http://dlang.org/module.html#staticorder


Re: static class vs. static struct

2015-01-27 Thread ref2401 via Digitalmars-d-learn
For several times I've met struct(or static struct) usage in 
Phobos for singleton pattern implementation. Unfortunately now i 
can remember only core.runtime.Runtime.
So I've got a question. Why do Phobos guys use struct or static 
struct for or singleton pattern implementation? Why don't use 
static final class for this purpose?


static class vs. static struct

2015-01-26 Thread ref2401 via Digitalmars-d-learn

What's the difference between static class and static struct?
What should i use?


Re: dlang.org redesign n+1

2015-01-22 Thread ref2401 via Digitalmars-d

Can we just get back the old design, please?


Re: redirecting the unittests error output

2015-01-15 Thread ref2401 via Digitalmars-d-learn

Thank you.


redirecting the unittests error output

2015-01-14 Thread ref2401 via Digitalmars-d-learn

How can i redirect the unittests error output to a file?


Re: redirecting the unittests error output

2015-01-14 Thread ref2401 via Digitalmars-d-learn

Unfortunately i'm new to using shells.

I use standard windows cmd. Here is my script:

dmd main.d -debug -unittest -wi

if %errorLevel% equ 0 (
start main.exe
) else (
echo --- Building failed! ---
pause
)

I wrote start main.exe 2 errorFile but it doesn't work. 
errorFile is empty.




Re: core.atomic: atomicFence, atomicLoad, atomicStore

2015-01-12 Thread ref2401 via Digitalmars-d-learn

Thanks for the links.

I have shared class instance. There are two threads which can 
read/write fields of the class. As i understand i can declare 
class as synchronized or i can read/write using 
atomicLoad/atomicStore.

What's the difference between these two approaches?
In what circumstances should i consider synchronized classes or 
using std.atomic?


core.atomic: atomicFence, atomicLoad, atomicStore

2015-01-10 Thread ref2401 via Digitalmars-d-learn
I learned how 'atomicOp' and 'cas' work and why i need them from 
the following sources:

http://ddili.org/ders/d.en/concurrency_shared.html (Ali's book)
http://www.informit.com/articles/article.aspx?p=1609144 (Andrei's 
book)


Can anybody tell me how 'atomicFence', 'atomicLoad' and 
'atomicStore' work and what do i need them for? Unfortunately 
official documentation didn't make it clear for me.


formattedWrite writes nothing

2014-05-02 Thread ref2401 via Digitalmars-d-learn

class MyClass {
Appender!string _stringBuilder;

this() {
_stringBuilder = Appender!string(null);
_stringBuilder.clear();
}

@property string str() {
return _stringBuilder.data;
}

void append(string s) {
formattedWrite(_stringBuilder, %s, s);
}
}

MyClass c = new MyClass();
c.append(text 1);
c.append(__222);

writeln(c.str); //in this case nothing is printed out

Following workarounds work:
1) call _stringBuilder.put() instead of formattedWrite()
2) if _stringBuilder.clear() is omitted in the constructor, 
formattedWrite(...) will work as expected.


Is it a bug or is there a reason for such behaviour?