Re: Functional Programming in D

2019-10-09 Thread SrMordred via Digitalmars-d-learn

https://garden.dlang.io/


Re: Functional Programming in D

2019-10-09 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 09, 2019 at 05:41:02PM +, Jonathan Gerlach via 
Digitalmars-d-learn wrote:
> On Wednesday, 9 October 2019 at 14:26:53 UTC, NonNull wrote:
> > Hello,
> > I want to become fluent in the use of functional programming
> > techniques in D (as well as the use of ranges) using std.functional
> > (and std.algorithm and whatever else is relevant). Is there anything
> > out there that isn't just module documentation that covers the full
> > scope of this?
> 
> I had this same feeling about wanting to learn `std.functional` a bit
> more, so I decided to do https://adventofcode.com/ with additional
> constraints that the code would be functional D with as many unit
> tests as I could manage.  I learned a bunch and had a lot of fun with
> it.

Actually, std.functional is somewhat of a misnomer. It mostly deals with
higher-order functions, i.e., functions that return functions, currying,
that sort of thing.  These are part of functional programming, but
there's more to functional programming than that.  I'd say std.range and
std.algorithm are another major part of functional-style programming
support in D, along with the purity system.

Here are some resources that might help get you started:

https://klickverbot.at/blog/2012/05/purity-in-d/
https://tour.dlang.org/tour/en/basics/ranges
http://ddili.org/ders/d.en/ranges.html
http://dconf.org/2015/talks/davis.html
http://www.informit.com/articles/printerfriendly.aspx?p=1407357=1
http://wiki.dlang.org/Component_programming_with_ranges


T

-- 
What did the alien say to Schubert? "Take me to your lieder."


Re: Functional Programming in D

2019-10-09 Thread Jonathan Gerlach via Digitalmars-d-learn

On Wednesday, 9 October 2019 at 14:26:53 UTC, NonNull wrote:

Hello,
I want to become fluent in the use of functional programming 
techniques in D (as well as the use of ranges) using 
std.functional (and std.algorithm and whatever else is 
relevant). Is there anything out there that isn't just module 
documentation that covers the full scope of this?


I had this same feeling about wanting to learn `std.functional` a 
bit more, so I decided to do https://adventofcode.com/ with 
additional constraints that the code would be functional D with 
as many unit tests as I could manage.  I learned a bunch and had 
a lot of fun with it.


Re: ld errors in osx Catalina

2019-10-09 Thread Paolo Invernizzi via Digitalmars-d-learn
On Wednesday, 9 October 2019 at 16:08:41 UTC, rikki cattermole 
wrote:

On 09/10/2019 11:33 PM, David Briant wrote:

[...]


D as a native language links against libc, so using the system 
c compiler as the linker is a viable method to prevent having 
to look things up.


Perhaps try ldc? That uses LLVM so may be better on OSX.

Related: https://issues.dlang.org/show_bug.cgi?id=20019

Also those versions on homebrew look to be at least one version 
out of date.


If ldc on homebrew doesn't work, you should try the versions on 
the main site (which has dmg's) https://dlang.org/download.html


I confirm that ldc-1.18.0-beta2 works fine on mine Catalina, 
downloaded and activated with the official install script.


/Paolo


Re: ld errors in osx Catalina

2019-10-09 Thread rikki cattermole via Digitalmars-d-learn

On 09/10/2019 11:33 PM, David Briant wrote:
I've accidentally upgraded to Catalina - a little earlier than planned 
as I had hoped not to be trail blazing!


My problem is this, in a bash shell and a new directory when I run

$ dub init
... answering the questions that dub asks
$ dub

dmd compiles the skeleton project but ld fails (full dump below).

I've tried uninstalling dub, dmd (via homebrew) and reinstalling (had to 
use the latest beta) and upgrading xcode and also upgrading to Catalina.


I'm a d newbie and this is my first escapade into compiling on the mac.

Has anyone an idea how to fix this?


D as a native language links against libc, so using the system c 
compiler as the linker is a viable method to prevent having to look 
things up.


Perhaps try ldc? That uses LLVM so may be better on OSX.

Related: https://issues.dlang.org/show_bug.cgi?id=20019

Also those versions on homebrew look to be at least one version out of date.

If ldc on homebrew doesn't work, you should try the versions on the main 
site (which has dmg's) https://dlang.org/download.html


Re: ld errors in osx Catalina

2019-10-09 Thread David Briant via Digitalmars-d-learn

On Wednesday, 9 October 2019 at 15:42:42 UTC, David Briant wrote:
On Wednesday, 9 October 2019 at 10:33:21 UTC, David Briant 
wrote:

[...]



If I uninstall clang using conda I now get:

(base) Davids-MacBook:fred david$ dub
Performing "debug" build using /Library/D/dmd/bin/dmd for 
x86_64.

fred ~master: building configuration "application"...
Linking...
x86_64-apple-darwin13.4.0-clang: No such file or directory
core.thread.ThreadError@src/core/thread.d(3093): Unable to load 
thread state


Error: linker exited with status 255
/Library/D/dmd/bin/dmd failed with exit code 1.


It seems like dub has somehow gotten entwined with the anaconda 
compiler - any ideas how to fix?


FYI Solution was to use anaconda-clean to remove anaconda 
completely, then uninstall dmd using homebrew then reinstall the 
beta version.


Re: ld errors in osx Catalina

2019-10-09 Thread David Briant via Digitalmars-d-learn

On Wednesday, 9 October 2019 at 10:33:21 UTC, David Briant wrote:
I've accidentally upgraded to Catalina - a little earlier than 
planned as I had hoped not to be trail blazing!


My problem is this, in a bash shell and a new directory when I 
run


$ dub init
... answering the questions that dub asks
$ dub

dmd compiles the skeleton project but ld fails (full dump 
below).


I've tried uninstalling dub, dmd (via homebrew) and 
reinstalling (had to use the latest beta) and upgrading xcode 
and also upgrading to Catalina.


I'm a d newbie and this is my first escapade into compiling on 
the mac.


Has anyone an idea how to fix this?



If I uninstall clang using conda I now get:

(base) Davids-MacBook:fred david$ dub
Performing "debug" build using /Library/D/dmd/bin/dmd for x86_64.
fred ~master: building configuration "application"...
Linking...
x86_64-apple-darwin13.4.0-clang: No such file or directory
core.thread.ThreadError@src/core/thread.d(3093): Unable to load 
thread state


Error: linker exited with status 255
/Library/D/dmd/bin/dmd failed with exit code 1.


It seems like dub has somehow gotten entwined with the anaconda 
compiler - any ideas how to fix?


Functional Programming in D

2019-10-09 Thread NonNull via Digitalmars-d-learn

Hello,
I want to become fluent in the use of functional programming 
techniques in D (as well as the use of ranges) using 
std.functional (and std.algorithm and whatever else is relevant). 
Is there anything out there that isn't just module documentation 
that covers the full scope of this?




Re: Blog Post #77: Notebook, Part I

2019-10-09 Thread GreatSam4sure via Digitalmars-d-learn

On Wednesday, 9 October 2019 at 09:44:39 UTC, Ron Tarrant wrote:
On Wednesday, 9 October 2019 at 03:13:48 UTC, GreatSam4sure 
wrote:



Good works


Thanks, GreatSam4sure.

Is there any way to detect the size of my screen using gtkd? 
So that incan calculate the size of my screen and center my 
window on the screen using move(x, y).


I had a quick look into this and there is no straightforward 
solution, so I can't give you an immediate answer. It would be 
easier to explain with a demo, so I'll need some time to work 
one up. I've put it on my to-do list.


Besides can you convert all your posts to a pdf that is easily 
downloadable for those with little internet access?


I've been thinking about an ebook based on the blog, something 
that would start with installing a development environment, go 
into how to organize and write each part of an application, and 
end with how to distribute the finished product. It's in very 
early stages ATM, but I'm open to any suggestions you (or 
anyone else) may have for how to make it as useful as possible.



Thanks, it will be better to use coded. It is very easy to stand 
a gtkd project in coded and vs code.



All dependency taking care of. Dub will download the dependency 
for if you are connected to the internet


Have DUB sub packages inherit settings

2019-10-09 Thread Dennis via Digitalmars-d-learn
I want to split my package into sub packages for faster 
compilation, but I have some custom settings that I don't want to 
copy-paste 10 times since that makes editing them really 
annoying. Is there a way to inherit the settings from the 
main-package, or avoid repetition in another way?


I found this 2 years old post:
https://forum.dlang.org/post/wdkrsfjfbtnmpxcgu...@forum.dlang.org
It is mentioned that when using --combined the flags are 
inherited, but I also want to inherit the settings when not using 
that flag.


The settings in question are:
```
dflags "-dip1000" "-dip25"

buildType "debug" {
buildOptions "debugMode" "debugInfo"
buildOptions "betterC"
buildRequirements "allowWarnings"
}

buildType "release" {
buildOptions "releaseMode" "optimize" "inline"
buildOptions "betterC"
}

buildType "unittest" {
buildOptions "unittests" "debugMode" "debugInfo"
dflags "-checkaction=context"
buildRequirements "allowWarnings"
}
```



Re: formatting a float or double in a string with all significant digits kept

2019-10-09 Thread David Briant via Digitalmars-d-learn

On Tuesday, 8 October 2019 at 20:37:03 UTC, dan wrote:
I have a double precision number that i would like to print all 
significant digits of, but no more than what are actually 
present in the number.  Or more exactly, i want to print the 
minimum number of digits necessary to recover the original 
number to within 2 or 3 least significant bits in the stored, 
in-core, version of its bit pattern.


For example,


import std.string;
import std.stdio;
import std.math;

void main( ) {
  auto t = format("%3.30f", PI );
  writeln("Value of PI is: ", PI, " or, : ", t);
}

The default way writeln prints is 5 digits to the right of the 
decimal point.


I can format to print with any number of digits, such as 30 
above, but that's too many.


For pi, the correct number of digits to print looks to be about 
18 (and the extra 12 digits presumably are from the decimal 
expansion of the least significant bit?).


But i would like to be able to do this without knowing the 
expansion of pi, or writing too much code, especially if 
there's some d function like writeAllDigits or something 
similar.


Thanks in advance for any pointers!

dan


Hi Dan,

What's your usecase here, e.g. a csv/json reader / writer? You 
say it's for double precision numbers (64bit format) then provide 
an example for reals (80bit format). So I'm not certain your goal.


If you google "what every developer should know about doubles" 
you'll hit a number of useful articles that explain the common 
issues of floating point representation in detail.


-- David


ld errors in osx Catalina

2019-10-09 Thread David Briant via Digitalmars-d-learn
I've accidentally upgraded to Catalina - a little earlier than 
planned as I had hoped not to be trail blazing!


My problem is this, in a bash shell and a new directory when I run

$ dub init
... answering the questions that dub asks
$ dub

dmd compiles the skeleton project but ld fails (full dump below).

I've tried uninstalling dub, dmd (via homebrew) and reinstalling 
(had to use the latest beta) and upgrading xcode and also 
upgrading to Catalina.


I'm a d newbie and this is my first escapade into compiling on 
the mac.


Has anyone an idea how to fix this?



(base) Davids-MacBook:fred david$ dub
Performing "debug" build using /Library/D/dmd/bin/dmd for x86_64.
fred ~master: building configuration "application"...
Linking...
ld: warning: ignoring file 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libpthread.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libpthread.tbd
ld: warning: ignoring file 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libm.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libm.tbd
ld: warning: ignoring file 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd

Undefined symbols for architecture x86_64:
  "__NSGetMachExecuteHeader", referenced from:
  
__D2rt9backtrace5dwarf23traceHandlerOpApplyImplFxAPvMDFKmKxAaZiZi 
in libphobos2.a(dwarf_9d0_924.o)

  "__Unwind_DeleteException", referenced from:
  ___dmd_personality_v0 in libphobos2.a(dwarfeh_892_811.o)
  ___dmd_begin_catch in libphobos2.a(dwarfeh_88f_6b9.o)
  "__Unwind_GetIP", referenced from:
  ___dmd_personality_v0 in libphobos2.a(dwarfeh_892_811.o)
  "__Unwind_GetLanguageSpecificData", referenced from:
  ___dmd_personality_v0 in libphobos2.a(dwarfeh_892_811.o)
  "__Unwind_GetRegionStart", referenced from:
  ___dmd_personality_v0 in libphobos2.a(dwarfeh_892_811.o)
  "__Unwind_RaiseException", referenced from:
  __d_throwdwarf in libphobos2.a(dwarfeh_891_56a.o)
  "__Unwind_Resume", referenced from:
  __D3std5stdio__T7writelnTAyaZQnFNfQjZv in fred.o
  __D3std5stdio4File8opAssignMFNcNjNfSQBhQBgQBdZQl in 
libphobos2.a(stdio_19dd_180.o)
  __D3std5stdio4File6reopenMFNeAyaMAxaZv in 
libphobos2.a(stdio_19dd_180.o)
  __D3std5stdio4File6fdopenMFNeiMAxaAyaZv in 
libphobos2.a(stdio_19dd_180.o)
  __D3std5stdio4File6detachMFNeZv in 
libphobos2.a(stdio_19dd_180.o)
  __D3std5stdio4File5closeMFNeZv in 
libphobos2.a(stdio_19dd_180.o)
  
__D3std5stdio4File11ByChunkImpl6__ctorMFNcSQBoQBnQBkmZSQCaQBzQBwQBu in libphobos2.a(stdio_19dd_180.o)

  ...
  "__Unwind_SetGR", referenced from:
  ___dmd_personality_v0 in libphobos2.a(dwarfeh_892_811.o)
  "__Unwind_SetIP", referenced from:
  ___dmd_personality_v0 in libphobos2.a(dwarfeh_892_811.o)
  "___error", referenced from:
  __D3std5stdio4File7tryLockMFEQBaQz8LockTypemmZb in 
libphobos2.a(stdio_19dd_180.o)
  
__D3std9exception14ErrnoException6__ctorMFNfAyaQdmZCQBxQBwQBp in 
libphobos2.a(exception_489_5b5.o)

  __d_run_main2 in libphobos2.a(dmain2_888_4ad.o)
  __D4core6thread6Thread5sleepFNbNiSQBf4time8DurationZv in 
libphobos2.a(thread_386_258.o)

  _fakePureReprintReal in libphobos2.a(demangle_2ff_79b.o)
  "___stderrp", referenced from:
  ___dmd_personality_v0 in libphobos2.a(dwarfeh_892_811.o)
  __d_throwdwarf in libphobos2.a(dwarfeh_891_56a.o)
  
__D2rt7dwarfeh8scanLSDAFPxhmmbbPSQBe6unwind17_Unwind_ExceptionJmJiZEQCnQCn10LsdaResult in libphobos2.a(dwarfeh_896_2c9.o)
  
__D2rt6dmain218_d_print_throwableUC6object9ThrowableZ4sinkMFNbNiNlMxAaZv in libphobos2.a(dmain2_88b_776.o)

  __d_run_main2 in libphobos2.a(dmain2_888_4ad.o)
  __D2rt6dmain212_d_run_main2UAAamPUQgZiZ6runAllMFZv in 
libphobos2.a(dmain2_888_4ad.o)
  
__D2rt7dwarfeh17actionTableLookupFPSQBh6unwind17_Unwind_ExceptionkPxhQdhmQhZi in libphobos2.a(dwarfeh_897_6e0.o)

  ...
  "___stdoutp", referenced from:
  
__D3std5stdio__T10makeGlobalVEQBbQBa13StdFileHandlea22_636f72652e737464632e737464696f2e7374646f7574ZQDgFNbNcNdNiZSQEhQEg4File in libphobos2.a(stdio_19e9_cfb.o)

  __d_run_main2 in libphobos2.a(dmain2_888_4ad.o)
  "__dyld_get_image_header", referenced from:
  __D2rt19sections_osx_x86_6411getTLSRangeFNbNixPvZAv in 
libphobos2.a(sections_osx_x86_64_93f_420.o)

  "__dyld_image_count", referenced from:
  

Re: Blog Post #77: Notebook, Part I

2019-10-09 Thread Ron Tarrant via Digitalmars-d-learn

On Wednesday, 9 October 2019 at 03:13:48 UTC, GreatSam4sure wrote:


Good works


Thanks, GreatSam4sure.

Is there any way to detect the size of my screen using gtkd? So 
that incan calculate the size of my screen and center my window 
on the screen using move(x, y).


I had a quick look into this and there is no straightforward 
solution, so I can't give you an immediate answer. It would be 
easier to explain with a demo, so I'll need some time to work one 
up. I've put it on my to-do list.


Besides can you convert all your posts to a pdf that is easily 
downloadable for those with little internet access?


I've been thinking about an ebook based on the blog, something 
that would start with installing a development environment, go 
into how to organize and write each part of an application, and 
end with how to distribute the finished product. It's in very 
early stages ATM, but I'm open to any suggestions you (or anyone 
else) may have for how to make it as useful as possible.




Re: formatting a float or double in a string with all significant digits kept

2019-10-09 Thread GreatSam4sure via Digitalmars-d-learn
On Wednesday, 9 October 2019 at 07:16:43 UTC, Jon Degenhardt 
wrote:

On Wednesday, 9 October 2019 at 05:46:12 UTC, berni44 wrote:

On Tuesday, 8 October 2019 at 20:37:03 UTC, dan wrote:
But i would like to be able to do this without knowing the 
expansion of pi, or writing too much code, especially if 
there's some d function like writeAllDigits or something 
similar.


You can use the property .dig to get the number of significant 
digits of a number:


writeln(PI.dig); // => 18

You still need to account for the numbers before the dot. If 
you're happy with scientific notation you can do:


auto t = format("%.*e", PI.dig, PI);
writeln("PI = ",t);


Using the '.dig' property is a really nice idea and looks very 
useful for this. A clarification though - It's the significant 
digits in the data type, not the value. (PI is 18 because it's 
a real, not a double.) So:


writeln(1.0f.dig, ", ", float.dig);  =>  6, 6
writeln(1.0.dig, ", ", double.dig);  => 15, 15
writeln(1.0L.dig, ", ", real.dig);   => 18, 18

Another possibility would be to combine the '.dig' property 
with the "%g" option, similar to the use "%e" shown. For 
example, these lines:


writeln(format("%0.*g", PI.dig, PI));
writeln(format("%0.*g", double.dig, 1.0));
writeln(format("%0.*g", double.dig, 100.0));
writeln(format("%0.*g", double.dig, 1.0001));
writeln(format("%0.*g", double.dig, 0.0001));

produce:

3.14159265358979324
1
100
1.0001
1e-08

Hopefully experimenting with the different formatting options 
available will yield one that works for your use case.




Good solution

But what does it takes to leave a number the way it is without 
formatting automatic to 6 significant figure out how that 
requires such a work around as shown above. I know C language is 
the same but must D follow suit.


One of the compilers, i think the DMD 2.084 (not sure now) 
correct but now the recent one's have revert back. Every number 
should be left the way it is like java, C#(not sure), 
actionscript, javascript, etc.


I don't think it will take that much effort for trivial things 
like to stress developers.


This is the best solution i have ever seen on this issue on the 
forum.i have ask this question several times on this forum




Re: formatting a float or double in a string with all significant digits kept

2019-10-09 Thread Jon Degenhardt via Digitalmars-d-learn

On Wednesday, 9 October 2019 at 05:46:12 UTC, berni44 wrote:

On Tuesday, 8 October 2019 at 20:37:03 UTC, dan wrote:
But i would like to be able to do this without knowing the 
expansion of pi, or writing too much code, especially if 
there's some d function like writeAllDigits or something 
similar.


You can use the property .dig to get the number of significant 
digits of a number:


writeln(PI.dig); // => 18

You still need to account for the numbers before the dot. If 
you're happy with scientific notation you can do:


auto t = format("%.*e", PI.dig, PI);
writeln("PI = ",t);


Using the '.dig' property is a really nice idea and looks very 
useful for this. A clarification though - It's the significant 
digits in the data type, not the value. (PI is 18 because it's a 
real, not a double.) So:


writeln(1.0f.dig, ", ", float.dig);  =>  6, 6
writeln(1.0.dig, ", ", double.dig);  => 15, 15
writeln(1.0L.dig, ", ", real.dig);   => 18, 18

Another possibility would be to combine the '.dig' property with 
the "%g" option, similar to the use "%e" shown. For example, 
these lines:


writeln(format("%0.*g", PI.dig, PI));
writeln(format("%0.*g", double.dig, 1.0));
writeln(format("%0.*g", double.dig, 100.0));
writeln(format("%0.*g", double.dig, 1.0001));
writeln(format("%0.*g", double.dig, 0.0001));

produce:

3.14159265358979324
1
100
1.0001
1e-08

Hopefully experimenting with the different formatting options 
available will yield one that works for your use case.