Re: Running GtkD programs on macOS

2019-11-29 Thread Mike Wey via Digitalmars-d-learn

On 29-11-2019 04:40, Joel wrote:
Oh, I used 'brew install gtk+3', and the test program worked, but (see 
below) I don't know about all that installing - is that alright?


They all look like GTK+ dependencies so that would be alright/

--
Mike Wey


Re: Template mixin / unresolved external / scope problem?

2019-11-29 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-11-28 16:36:36 +, Jacob Carlborg said:

Are you using the latest version, 2.089.0? It might be fixed in that 
version [1].


[1] https://dlang.org/changelog/2.089.0.html#mixin_template_mangling


Ha! Thanks Jacob, that looks like the root-cause. Didn't expect to use 
a feature which was just fixe in the newest compiler release...


Using it now, but 2.089 broke some code using CAS... need to take a 
look into it first before I can tell if it works with the template 
mixin.


Thanks.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Map, filter and pure functions

2019-11-29 Thread Paul Backus via Digitalmars-d-learn

On Friday, 29 November 2019 at 15:54:13 UTC, realhet wrote:

On Friday, 29 November 2019 at 15:49:24 UTC, Paul Backus wrote:
It's actually a much simpler reason: filter calls .front twice 
for each element in its input (once to check if the value 
satisfies the predicate, and then again to return the value if 
it does), and the range returned by map doesn't save the value 
of .front between calls, so it has to re-compute it each time 
by calling the transform function.


This makes it clear.

In my case a cache which can access all the previous elements 
would be a too big thing, so I will do the filtering in a later 
stage manually. But most importantly, now I know what's going 
on, Thank You!


The "cache" wrapper only caches one element at a time. The cached 
value is discarded after each call to .popFront.


Re: Map, filter and pure functions

2019-11-29 Thread realhet via Digitalmars-d-learn

On Friday, 29 November 2019 at 15:49:24 UTC, Paul Backus wrote:
It's actually a much simpler reason: filter calls .front twice 
for each element in its input (once to check if the value 
satisfies the predicate, and then again to return the value if 
it does), and the range returned by map doesn't save the value 
of .front between calls, so it has to re-compute it each time 
by calling the transform function.


This makes it clear.

In my case a cache which can access all the previous elements 
would be a too big thing, so I will do the filtering in a later 
stage manually. But most importantly, now I know what's going on, 
Thank You!


Re: Map, filter and pure functions

2019-11-29 Thread realhet via Digitalmars-d-learn

On Friday, 29 November 2019 at 15:30:22 UTC, realhet wrote:

...


Unfortunately function purity is not the answer.

I put a very long calculation into the transform function which 
is called from "map!".

And the "filter!" is making the "map!" call my function 2 times:
First for the "filter!" to decide it allows the element or not.
And second when the map! is passing it to the foreach() where I 
write the elements out.


Is there a solution for this performance issue?

Using functional programming, my program looks beautiful. But I 
need it to be optimal too.


//To be easier to understand, I want to make the following:
foreach(a; input){
  auto temp = slowFunction(a);
  if(check(temp))
writeln(temp);
}

//But the elegant functional form ->
input.map!slowFunction.filter!(a => check(a)).each!writeln;

//Produces the following unoptimal solution:
foreach(a; input){
  if(check(slowFunction(a)))
writeln(slowFunction(a));
}

Is there a functional way to fix this?

Thank you in advance!





Re: Map, filter and pure functions

2019-11-29 Thread Paul Backus via Digitalmars-d-learn

On Friday, 29 November 2019 at 15:30:22 UTC, realhet wrote:

Hi,

I have an input range.
I use the map! on it to transform using a function.
Finally I use filter! on the transformed data.

When I do a foreach on this, i noticed, that the transform 
function is called twice for each element.
If I remove the filter! it does only one transform function 
call per element.


Is this because the function is NOT PURE, so Phobos thinks that 
the function can give different results for the same input?


If I modify the function to be pure, will the transform 
function be called only once?


It's actually a much simpler reason: filter calls .front twice 
for each element in its input (once to check if the value 
satisfies the predicate, and then again to return the value if it 
does), and the range returned by map doesn't save the value of 
.front between calls, so it has to re-compute it each time by 
calling the transform function.


You can work around this using std.algorithm.iteration.cache, a 
range wrapper that calls .front on the underlying range exactly 
once, and then saves the value and reuses it for subsequent calls:


myRange
.map!transform
.cache
.filter!pred
.each!doSomething;


Re: optional process

2019-11-29 Thread Taylor R Hillegeist via Digitalmars-d-learn

On Friday, 29 November 2019 at 15:24:31 UTC, Paul Backus wrote:
On Friday, 29 November 2019 at 15:17:35 UTC, Taylor R 
Hillegeist wrote:

I know phobos has choose which is close.
But what I want is something like:

bool sortOutput;

if(sortOutput){
read(Textfile)
   .splitter("\n")
   .filter(a=>a.contains("data))
   .doif(sortOutput,sort!("a < b"))
   .writeln();


import std.functional: pipe;

bool sortOutput;

read(Textfile)
   .splitter("\n")
   .filter!(a=>a.contains("data))
   .pipe!((output) {
  if (sortOutput)
 return output.sort!("a < b");
  else
 return output;
   })
   .writeln(); // maybe you meant each!writeln ?


That is actually exactly the kind of thing I was looking for. (it 
gets the job done without repeats) I would still like it to be in 
the first form though e.g. doif. it would keep the code cleaner.
Thank you for this.  (also yes I just made up the example so 
.each!writeln is appropriate it would be surprising to me if that 
was the only error)




Map, filter and pure functions

2019-11-29 Thread realhet via Digitalmars-d-learn

Hi,

I have an input range.
I use the map! on it to transform using a function.
Finally I use filter! on the transformed data.

When I do a foreach on this, i noticed, that the transform 
function is called twice for each element.
If I remove the filter! it does only one transform function call 
per element.


Is this because the function is NOT PURE, so Phobos thinks that 
the function can give different results for the same input?


If I modify the function to be pure, will the transform function 
be called only once?


Re: optional process

2019-11-29 Thread Paul Backus via Digitalmars-d-learn
On Friday, 29 November 2019 at 15:17:35 UTC, Taylor R Hillegeist 
wrote:

I know phobos has choose which is close.
But what I want is something like:

bool sortOutput;

if(sortOutput){
read(Textfile)
   .splitter("\n")
   .filter(a=>a.contains("data))
   .doif(sortOutput,sort!("a < b"))
   .writeln();


import std.functional: pipe;

bool sortOutput;

read(Textfile)
   .splitter("\n")
   .filter!(a=>a.contains("data))
   .pipe!((output) {
  if (sortOutput)
 return output.sort!("a < b");
  else
 return output;
   })
   .writeln(); // maybe you meant each!writeln ?


optional process

2019-11-29 Thread Taylor R Hillegeist via Digitalmars-d-learn
When using the standard library. and making command-line 
applications I find myself wanting optional processes in line. 
for me, this typically makes the following structure.


bool sortOutput;

if(sortOutput){
read(Textfile)
   .splitter("\n")
   .filter(a=>a.contains("data))
   .sort!("a < b").writeln();

}else{

read(Textfile)
   .splitter("\n")
   .filter(a=>a.contains("data))
   .writeln();
}

I know phobos has choose which is close.
But what I want is something like:

bool sortOutput;

if(sortOutput){
read(Textfile)
   .splitter("\n")
   .filter(a=>a.contains("data))
   .doif(sortOutput,sort!("a < b"))
   .writeln();


Re: Leak-detection of references to scoped class instances

2019-11-29 Thread IGotD- via Digitalmars-d-learn

On Thursday, 28 November 2019 at 21:49:09 UTC, Per


Also, what happens if `C` doesn't fit on the stack?


This is OS specific I think. For example on Linux at the end of 
the stack there is a guard page and when you hit it the process 
will segfault.





Re: Running GtkD programs on macOS

2019-11-29 Thread Joel via Digitalmars-d-learn

On Friday, 29 November 2019 at 08:22:09 UTC, Joel wrote:
I've used dub alright, but don't know how to install the dylib 
files:


object.Exception@../../../../.dub/packages/gtk-d-3.9.0/gtk-d/generated/gtkd/gtkd/Loader.d(125):
 Library load failed (libatk-1.0.0.dylib): dlopen(libatk-1.0.0.dylib, 258): 
image not found

What's a good way to fix this problem?


Oh, I used 'brew install gtk+3', and the test program worked, but 
(see below) I don't know about all that installing - is that 
alright?


Joel-Computer:GtkD joelchristensen$ brew install gtk+3
==> Installing dependencies for gtk+3: gettext, gdbm, 
openssl@1.1, readline, sqlite, xz, python, glib, atk, libtiff, 
gdk-pixbuf, gsettings-desktop-schemas, hicolor-icon-theme, 
libepoxy, fontconfig, lzo, pixman, cairo, fribidi, graphite2, 
icu4c, harfbuzz and pango

==> Installing gtk+3 dependency: gettext
==> Downloading 
https://homebrew.bintray.com/bottles/gettext-0.20.1.catalina.bottle.tar.gz
==> Downloading from 
https://akamai.bintray.com/10/107d7f386fbeea6979f9376cdbbcf3f60943caaad61bdc754d3019ce625dffe6?__gda__=exp=1575016927~hmac=1f2f6b107535855972ea31d612cdd1bcb0b29049b0c57abc49893f176a5cd205&response-content-di

 100.0%
==> Pouring gettext-0.20.1.catalina.bottle.tar.gz
==> Caveats
gettext is keg-only, which means it was not symlinked into 
/usr/local,
because macOS provides the BSD gettext library & some software 
gets confused if both are in the library path.


If you need to have gettext first in your PATH run:
  echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> 
~/.zshrc


For compilers to find gettext you may need to set:
  export LDFLAGS="-L/usr/local/opt/gettext/lib"
  export CPPFLAGS="-I/usr/local/opt/gettext/include"

==> Summary
🍺  /usr/local/Cellar/gettext/0.20.1: 1,893 files, 18.4MB
==> Installing gtk+3 dependency: gdbm
==> Downloading 
https://homebrew.bintray.com/bottles/gdbm-1.18.1.catalina.bottle.1.tar.gz

 100.0%
==> Pouring gdbm-1.18.1.catalina.bottle.1.tar.gz
🍺  /usr/local/Cellar/gdbm/1.18.1: 20 files, 602.8KB
==> Installing gtk+3 dependency: openssl@1.1
==> Downloading 
https://homebrew.bintray.com/bottles/open...@1.1-1.1.1d.catalina.bottle.tar.gz
==> Downloading from 
https://akamai.bintray.com/d7/d7f992ebfd78f80828051f6dc6a1a99aed405f86b0f39ea651fd0afeadd1b0f4?__gda__=exp=1575016937~hmac=5f2ce786f74315c4cdd29cf182505c91b4674ea63dcbd3582441367ea9f101ad&response-content-di

 100.0%
==> Pouring open...@1.1-1.1.1d.catalina.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs

and run
  /usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into 
/usr/local,
because openssl/libressl is provided by macOS so don't link an 
incompatible version.


If you need to have openssl@1.1 first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> 
~/.zshrc


For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
  export 
PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"


==> Summary
🍺  /usr/local/Cellar/openssl@1.1/1.1.1d: 7,983 files, 17.9MB
==> Installing gtk+3 dependency: readline
==> Downloading 
https://homebrew.bintray.com/bottles/readline-8.0.1.catalina.bottle.tar.gz
==> Downloading from 
https://akamai.bintray.com/ab/ab3c966f4cae7d0f3ecc5688bb989820c3261f5ed547a08c84186ba7f53bdd9c?__gda__=exp=1575016950~hmac=ad277b652e65c3cb8d94e94d22db1d3f5c7f563b2bf9b1d1fb745c9318673a32&response-content-di

 100.0%
==> Pouring readline-8.0.1.catalina.bottle.tar.gz
==> Caveats
readline is keg-only, which means it was not symlinked into 
/usr/local,
because macOS provides the BSD libedit library, which shadows 
libreadline.
In order to prevent conflicts when programs look for libreadline 
we are

defaulting this GNU Readline installation to keg-only.

For compilers to find readline you may need to set:
  export LDFLAGS="-L/usr/local/opt/readline/lib"
  export CPPFLAGS="-I/usr/local/opt/readline/include"

For pkg-config to find readline you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig"

==> Summary
🍺  /usr/local/Cellar/readline/8.0.1: 48 files, 1.5MB
==> Installing gtk+3 dependency: sqlite
==> Downloading 
https://homebrew.bintray.com/bottles/sqlite-3.30.1.catalina.bottle.tar.gz
==> Downloading from 
https://akamai.bintray.com/38/38c39121f7634ec563bb201b483f66cf567dfe61e02624ffb06f620f11158ab1?__gda__=exp=1575016952~hmac=397e8214ce6d53e8e7ccb6d939004d

Running GtkD programs on macOS

2019-11-29 Thread Joel via Digitalmars-d-learn
I've used dub alright, but don't know how to install the dylib 
files:


object.Exception@../../../../.dub/packages/gtk-d-3.9.0/gtk-d/generated/gtkd/gtkd/Loader.d(125):
 Library load failed (libatk-1.0.0.dylib): dlopen(libatk-1.0.0.dylib, 258): 
image not found

What's a good way to fix this problem?