Re: Best practices of using const

2019-02-17 Thread Marco de Wild via Digitalmars-d-learn

On Wednesday, 13 February 2019 at 16:40:18 UTC, H. S. Teoh wrote:
On Wed, Feb 13, 2019 at 11:32:46AM +, envoid via 
Digitalmars-d-learn wrote:
Unfortunately, that guarantee also excludes a lot of otherwise 
useful idioms, like objects that cache data -- a const object 
cannot cache data because that means it's being mutated, or 
lazily-initialized objects -- because once the ctor has run, 
the object can no longer be mutated. Most notably, D's powerful 
range idiom is pretty much unusable with const because 
iteration over a range requires mutating the range (though 
having const *elements* in a range is fine).  This doesn't seem 
as bad at first glance, but it wreaks havoc on generic code, 
another thing that D is purportedly good at. It's very hard 
(and often impossible) to write generic code that works with 
both const and mutable objects.


So ironically, the iron-clad semantics of D's const system 
turns out to be also its own downfall.



T


I agree that const by nature unfortunately kills lazy 
initialization. However, I don't really understand why const is a 
problem with ranges. Const elements are not a problem. Iterating 
over a range consumes it (if I understand correctly). It does not 
make sense to be able to consume a const object, so from my point 
of view it's perfectly logical to disallow iterating const 
ranges. If I'm missing something, please correct me.


I use const quite thoroughly in my project (a mahjong board game) 
and in fact I am writing a blog post explaining how it helped me 
understand what was happening in my code base. It enforces 
encapsulated mutations. In classic OOP languages, mutable objects 
propagate through the entire system, unless you actively create 
an immutable copy of it (which is a lot of work for little gain). 
If someone modifies your object on a place you don't expect (e.g. 
creating and persisting data when rendering a read-only view), it 
becomes hard to impossible to reason about the problem and debug 
it.
Refactoring in const was a lot of work, but I think it made my 
code better in the end. I didn't run into any problems when using 
it, except when I tried to modify an object where I should not 
have (e.g. sorting a hand when rendering the view). I was able to 
untangle the spaghetti because the compiler poked me about it. As 
I didn't run into any problems and it helped clean up my code 
base, I would recommend trying it.


Re: Linux & DMD & GtkD

2019-02-17 Thread Russel Winder via Digitalmars-d-learn
On Sat, 2019-02-16 at 16:28 +, Ron Tarrant via Digitalmars-d-learn wrote:
> 
> […]

Apologies for the delay in replying.

> It's been almost 20 years since I used Linux and my notes are 
> long gone. A ton of things have changed. Like, for instance, it 
> found all my hardware this time, without me getting involved. But 
> also the software installation managers and lots of other things 
> are completely unrecognizable. On top of that, my brain has 
> (unfortunately) been molded into the Windows/Microsoft way of 
> thinking.

Personally I use aptitude for all Debian package management – Ubuntu and Mint
are the same as Debian really in this but with different package repositories.
Some people use apt and some apt-get, etc. For me the advantage of aptitude is
that it has a curses-based GUI as well as command line.

> I guess what I'm hoping for is a step-by-step, 
> full-on-hand-holding, large-print with pictures tutorial for how 
> to get GtkD and (I guess) dub working. I know the stuff you wrote 
> is probably helpful, but I'm not well-enough versed in Linux or 
> any flavour of UNIX ATM to understand it, pick which option I 
> should use, and to put these commands in proper order.

|> aptitude search gtkd
i A libgtkd-3-0- GTK+ graphical user interface library
- D bin
i A libgtkd-3-dev  - GTK+ graphical user interface library
- devel
p   libgtkd3-67- gtkd3 for dmd2 (runtime
library) 
p   libgtkd3-68- gtkd3 for dmd2 (runtime
library) 
p   libgtkd3-69- gtkd3 for dmd2 (runtime
library) 
p   libgtkd3-70- gtkd3 for dmd2 (runtime
library) 
p   libgtkd3-71- gtkd3 for dmd2 (runtime
library) 
p   libgtkd3-72- gtkd3 for dmd2 (runtime
library) 
p   libgtkd3-73- gtkd3 for dmd2 (runtime
library) 
p   libgtkd3-74- gtkd3 for dmd2 (runtime
library) 
p   libgtkd3-75- gtkd3 for dmd2 (runtime
library) 
p   libgtkd3-76- gtkd3 for dmd2 (runtime
library) 
p   libgtkd3-77- gtkd3 for dmd2 (runtime
library) 
p   libgtkd3-78- gtkd3 for dmd2 (runtime
library) 
p   libgtkd3-79- GtkD3 for DMD2 (runtime
library) 
p   libgtkd3-80- GtkD3 for DMD2 (runtime
library) 
p   libgtkd3-81- GtkD3 for DMD2 (runtime
library) 
p   libgtkd3-82- GtkD3 for DMD2 (runtime
library) 
p   libgtkd3-83- GtkD3 for DMD2 (runtime
library) 
p   libgtkd3-84- GtkD3 for DMD2 (runtime
library) 
p   libgtkd3-dev   - GtkD3 for DMD2 (development
files)   
i   libgtkd3-doc   - GtkD3 for DMD2 (documentation and
examples)  
p   libgtkdatabox-dev  - Gtk+ library to display large amounts
of nume
p   libgtkdatabox-doc  - Gtk+ library to display large amounts
of nume
p   libgtkdatabox0 - Gtk+ library to display large amounts
of nume
p   libgtkdatabox0-glade   - Gtk+ library to display large amounts
of nume
p   libgtkdatabox0-libglade- Gtk+ library to display large amounts
of nume
p   libgtkdsv-3-0  - GTK+ syntax highlighting widget - D
bindings 
p   libgtkdsv-3-dev- GTK+ syntax highlighting widget -
development

I am using the GtkD package created by the D Debian package people. This is
created using LDC rather than DMD. All the other libgtkd3 packages are ones
build by Jordi Sayol on D-Apt. If you want to use DMD, it is probably best to
install them. Me, I am an LDC oriented person so am happy with the standard
Debian packaged GtkD.

The libgtkd-3-0 package contains just the runtime libraries, or library in
this case. This being Linux libraries are always shared objects (aka DLLs):

> dpkg -L libgtkd-3-0 
/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libgtkd-3.so.0.8.5
/usr/share
/usr/share/doc
/usr/share/doc/libgtkd-3-0
/usr/share/doc/libgtkd-3-0/changelog.Debian.gz
/usr/share/doc/libgtkd-3-0/changelog.gz
/usr/share/doc/libgtkd-3-0/copyright
/usr/lib/x86_64-linux-gnu/libgtkd-3.so.0

The  libgtkd-3-dev  package contains all the files needed to build code
against GtkD.

 |> dpkg -L libgtkd-3-dev
/.
/usr
/usr/include
/usr/include/d
/usr/include/d/gtkd-3
…
[all the GtkD sources.]
…
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/lib/x86_64-linux-gnu/pkgconfig/gtkd-3.pc
/usr/share
/usr/share/doc
/usr/share/doc/libgtkd-3-dev
/usr/share/doc/libgtkd-3-dev/changelog.Debian.gz

Error with matplotlib

2019-02-17 Thread Samir via Digitalmars-d-learn
I am trying to run the code from the "Simple Example" listed in 
the matplotlib-d package page[1] and am running into the 
following error:


$ dub build
Performing "debug" build using 
/usr/home/samir/dlang/dmd-2.082.0/freebsd/bin64/dmd for x86_64.

matplotlib-d 0.1.4: building configuration "library"...
Running pre-build commands...
Traceback (most recent call last):
  File 
"/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/python/prebuild.py", line 37, in 

gen_pyplot_functions(argv[1])
  File 
"/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/python/prebuild.py", line 25, in gen_pyplot_functions

import matplotlib.pyplot
ImportError: No module named matplotlib.pyplot
Command failed with exit code 1: python 
/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/python/prebuild.py /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d


Some information about my environment:
$ uname -a
FreeBSD enterprise 11.2-RELEASE-p9 FreeBSD 11.2-RELEASE-p9 #0: 
Tue Feb  5 15:30:36 UTC 2019 
r...@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  
amd64

$ dmd --version
DMD64 D Compiler v2.082.0
Copyright (C) 1999-2018 by The D Language Foundation, All Rights 
Reserved written by Walter Bright

$ python3
Python 3.6.7 (default, Jan 10 2019, 01:15:48)
[GCC 4.2.1 Compatible FreeBSD Clang 6.0.0 (tags/RELEASE_600/final 
326565)] on freebsd11
Type "help", "copyright", "credits" or "license" for more 
information.

import matplotlib
matplotlib.__file__

'/usr/local/lib/python3.6/site-packages/matplotlib/__init__.py'

matplotlib.__version__

'3.0.2'

dub.json:
{
"name": "matplotlib",
"authors": [
"User &"
],
"description": "A minimal D application.",
"copyright": "Copyright _ 2019, User &",
"license": "proprietary",
"dependencies": {
"matplotlib-d": "~>0.1.4"
}
}

source/app.d:
import std.math;
import std.range;
import std.algorithm;
import plt = matplotlibd.pyplot;

void main() {
 auto x = iota(0, 2.05, 0.05).map!(x => x * PI);
 auto y = x.map!(sin);

 plt.plot(x, y, "r-", ["label": "$y=sin(x)$"]);
 plt.xlim(0, 2 * PI);
 plt.ylim(-1, 1);
 plt.legend();
 plt.savefig("simple.png");
 plt.clear();
}

[1] http://code.dlang.org/packages/matplotlib-d


Re: Linux & DMD & GtkD

2019-02-17 Thread Jordi Sayol via Digitalmars-d-learn
El 17/2/19 a les 15:19, Jordi Sayol ha escrit:
> Then you can compile/run a GtkD example contained on gtkd doc archive. To do 
> that just run the next line:
> 
> $ dmd `pkg-config --cflags --libs gtkd-3` -run 
> /usr/share/libgtkd3-doc/demos/gtkD/TestWindow/*.d -ofTestWindow

Sorry, do not run at compile time. Just remove "-run" to properly compile the 
example:

$ dmd `pkg-config --cflags --libs gtkd-3` 
/usr/share/libgtkd3-doc/demos/gtkD/TestWindow/*.d -ofTestWindow

> 
> 
> To run the compiled example just type:
> 
> $ ./TestWindow

Regards,
Jordi


Re: Linux & DMD & GtkD

2019-02-17 Thread Jordi Sayol via Digitalmars-d-learn
El 16/2/19 a les 14:35, Ron Tarrant via Digitalmars-d-learn ha escrit:
> Hi guys,
> 
> I finally got a Linux Mint installation happening (very impressed, BTW) and 
> did the usual HelloWorld.d compile with dmd, but I'm having trouble working 
> out how to link to GtkD.
> 
> dmd -de -w -m64 -L+gtkd hello_gtkd_world.d
> 
> says it can't find MainWindow which tells me the gtkd libraries are not 
> installed, are not included in the path, or some other oversight on my part.
> 
> I tried using whereis to find gtkd, but to no avail.
> 
> Questions:
> 
> 1. Am I using the right syntax in the above command line?
> 
> 2. How to search for things on Linux Mint
> 
> The recommendations I've found so far are for the gnome search tool which 
> spits out an error:
> 
> Package gnome-search-tool is not available, but is referred to by another 
> package.
> This may mean that the package is missing, has been obsoleted, or
> is only available from another source
> 

Hello Ron,

There is "d-apt"  where there are dmd and gtkd 
deb for Linux Mint.

To add this repository to your Linux Mint just run this two lines from command 
line:

$ sudo wget 
https://netcologne.dl.sourceforge.net/project/d-apt/files/d-apt.list -O 
/etc/apt/sources.list.d/d-apt.list

$ sudo apt-get update --allow-insecure-repositories && sudo apt-get -y 
--allow-unauthenticated install --reinstall d-apt-keyring && sudo apt-get update

After that you can install all the packages on "d-apt".


To install dmd compiler, dmd doc, gtkd devel and gtkd doc packages just run the 
next line:

$ sudo apt-get install dmd-compiler dmd-doc libgtkd3-dev libgtkd3-doc


Then you can compile/run a GtkD example contained on gtkd doc archive. To do 
that just run the next line:

$ dmd `pkg-config --cflags --libs gtkd-3` -run 
/usr/share/libgtkd3-doc/demos/gtkD/TestWindow/*.d -ofTestWindow


To run the compiled example just type:

$ ./TestWindow


There are more examples at /usr/share/libgtkd3-doc/demos/


Hope this help you.

Jordi