Re: Linux & DMD & GtkD

2019-02-18 Thread Peter Jacobs via Digitalmars-d-learn

On Monday, 18 February 2019 at 14:24:46 UTC, Ron Tarrant wrote:

On Monday, 18 February 2019 at 10:38:10 UTC, Peter Jacobs wrote:

Being an old linux user, I prefer make to dub, however, I do 
use dub to build GtkD and then I just use dmd to build my 
application program.


This appeals to me, too.


dub clean
dub build


Got this bit working after generating an sdl file. But I think 
I'm missing something from this next approach:



make
dmd -w -g -debug -I=../GtkD/generated/gtkd \
-oftest_rig_imperative test_rig_imperative.d \
-L../GtkD/libgtkd-3.a
./test_rig_imperative


It's been literally decades since I used a makefile. Did I miss 
the part where you the makefile was written/generated?




Yes, you did miss that part because I didn't write it in, 
thinking that the echo of the command would be sufficient.  
Sorry.  Anyway, here is the single rule in my makefile.  I tend 
to use makefiles as a memory aid so they are often quite simple.


test_rig_imperative: test_rig_imperative.d
dmd -w -g -debug -I=../GtkD/generated/gtkd \
-oftest_rig_imperative test_rig_imperative.d \
-L../GtkD/libgtkd-3.a

Cheers,
Peter J.



Re: Is there a way to replace Exception with as a macro in C?

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

On Tuesday, 19 February 2019 at 05:50:04 UTC, yisooan wrote:

I wonder there is the way as I said in the title. For instance,

in C,

#define indexInvalidException Exception("The index is invalid")

/* Do something with the macro here */
if (false)
  indexInvalidException;


This is allowed.
But I want to do the exact same thing in D. I have already 
tried some expressions with alias? but it doesn't work.


alias indexInvalidException = Exception("The index is 
invalid");


/* Use the alias in somewhere */
if (false)
  throw new indexInvalidException;


Would you help me, please?


Alias is just a nickname for a symbol (i.e. alias string = 
immutable(char)[];) and lets you refer to that symbol with the 
nickname. You can't supply runtime parameters (like constructor 
parameters), but you can give compile-time template parameters 
(as the result of applying those parameters is a symbol rather 
than a value). Macros on the other hand, do a textual 
replacement, i.e. they alter the source code that goes into the 
compiler.


Depending on how brief you want to make your code, you can either 
use classic inheritance

class IndexInvalidException : Exception
{
this()
{
super("The index is invalid")
}
}


or, closest as you can get to macros:
enum throwNewIndexInvalidException = `throw new Exception("The 
index is invalid");`;


void main()
{
mixin(throwNewIndexInvalidException);
}

String mixins transform a string into an expression, and paste 
the expression wherever it is mixed in. It gets precompiled 
rather than substituted in the source code. This means it's best 
to have the whole line into a string, instead of individual parts 
(you can't have a mixin with just `Exception("The index is 
invalid")` for example).


Re: Is there a way to replace Exception with as a macro in C?

2019-02-18 Thread Mike Parker via Digitalmars-d-learn

On Tuesday, 19 February 2019 at 06:16:59 UTC, Mike Parker wrote:


```
Exception invalidIndexException() { throw new Exception("Index 
is invalid"); }


Eh, that should be:

void invalidIndexException() {...}


Re: Is there a way to replace Exception with as a macro in C?

2019-02-18 Thread Mike Parker via Digitalmars-d-learn

On Tuesday, 19 February 2019 at 05:50:04 UTC, yisooan wrote:


This is allowed.
But I want to do the exact same thing in D. I have already 
tried some expressions with alias? but it doesn't work.




alias can't be used for expressions.



Would you help me, please?


There's nothing exactly equivalent to the C preprocessor. The 
closest you'd be able to get without using a keyword like mixin 
is to use a function:


```
Exception invalidIndexException() { throw new Exception("Index is 
invalid"); }


if(false) invalidIndexException;
```

Of course, you can also subclass Exception:

```
class InvalidIndexException : Exception
{
this(string file = __FILE__, size_t line = __LINE__)
{
super("Index is invalid", file, line);
}
}

if(false) throw new InvalidIndexException;
```




Is there a way to replace Exception with as a macro in C?

2019-02-18 Thread yisooan via Digitalmars-d-learn

I wonder there is the way as I said in the title. For instance,

in C,

#define indexInvalidException Exception("The index is invalid")

/* Do something with the macro here */
if (false)
  indexInvalidException;


This is allowed.
But I want to do the exact same thing in D. I have already tried 
some expressions with alias? but it doesn't work.



alias indexInvalidException = Exception("The index is invalid");

/* Use the alias in somewhere */
if (false)
  throw new indexInvalidException;


Would you help me, please?


Fractal generators in D?

2019-02-18 Thread Michelle Long via Digitalmars-d-learn
Are their any fractal generators in D, ideally using the GPU and 
possibly supporting 3D/4D generation?




Re: dub ldc error _d_array_slice_copy

2019-02-18 Thread SrMordred via Digitalmars-d-learn

On Monday, 18 February 2019 at 23:40:20 UTC, kinke wrote:

On Monday, 18 February 2019 at 19:10:50 UTC, SrMordred wrote:
dub --compiler=ldc2 //app.d:4: error: undefined reference to 
'_d_array_slice_copy'


Dub has nothing to do with it, it's the -betterC flag, and LDC 
expecting that druntime function to be available for slice 
copies. Quick workaround: add a manual version (here without 
any checks) somewhere in your code:


extern(C) void _d_array_slice_copy(void* dst, size_t dstlen, 
void* src, size_t srclen, size_t elemsz)

{
import ldc.intrinsics : llvm_memcpy;
llvm_memcpy!size_t(dst, src, dstlen * elemsz, 0);
}


Thanks, I discovered this workaround too :)

But I dont get it:
-betterC aren't supoused to be D without any druntime?
Why it is searching for this function?



Re: Error with matplotlib

2019-02-18 Thread Samir via Digitalmars-d-learn

On Monday, 18 February 2019 at 21:50:25 UTC, Andre Pany wrote:
In the meantime you could adapt the python script on your local 
file system in the dub packages cache folder as described here 
https://github.com/koji-kojiro/matplotlib-d/pull/11/files


Andre,

Thank you very much for your help today!

I copied the version of prebuild.py located here[1] and replaced 
the version located at 
/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/python 
locally on my machine after which the program ran.


I guess I still have the question as to why does the error 
message refer to issues in 
/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot.d-mixin-41 when the solution was changing /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/python/prebuild.py?


Apologies for all of the questions -- I'm just trying to better 
understand how to incorporate other packages in my simple 
programs.


Samir

[1] 
https://github.com/koji-kojiro/matplotlib-d/blob/master/python/prebuild.py


Re: dub ldc error _d_array_slice_copy

2019-02-18 Thread kinke via Digitalmars-d-learn

On Monday, 18 February 2019 at 19:10:50 UTC, SrMordred wrote:
dub --compiler=ldc2 //app.d:4: error: undefined reference to 
'_d_array_slice_copy'


Dub has nothing to do with it, it's the -betterC flag, and LDC 
expecting that druntime function to be available for slice 
copies. Quick workaround: add a manual version (here without any 
checks) somewhere in your code:


extern(C) void _d_array_slice_copy(void* dst, size_t dstlen, 
void* src, size_t srclen, size_t elemsz)

{
import ldc.intrinsics : llvm_memcpy;
llvm_memcpy!size_t(dst, src, dstlen * elemsz, 0);
}


Re: Error with matplotlib

2019-02-18 Thread Andre Pany via Digitalmars-d-learn

On Monday, 18 February 2019 at 21:28:14 UTC, Samir wrote:

On Monday, 18 February 2019 at 20:30:23 UTC, Andre Pany wrote:

[...]


Thank you for that!  After installing the version of matplotlib 
for python2 and rerunning dub build, I now get 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...
/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot.d-mixin-41(191,6):
 Error: no identifier for declarator void
/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot.d-mixin-41(191,18):
 Error: found ... when expecting )
/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot.d-mixin-41(191,21):
 Error: declaration expected, not )
/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot.d-mixin-41(191,63):
 Error: declaration expected, not if
/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot.d-mixin-41(191,89):
 Error: no identifier for declarator a
/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot.d-mixin-41(191,89):
 Error: declaration expected, not )
/usr/home/samir/dlang/dmd-2.082.0/freebsd/bin64/dmd failed with 
exit code 1.


I don't see a pyplot.d-mixin-41 file in that directory but I do 
have pyplot.d.


Is there an issue with the package itself?

Samir


Issue is already solved in master but a new release is missing. 
Github issue 
https://github.com/koji-kojiro/matplotlib-d/issues/12 created.


In the meantime you could adapt the python script on your local 
file system in the dub packages cache folder as described here 
https://github.com/koji-kojiro/matplotlib-d/pull/11/files


Kind regards
Andre


Re: Error with matplotlib

2019-02-18 Thread Samir via Digitalmars-d-learn

On Monday, 18 February 2019 at 20:30:23 UTC, Andre Pany wrote:
The issue is, the dub package is using python 2 (it executes 
application python) while you have installed matplotlib for 
Python 3 (application python3).


Thank you for that!  After installing the version of matplotlib 
for python2 and rerunning dub build, I now get 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...
/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot.d-mixin-41(191,6):
 Error: no identifier for declarator void
/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot.d-mixin-41(191,18):
 Error: found ... when expecting )
/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot.d-mixin-41(191,21):
 Error: declaration expected, not )
/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot.d-mixin-41(191,63):
 Error: declaration expected, not if
/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot.d-mixin-41(191,89):
 Error: no identifier for declarator a
/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot.d-mixin-41(191,89):
 Error: declaration expected, not )
/usr/home/samir/dlang/dmd-2.082.0/freebsd/bin64/dmd failed with 
exit code 1.


I don't see a pyplot.d-mixin-41 file in that directory but I do 
have pyplot.d.


Is there an issue with the package itself?

Samir


Re: Error with matplotlib

2019-02-18 Thread Andre Pany via Digitalmars-d-learn

On Monday, 18 February 2019 at 19:24:52 UTC, Samir wrote:

On Monday, 18 February 2019 at 18:27:17 UTC, Andre Pany wrote:
Therefore python needs to be installed and also 
matplotlib.pyplot.


Hi Andre,

I do have both python3 and matplotlib installed:

 $ 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.

 >>> matplotlib.__version__
 '3.0.2'
 >>> import matplotlib.pyplot
 >>>

Do I have an issue with the way my dub.json file is configured?
 This is the first time I am using dub.  I also just copied and 
pasted the code in app.d straight from the matplotlib-d package 
page (http://code.dlang.org/packages/matplotlib-d).


Thanks
Samir


The issue is, the dub package is using python 2 (it executes 
application python) while you have installed matplotlib for 
Python 3 (application python3).


Kind regards
Andre


Re: dub ldc error _d_array_slice_copy

2019-02-18 Thread SrMordred via Digitalmars-d-learn

On Monday, 18 February 2019 at 19:14:42 UTC, SrMordred wrote:

oh, and:
DUB version 1.13.0, built on Feb 17 2019

LDC - the LLVM D compiler (1.14.0):
  based on DMD v2.084.1 and LLVM 7.0.1


Sorry, both give the same error, the problem is related to 
-betterC flag (which i forgot to add on first compile example), 
but stil..


Re: Windows Defender won't let me install DMD

2019-02-18 Thread Samir via Digitalmars-d-learn

On Monday, 18 February 2019 at 19:44:56 UTC, Samir wrote:
that is what the two reference books[1] I am using to learn D 
have been using.


Idiot me forgot to mention the two resources I have been using:
(1) "Programming in D", by Ali Çehreli, available at 
http://ddili.org/ders/d.en/index.html
(2) "Learning D", by Michael Parker, available at 
https://www.packtpub.com/application-development/learning-d


Re: Windows Defender won't let me install DMD

2019-02-18 Thread Samir via Digitalmars-d-learn

On Monday, 18 February 2019 at 16:32:26 UTC, belkin wrote:

Obviously I need a compiler (which one is best ).


I too am a beginner (both at programming and at D).  I have been 
sticking to the dmd compiler (over others such as gdc or ldc) 
mainly because that is what the two reference books[1] I am using 
to learn D have been using.


But I also want an IDE and so far it seems Visual D would be a 
best choice.


I've been using vim as the syntax highlighting seems to work 
pretty well out of the box but mainly because I am not familiar 
with any IDEs.  Personally, I find that keeping things simple at 
this point are probably better for the way I work and learn.


The good news is that I have found the people here to be quite 
friendly and helpful when you run into issues.


Good luck!
Samir


Re: Windows Defender won't let me install DMD

2019-02-18 Thread Seb via Digitalmars-d-learn

On Monday, 18 February 2019 at 16:32:26 UTC, belkin wrote:
I am trying to install the compiler and get started on learning 
D again ( attempted and stopped way back )


This is the error message I am getting. I am on Windows 10.

Windows Defender SmartScreen prevented an unrecognized app from 
starting. Running this app might put your PC at risk.


App:
dmd-2.084.1.exe
Publisher:
Unknown publisher


There was a error/oversight with the 2.084.1 release. It 
accidentally didn't get signed, you can try 2.084.0 if you are 
afraid of the warning. The next release (2.085.0) should be 
signed again.


Re: Error with matplotlib

2019-02-18 Thread Samir via Digitalmars-d-learn

On Monday, 18 February 2019 at 18:27:17 UTC, Andre Pany wrote:
Therefore python needs to be installed and also 
matplotlib.pyplot.


Hi Andre,

I do have both python3 and matplotlib installed:

 $ 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.

 >>> matplotlib.__version__
 '3.0.2'
 >>> import matplotlib.pyplot
 >>>

Do I have an issue with the way my dub.json file is configured?  
This is the first time I am using dub.  I also just copied and 
pasted the code in app.d straight from the matplotlib-d package 
page (http://code.dlang.org/packages/matplotlib-d).


Thanks
Samir


Re: dub ldc error _d_array_slice_copy

2019-02-18 Thread SrMordred via Digitalmars-d-learn

oh, and:
DUB version 1.13.0, built on Feb 17 2019

LDC - the LLVM D compiler (1.14.0):
  based on DMD v2.084.1 and LLVM 7.0.1



dub ldc error _d_array_slice_copy

2019-02-18 Thread SrMordred via Digitalmars-d-learn

On ubuntu:

void test(size_t l)
{
char* a;
a[0 .. l] = a[0 .. l];  
}
extern(C) void main(){
test(0);
}

ldc2 source/app.d //compiles

dub --compiler=ldc2 //app.d:4: error: undefined reference to 
'_d_array_slice_copy'






Re: Error with matplotlib

2019-02-18 Thread Andre Pany via Digitalmars-d-learn

On Sunday, 17 February 2019 at 20:19:23 UTC, Samir wrote:
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:


[...]


This dub packages enables you to call python coding from D. In 
this specific case functions from the python module 
matplotlib.pyplot.


The dub package calls this python file which causes your error as 
python cannot find matplotlib.pyplot.


https://github.com/koji-kojiro/matplotlib-d/blob/master/python/prebuild.py

Therefore python needs to be installed and also matplotlib.pyplot.

I got the dub package example working some weeks ago. In general 
it should work.


Kind regards
Andre


Re: DMD: can't get extern __gshared to work right (vs. LDC)

2019-02-18 Thread rikki cattermole via Digitalmars-d-learn

On 19/02/2019 6:26 AM, DanielG wrote:
In the meantime, while I'm waiting for this bug to be noticed by anybody 
with the skills to address it, what would be the most elegant way of 
working around it?


Obviously I could do a:

version(Windows) {
   export extern __gshared ...
} else {
   extern __gshared ...
}

But what's the minimal way of toggling the presence of "export" in a 
declaration? Using mixins feels kind of gross for this, but if that's 
the only option ...


Almost makes me long for the C preprocessor :P


Because you need two different versions to choose between them, either 
set a per module version or use static if with enum's.


But yeah, I would do that. Of course a mixin template with a code string 
(q{ ... }) would be cleaner. After all, ``export { mixin(str); }`` would 
work well.


Re: DMD: can't get extern __gshared to work right (vs. LDC)

2019-02-18 Thread DanielG via Digitalmars-d-learn
In the meantime, while I'm waiting for this bug to be noticed by 
anybody with the skills to address it, what would be the most 
elegant way of working around it?


Obviously I could do a:

version(Windows) {
  export extern __gshared ...
} else {
  extern __gshared ...
}

But what's the minimal way of toggling the presence of "export" 
in a declaration? Using mixins feels kind of gross for this, but 
if that's the only option ...


Almost makes me long for the C preprocessor :P



Windows Defender won't let me install DMD

2019-02-18 Thread belkin via Digitalmars-d-learn
I am trying to install the compiler and get started on learning D 
again ( attempted and stopped way back )


This is the error message I am getting. I am on Windows 10.

Windows Defender SmartScreen prevented an unrecognized app from 
starting. Running this app might put your PC at risk.


App:
dmd-2.084.1.exe
Publisher:
Unknown publisher

Additional question as a beginner. What do I need to install to 
get started.
Obviously I need a compiler (which one is best ). But I also want 
an IDE and so far it seems Visual D would be a best choice.


Ideas?


Re: Zero length arrays in D

2019-02-18 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Feb 18, 2019 at 01:34:37PM +, Eduard Staniloiu via 
Digitalmars-d-learn wrote:
> Hello
> 
> According to the spec[0], D supports zero length arrays [1].

Huh. I didn't even know D was supposed to support this.  I found a few
examples of this usage in Adam Ruppe's arsd code, where the zero-length
array is sliced as you indicated:

struct X {
int[0] data;
}
X* x = ...;

int[] arr = x.data.ptr[0 .. n];
arr[i] = ...;


[...]
> Attempting to use the zero-length array results in a compiler error
> 
> `a.contents[2]` -> Error: array index 2 is out of bounds
> (*a).contents[0 ..  0]

Yeah this needs to be explicated in the docs / spec.


> The way I've used around this error is "safely" break/trick the type
> system
> 
> ```
> int *p = a.contents.ptr;
> int[] p_cont = p[0 .. n];
> p_cont[2] = 10; // fine
> ```
> 
> Is this the intended way of working with zero length arrays?
[...]

No idea.  But it's probably the only way of actually using them right
now. :-D  The spec / docs need to be updated.


T

-- 
Long, long ago, the ancient Chinese invented a device that lets them see 
through walls. It was called the "window".


Re: Linux & DMD & GtkD

2019-02-18 Thread Ron Tarrant via Digitalmars-d-learn
On Saturday, 16 February 2019 at 19:11:03 UTC, Antonio Corbi 
wrote:



/+
 dub.sdl:
 
 name   "gtkhello"
 dflags "-dip25" "-dip1000"
 dependency "gtk-d:gtkd" version="~>3.8.0"
 +/

/*
  dub run --single gtkhello.d
  dub build --single gtkhello.d.
  dub gtkhello.d .
*/


This is cool. And I even made it work. Again, thanks.


Re: Linux & DMD & GtkD

2019-02-18 Thread Ron Tarrant via Digitalmars-d-learn

On Monday, 18 February 2019 at 10:38:10 UTC, Peter Jacobs wrote:

Being an old linux user, I prefer make to dub, however, I do 
use dub to build GtkD and then I just use dmd to build my 
application program.


This appeals to me, too.


dub clean
dub build


Got this bit working after generating an sdl file. But I think 
I'm missing something from this next approach:



make
dmd -w -g -debug -I=../GtkD/generated/gtkd \
-oftest_rig_imperative test_rig_imperative.d \
-L../GtkD/libgtkd-3.a
./test_rig_imperative


It's been literally decades since I used a makefile. Did I miss 
the part where you the makefile was written/generated?


I'd also like to take this opportunity to express my deepest 
gratitude to all you guys for all this help. Getting back up and 
running in Linux has had its challenges and over the weekend, I 
admit I almost gave up after just trying to get a desktop sorted 
out. I won't bore you with off-topic details, but suffice to say, 
my Focusrite audio interface has a mind of its own.


But to wake up this morning to this outpouring of help made me 
feel tons better about it all. I have a build process [or five :) 
] now and all the discouragement of the weekend is draining away.


Thanks, guys! Seriously. Thank you.




Re: Linux & DMD & GtkD

2019-02-18 Thread Ron Tarrant via Digitalmars-d-learn

On Monday, 18 February 2019 at 06:29:54 UTC, Russel Winder wrote:

Hopefully the above has helped, do feel free to ask further 
questions. I am a day-in, day-out Debian Sid user and so may 
still be making assumptions tht aren't working for you…


I really appreciate all the time and effort you put into that 
reply, Russell. That is a ton of info there.


I didn't realize how soft (dare I say: micro-soft) Windows had 
made me over the last decade or so. Coming back to UNIX-like and 
POSIX OSs, I'm feeling like a complete newbie again.


But some day I shall reclaim my Super Cow Powers. :)


Re: Linux & DMD & GtkD

2019-02-18 Thread Ron Tarrant via Digitalmars-d-learn

On Monday, 18 February 2019 at 13:55:41 UTC, Ron Tarrant wrote:


But some day I shall reclaim my Super Cow Powers. :)


Oh, I guess I misspelled 'seardh.' That may explain why my 
attempt to run aptitude was 'put out to pasture.'




Re: Linux & DMD & GtkD

2019-02-18 Thread Ron Tarrant via Digitalmars-d-learn

On Monday, 18 February 2019 at 13:34:22 UTC, Ron Tarrant wrote:

You've saved me a ton of time and effort.


This can be interpreted as: flailing about, bashing my shell 
against the terminal.


Re: Linux & DMD & GtkD

2019-02-18 Thread Ron Tarrant via Digitalmars-d-learn

On Sunday, 17 February 2019 at 14:19:35 UTC, Jordi Sayol wrote:

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



Jordi


Thanks, Jordi. This is going straight into my notes. You've saved 
me a ton of time and effort.


Re: Linux & DMD & GtkD

2019-02-18 Thread Ron Tarrant via Digitalmars-d-learn
On Saturday, 16 February 2019 at 19:11:03 UTC, Antonio Corbi 
wrote:



For one-file programs, dub usage is very easy.

Placing a minimal comment-header between /+ +/ symbol comments, 
gets your job done like in this example ( I think the gtkd code 
is from one of your examples in the blog):



Antonio


Thanks, Antonio. That's very helpful.


Zero length arrays in D

2019-02-18 Thread Eduard Staniloiu via Digitalmars-d-learn

Hello

According to the spec[0], D supports zero length arrays [1].

I have given this a shot at https://run.dlang.io/is/PwbPxJ

Attempting to use the zero-length array results in a compiler 
error


`a.contents[2]` -> Error: array index 2 is out of bounds 
(*a).contents[0 .. 0]


The way I've used around this error is "safely" break/trick the 
type system


```
int *p = a.contents.ptr;
int[] p_cont = p[0 .. n];
p_cont[2] = 10; // fine
```

Is this the intended way of working with zero length arrays?

Cheers,
Edi


[0] - https://dlang.org/spec/arrays.html#static-arrays, best 
practices pt 2
[1] - 
https://gcc.gnu.org/onlinedocs/gcc-4.7.4/gcc/Zero-Length.html


Re: Linux & DMD & GtkD

2019-02-18 Thread Peter Jacobs via Digitalmars-d-learn

On Saturday, 16 February 2019 at 13:35:57 UTC, Ron Tarrant wrote:

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


Being an old linux user, I prefer make to dub, however, I do use 
dub to build GtkD and then I just use dmd to build my application 
program.  Here is a transcript of building and running the first 
tutorial exercise on my computer that runs LinuxMint.  It all 
works nicely, when pointing the DMD compiler to the generated 
gtkd bindings and the linker to the dub-built library file.


peterj@helmholtz ~/work/play/dlang/GtkD $ dub clean
Cleaning package at /home/peterj/work/play/dlang/GtkD...
peterj@helmholtz ~/work/play/dlang/GtkD $ dub build
Performing "debug" build using /usr/bin/dmd for x86_64.
gtk-d:gtkd ~master: building configuration "library"...
generated/gtkd/glib/Spawn.d(305,3): Deprecation: foreach: loop 
index implicitly converted from size_t to int

gtk-d:gstreamer ~master: building configuration "library"...
gtk-d:peas ~master: building configuration "library"...
gtk-d:sv ~master: building configuration "library"...
gtk-d:vte ~master: building configuration "library"...
peterj@helmholtz ~/work/play/dlang/GtkD $ cd ../gtkd-example/
peterj@helmholtz ~/work/play/dlang/gtkd-example $ make
dmd -w -g -debug -I=../GtkD/generated/gtkd \
-oftest_rig_imperative test_rig_imperative.d \
-L../GtkD/libgtkd-3.a
peterj@helmholtz ~/work/play/dlang/gtkd-example $ 
./test_rig_imperative

Hello GtkD Imperative
Bye.
peterj@helmholtz ~/work/play/dlang/gtkd-example $ dmd --version
DMD64 D Compiler v2.085.0-beta.1
Copyright (C) 1999-2019 by The D Language Foundation, All Rights 
Reserved written by Walter Bright