Re: Cannot make my shared PureMallocator callable in pure functions

2018-02-17 Thread Nordlöw via Digitalmars-d-learn

On Saturday, 17 February 2018 at 14:54:37 UTC, ag0aep6g wrote:
Nordlöw's methods are only weakly pure. They have mutable 
indirections either in the return type or in a parameter type. 
So calls to them should not be optimized away.


I found a solution at

https://github.com/nordlow/phobos-next/blob/master/src/pure_mallocator.d

currently successfully used at

https://github.com/nordlow/phobos-next/blob/master/src/open_hashmap_or_hashset.d

Works for me.

Thanks!


Re: dmd-2.078.2 problems with Ubuntu 17.10 32Bit

2018-02-17 Thread Jordi Sayol via Digitalmars-d-learn
El 17/02/18 a les 18:49, Martin Tschierschke via Digitalmars-d-learn ha escrit:
> But the installation via apt-get is not working without the steps already 
> mentioned in the post before! (s/http/https/  and manually import of the 
> public key)

"d-apt.list" file fixed! (s/http/https/)

d-apt public key is in the "d-apt-keyring" deb package, so you don't have to 
manually install it.

> 
> This (from https://dlang.org/download.html) is outdated for 17.10.
> 
> sudo wget http://master.dl.sourceforge.net/project/d-apt/files/d-apt.list -O 
> /etc/apt/sources.list.d/d-apt.list
> sudo apt-get update && sudo apt-get -y --allow-unauthenticated install 
> --reinstall d-apt-keyring
> sudo apt-get update && sudo apt-get install dmd-compiler dub

It appears that everything should work on 17.10 now. I'll do more tests on a 
virtual machine.




Re: Visual D >> TRACKER : error TRK0004: Failed to locate: "FileTracker32.dll". The system cannot find the file specified.

2018-02-17 Thread Saravana Kumar Arumugam via Digitalmars-d-learn
On Saturday, 17 February 2018 at 20:30:16 UTC, Saravana Kumar 
Arumugam wrote:
...Make sure you also renamed the file "FileTrackerUI.dll" to 
"FileTracker32UI.dll" in the latest LCID folder...


Don't forget to make copy!! That'll bring you even more problems 
while compiling other projects! It worked for me!





Re: Visual D >> TRACKER : error TRK0004: Failed to locate: "FileTracker32.dll". The system cannot find the file specified.

2018-02-17 Thread Saravana Kumar Arumugam via Digitalmars-d-learn

On Friday, 2 February 2018 at 08:56:45 UTC, Markus wrote:
On Tuesday, 21 November 2017 at 04:39:52 UTC, A Guy With a 
Question wrote:
I'm trying to learn D using Visual D in Visual Studio 
Community 2015. Both dmd and ldc give me this error when 
building from Visual Studio. Any ideas? I'm able to build C++ 
projects...


I had to update "Visual Studio 2015 Update 2" to "Visual Studio 
2015 Update 3" to resolve that issue.


Another way is just copy and rename "FileTracker.dll" to 
"FileTracker32.dll" in "%ProgramFiles%\MSBuild\\Bin" 
folder. Make sure you also renamed the file "FileTrackerUI.dll" 
to "FileTracker32UI.dll" in the latest LCID folder (latest 
numbered folder in same location).


But that's the hard fix. Probably MSBuid issue.


Re: Cannot make my shared PureMallocator callable in pure functions

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

On 2/17/18 9:54 AM, ag0aep6g wrote:

On 02/17/2018 03:04 PM, Steven Schveighoffer wrote:
You have to be a bit careful here. pure functions can assume nothing 
is happening and simply not call the function.


That's only a problem when the called function is strongly pure, right?

Nordlöw's methods are only weakly pure. They have mutable indirections 
either in the return type or in a parameter type. So calls to them 
should not be optimized away.


That's fine as long as you aren't going to use the allocator to make any 
immutable or const data ;)


-Steve


Re: confused with data types

2018-02-17 Thread arturg via Digitalmars-d-learn

double[][] skalar_m_2d(double[][] arr, double skalar)
{
import std.algorithm;
// return arr.map(a=> a[] *= skalar).array;
arr.each!((ref a) => a[] *= skalar));
return arr;
}



Re: dmd-2.078.2 problems with Ubuntu 17.10 32Bit

2018-02-17 Thread Martin Tschierschke via Digitalmars-d-learn
On Wednesday, 14 February 2018 at 11:23:48 UTC, Andrea Fontana 
wrote:
On Wednesday, 14 February 2018 at 11:16:25 UTC, Martin 
Tschierschke wrote:

Ok, good to know!
I started with 16.04 and made the initial mistake to take the 
32 Bit version,

do you use 32 or 64 Bit?


64bit of course!

Andrea


After this info, I made the step to change to Ubuntu 17.10 64 Bit.
And - it works!

But the installation via apt-get is not working without the steps 
already mentioned in the post before! (s/http/https/  and 
manually import of the public key)


This (from https://dlang.org/download.html) is outdated for 17.10.

sudo wget 
http://master.dl.sourceforge.net/project/d-apt/files/d-apt.list 
-O /etc/apt/sources.list.d/d-apt.list
sudo apt-get update && sudo apt-get -y --allow-unauthenticated 
install --reinstall d-apt-keyring

sudo apt-get update && sudo apt-get install dmd-compiler dub




Re: confused with data types

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

On Saturday, 17 February 2018 at 16:12:48 UTC, thorstein wrote:

public double[][] skalar_m_2d(double[][] array, double skalar)
{
  return array.map!(b => b[].map!(c => c * skalar));
}


It'd probably be better to just do that in-place...

foreach(row; array)
  row[] *= skalar;
return array;

Note that'd overwrite the existing data though. But the compiler 
could more aggressively optimize that than the individual maps.



How can I get the result as double[][] ???



But if you do need the double[][] type exactly as well as a new 
copy instead of editing the one you have, you can:


static import std.array;
return std.array.array(array.map!(b => std.array.array(b[].map!(c 
=> c * skalar;



The std.array.array function copies the return value of functions 
like `map` into a new array. It is called twice here because 
double[][] is an array of arrays.


(the word "array" is used way too much there lol)


The reason map doesn't do this automatically btw is because 
copying the arrays can be somewhat expensive, so it doesn't force 
you to do work you don't often need.


Re: confused with data types

2018-02-17 Thread JN via Digitalmars-d-learn

On Saturday, 17 February 2018 at 16:12:48 UTC, thorstein wrote:

Hello,

This was my goal:
-
public double[][] skalar_m_2d(double[][] array, double skalar)
{
  return array.map!(b => b[].map!(c => c * skalar));
}

!!! But: return value is not double!

Type check for return value:

a = array.map!(b => b[].map!(c => c * skalar))
writeln(typeof(a).stringof); //-> MapResult!("__lambda4, 
double[][])


a = array.map!(b => b[].map!(c => c * skalar))[1];
writeln(typeof(a).stringof); //-> MapResult!("__lambda2, 
double[])


How can I get the result as double[][] ???

Thanks, thorstein


I'm no expert, but importing std.array and doing a.array() should 
work.


confused with data types

2018-02-17 Thread thorstein via Digitalmars-d-learn

Hello,

This was my goal:
-
public double[][] skalar_m_2d(double[][] array, double skalar)
{
  return array.map!(b => b[].map!(c => c * skalar));
}

!!! But: return value is not double!

Type check for return value:

a = array.map!(b => b[].map!(c => c * skalar))
writeln(typeof(a).stringof); //-> MapResult!("__lambda4, 
double[][])


a = array.map!(b => b[].map!(c => c * skalar))[1];
writeln(typeof(a).stringof); //-> MapResult!("__lambda2, double[])

How can I get the result as double[][] ???

Thanks, thorstein


Re: Cannot make my shared PureMallocator callable in pure functions

2018-02-17 Thread Eduard Staniloiu via Digitalmars-d-learn

On Saturday, 17 February 2018 at 12:33:25 UTC, Nordlöw wrote:

I'm struggling with making

https://github.com/nordlow/phobos-next/blob/master/src/pure_mallocator.d

callable in pure functions such as here

https://github.com/nordlow/phobos-next/blob/master/src/pure_mallocator.d#L84

Shouldn't a shared

static shared PureMallocator instance;

make it possible to call

PureMallocator.instance.allocate(16);

in pure functions?


As the folks before me have pointed out, the language doesn't 
allow you to use globals inside pure code, excepting global 
immutables; this makes sense as once an immutable object was 
constructed it will never change.


As Steven pointed out, we are just trying to fool the compiler 
into thinking that allocators don't have side effects; in the 
case of Mallocator, we are just forwarding calls to libc's 
mallocator.


With this in mind, it looks to me that you just need to decide 
what is the best/easiest way for you to forward the calls. You 
could:
  1) make all you methods static (after all, the allocator is 
stateless)

  2) make `instance` immutable and make all the methods const



Re: Cannot make my shared PureMallocator callable in pure functions

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

On 02/17/2018 03:04 PM, Steven Schveighoffer wrote:
You have to be a bit careful here. pure functions can assume nothing is 
happening and simply not call the function.


That's only a problem when the called function is strongly pure, right?

Nordlöw's methods are only weakly pure. They have mutable indirections 
either in the return type or in a parameter type. So calls to them 
should not be optimized away.


Re: Cannot make my shared PureMallocator callable in pure functions

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

On 2/17/18 8:32 AM, ag0aep6g wrote:

On 02/17/2018 01:35 PM, rikki cattermole wrote:

pure means no globals. As in none :)


... except immutable ones. And since PureMallocator has no fields, 
`instance` can be made immutable, and all the methods can be made static 
or const. Then they can be used in `pure` code.


You have to be a bit careful here. pure functions can assume nothing is 
happening and simply not call the function.


-Steve


Re: Return value in BetterC mode.

2018-02-17 Thread meppl via Digitalmars-d-learn

On Saturday, 17 February 2018 at 07:58:40 UTC, ANtlord wrote:

Hello!
Yesterday I found an interesting issue for myself while I was 
implementing unique pointer for my project in BetterC. When I 
was trying to return new instance from a `move` method I got 
calling of destructor the instance. When the instance is out of 
scope the calling is happens again. I also see that addresses 
of an instance that calls destructor are same.


That thing doesn't happen when I don't use BetterC mode. Is 
that bug or feature?
Please checkout code https://run.dlang.io/is/m1TRnT and try it 
in BetterC mode and in usual mode.


But if I return result of a constructor directly instead of 
saving the result to variable and returning the variable from 
the `move` method I don't see double calling of the same 
destructor.


I. e.
```
auto newObject = Box(this);
return newObject;
```
is replaced by
```
return Box(this);
```

So... is that bug or feature?


Okay, with the glorious help of the compiler-switch `-vcg-ast` I 
was able to see the source of that weirdness. See also: 
https://forum.dlang.org/thread/juxihybpqpjycmxiy...@forum.dlang.org


It seems that there is always a try-block when the struct has a 
destructor


I reduced your code to:



struct S {
~this() {}
}
S myFunction() {
S s = S();
return s;
}
extern( C) void main(){}




transformation of myFunction() with

$ dmd -betterC -vcg-ast source/app.d

S myFunction()
{
S s = S();
try
{
return s;
}
finally
s.~this();
}


transformation of myFunction() with

$ dmd -vcg-ast source/app.d

S myFunction()
{
S s = S();
try
return s;
catch(Throwable __o3)
{
s.~this();
throw __o3;
}
}



sadly I have no good idea how to name the title of that issue :/


Re: Cannot make my shared PureMallocator callable in pure functions

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

On 2/17/18 7:33 AM, Nordlöw wrote:

I'm struggling with making

https://github.com/nordlow/phobos-next/blob/master/src/pure_mallocator.d

callable in pure functions such as here

https://github.com/nordlow/phobos-next/blob/master/src/pure_mallocator.d#L84 



Shouldn't a shared

     static shared PureMallocator instance;

make it possible to call

     PureMallocator.instance.allocate(16);

in pure functions?


Pure functions cannot access shared or thread-local data. They are not 
supposed to have any side effects.


Keep in mind, allocators have side effects, we just pretend they don't. 
You need to fool the compiler into thinking you aren't doing anything to 
global data.


The design of allocators makes this difficult. I suggested at one point 
in the past that such allocators make all functions static, which solves 
other problems. Oh, I even made a PR: 
https://github.com/dlang/phobos/pull/4288


But it wasn't to allow purity, it was to allow storage of an "instance" 
anywhere.


-Steve


Re: Cannot make my shared PureMallocator callable in pure functions

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

On 02/17/2018 01:35 PM, rikki cattermole wrote:

pure means no globals. As in none :)


... except immutable ones. And since PureMallocator has no fields, 
`instance` can be made immutable, and all the methods can be made static 
or const. Then they can be used in `pure` code.


Re: Faking a non-pure function as pure

2018-02-17 Thread Nordlöw via Digitalmars-d-learn

On Friday, 16 February 2018 at 18:03:40 UTC, Ali Çehreli wrote:

auto pureF = assumePure();
pureF(42);

Ali


Thanks!


Re: Cannot make my shared PureMallocator callable in pure functions

2018-02-17 Thread Nordlöw via Digitalmars-d-learn
On Saturday, 17 February 2018 at 12:35:00 UTC, rikki cattermole 
wrote:

in pure functions?


pure means no globals. As in none :)


I guess one solution is to make the member functions in 
PureMallocator static and change how the template argument 
`Allocator` for a container is used to call these member 
functions directly instead of via `instance`, right?


Re: Cannot make my shared PureMallocator callable in pure functions

2018-02-17 Thread rikki cattermole via Digitalmars-d-learn

On 17/02/2018 12:48 PM, Nordlöw wrote:

On Saturday, 17 February 2018 at 12:35:00 UTC, rikki cattermole wrote:

in pure functions?


pure means no globals. As in none :)


I don't understand.

I thought std.experimental.allocators API was designed to be able 
express these needs, @andralex?


Library code cannot change the language.

pure functions cannot access globals period, it does not matter what you 
write. Its a hard limit. You simply don't want pure here.


Re: Cannot make my shared PureMallocator callable in pure functions

2018-02-17 Thread Nordlöw via Digitalmars-d-learn
On Saturday, 17 February 2018 at 12:35:00 UTC, rikki cattermole 
wrote:

in pure functions?


pure means no globals. As in none :)


I don't understand.

I thought std.experimental.allocators API was designed to be able 
express these needs, @andralex?


Cannot make my shared PureMallocator callable in pure functions

2018-02-17 Thread Nordlöw via Digitalmars-d-learn

I'm struggling with making

https://github.com/nordlow/phobos-next/blob/master/src/pure_mallocator.d

callable in pure functions such as here

https://github.com/nordlow/phobos-next/blob/master/src/pure_mallocator.d#L84

Shouldn't a shared

static shared PureMallocator instance;

make it possible to call

PureMallocator.instance.allocate(16);

in pure functions?


Re: Cannot make my shared PureMallocator callable in pure functions

2018-02-17 Thread Nordlöw via Digitalmars-d-learn

On Saturday, 17 February 2018 at 12:33:25 UTC, Nordlöw wrote:

PureMallocator.instance.allocate(16);


currently errors as

pure_mallocator.d(84,16): Error: pure function 
'pure_mallocator.__unittest_pure_mallocator_82_0' cannot access 
mutable static data 'instance'


Re: Cannot make my shared PureMallocator callable in pure functions

2018-02-17 Thread rikki cattermole via Digitalmars-d-learn

On 17/02/2018 12:33 PM, Nordlöw wrote:

I'm struggling with making

https://github.com/nordlow/phobos-next/blob/master/src/pure_mallocator.d

callable in pure functions such as here

https://github.com/nordlow/phobos-next/blob/master/src/pure_mallocator.d#L84 



Shouldn't a shared

     static shared PureMallocator instance;

make it possible to call

     PureMallocator.instance.allocate(16);

in pure functions?


pure means no globals. As in none :)


Return value in BetterC mode.

2018-02-17 Thread ANtlord via Digitalmars-d-learn

Hello!
Yesterday I found an interesting issue for myself while I was 
implementing unique pointer for my project in BetterC. When I was 
trying to return new instance from a `move` method I got calling 
of destructor the instance. When the instance is out of scope the 
calling is happens again. I also see that addresses of an 
instance that calls destructor are same.


That thing doesn't happen when I don't use BetterC mode. Is that 
bug or feature?
Please checkout code https://run.dlang.io/is/m1TRnT and try it in 
BetterC mode and in usual mode.


But if I return result of a constructor directly instead of 
saving the result to variable and returning the variable from the 
`move` method I don't see double calling of the same destructor.


I. e.
```
auto newObject = Box(this);
return newObject;
```
is replaced by
```
return Box(this);
```

So... is that bug or feature?