Re: Install of nightly with install.sh is not latest version

2021-04-27 Thread Jamie via Digitalmars-d-learn

On Tuesday, 27 April 2021 at 12:35:52 UTC, Jamie wrote:
When using the install.sh script and choosing 'dmd-nightly' I'm 
currently getting DMD v2.091.0-beta.2-master-ec39fe5 (the 
folder downloaded is dmd-master-2020-03-10).


I can install a more recent version using install 'dmd' etc.

Is this a bug? Or am I just using it incorrectly?

Cheers


Which I think stems from that fact that the nightly releases 
aren't updated here:

http://downloads.dlang.org/nightlies/


Install of nightly with install.sh is not latest version

2021-04-27 Thread Jamie via Digitalmars-d-learn
When using the install.sh script and choosing 'dmd-nightly' I'm 
currently getting DMD v2.091.0-beta.2-master-ec39fe5 (the folder 
downloaded is dmd-master-2020-03-10).


I can install a more recent version using install 'dmd' etc.

Is this a bug? Or am I just using it incorrectly?

Cheers


Re: Passing pointer to extern(C++) templated function

2020-10-13 Thread Jamie via Digitalmars-d-learn

On Tuesday, 13 October 2020 at 23:39:38 UTC, Ali Çehreli wrote:

On 10/13/20 4:11 PM, James Blachly wrote:

On 10/13/20 5:23 AM, Jamie wrote:


I think the issue is with D's "turtles all the way down" style 
const. My workaround would be to define wrapper functions that 
may need to do casting on one or the other side.


Ali


Why would the 'turtles all the way down' change function 
arguments? They are on the same 'level' whereas I took the 
transitive const to be applied through different depths in 
functions / classes etc.


Thanks for the suggestion, my current work around is to just 
remove the const but casting sounds a bit safer.


Re: Passing pointer to extern(C++) templated function

2020-10-13 Thread Jamie via Digitalmars-d-learn

On Tuesday, 13 October 2020 at 23:47:24 UTC, kinke wrote:

On Tuesday, 13 October 2020 at 09:23:48 UTC, Jamie wrote:
It appears that func3 and func4 take on different types 
depending on other variables being present? Is this expected?


Nope, it's a bug in the Itanium C++ mangler, please file a bug. 
MSVC++ mangling seems fine, after fixing the D declarations to


void func3(T)(T* b, const(T)* a);
void func4(T)(const(T)* a, T* b);

[A D `const T*` is equivalent to C++ `const T* const`; this 
matters for MSVC mangling...].


Happy to file a bug, but if it was a bug in the mangler wouldn't 
both C++ and D get the same result? Assuming D uses the same 
mangler for the extern(C++) stuff.


Passing pointer to extern(C++) templated function

2020-10-13 Thread Jamie via Digitalmars-d-learn
I'm having difficulties linking templated functions with multiple 
pointer arguments with extern(C++).


a.cpp
-
template void func1(T *b){}
template void func1(int *b);

template void func2(const T *a){}
template void func2(const int *a);

template void func3(T *b, const T *a){}
template void func3(int *b, const int *a);

template void func4(const T *a, T *b){}
template void func4(const int *a, int *b);

void func5(int *b, const int *a){}
void func6(const int *a, int *b){};
-

main.d
-
extern (C++)
{
void func1(T)(T *b);
void func2(T)(const T *a);
void func3(T)(T *b, const T *a);
void func4(T)(const T *a, T *b);
void func5(int *b, const int *a);
void func6(const int *a, int *b);
}

void main()
{
int i = 4;
int *pi = 

func1(pi);
func2();
func3(pi, );
func4(, pi);
func5(pi, );
func6(, pi);
}
-

Building with:
g++ -c a.cpp
dmd main.d a.o

Throws the error:
/usr/bin/ld: main.o: in function `_Dmain':
main.d:(.text._Dmain[_Dmain]+0x31): undefined reference to `void 
func3(int*, int*)'
/usr/bin/ld: main.d:(.text._Dmain[_Dmain]+0x3e): undefined 
reference to `void func4(int const*, int const)'

collect2: error: ld returned 1 exit status
Error: linker exited with status 1

When I inspect the object files, I see the following:
a.o
-
void func1(int*)
void func2(int const*)
void func3(int*, int const*)
void func4(int const*, int*)
func5(int*, int const*)
func6(int const*, int*)
-

main.o
-
void func1(int*)
void func2(int const*)
void func3(int*, int*)
void func4(int const*, int const)
func5(int*, int const*)
func6(int const*, int*)
-

It appears that func3 and func4 take on different types depending 
on other variables being present? Is this expected? Why do they 
differ from the non-templated functions func5 and func6 
respectively? How should I achieve this instead?




Re: Filling an associated array of associated arrays

2020-01-14 Thread Jamie via Digitalmars-d-learn

On Tuesday, 14 January 2020 at 23:59:59 UTC, mipri wrote:

On Tuesday, 14 January 2020 at 23:23:51 UTC, Jamie wrote:

c.f. https://issues.dlang.org/show_bug.cgi?id=17607

I found that by searching the forums for your error.


That has fixed my issue. I had searched the forums for relevant 
topics, but not the error itself. A lesson for me.


Cheers


Filling an associated array of associated arrays

2020-01-14 Thread Jamie via Digitalmars-d-learn
I'm trying to initialise an associated array of associated arrays 
with values, taking the same approach I would for an associated 
array:


string[string][string] table = [
"info" : [
"equation" : "H2 + I2 <=> 2HI",
"type" : "elementary",
],
"frc" : [
"A" : "1.2e9",
"n" : "1.2e9",
"C" : "1.2e9",
],
];

But I'm getting the error `Not an associative array initializer'.
Is there a way to do this in the fashion that I'm trying?

I can declare it like

string[string][string] table;
table["info"]["equation"] = "H2 + I2 <=> 2HI";
table["info"]["type"] = "elementary";

But don't see why the first way wouldn't work.



Re: Old code no longer working on any DMD compilers

2019-09-06 Thread Jamie via Digitalmars-d-learn
On Friday, 6 September 2019 at 00:41:12 UTC, Jonathan M Davis 
wrote:
On Thursday, September 5, 2019 6:24:07 PM MDT Jamie via 
Digitalmars-d-learn wrote:


/home/jamie/.dvm/compilers/dmd-2.077.0/linux/bin/../../src/phobos/std/math
.d(3702): Error: fmodl cannot be interpreted at compile time, 
because it
has no available source code called from here: called from 
here:

fmod(cast(real)to(n),
cast(real)to(2))

Thanks


Based on that implementation, fmod would work at compile time 
if you compile on Windows and use Microsoft's runtime instead 
of Digital Mars runtime (so, if it was compiled as 64-bit or it 
used whatever the flag is to force the COFF format instead of 
OMF for 32-bit). It won't work on any other platform at compile 
time, because core.stdc.math.fmodl is a C function, and C 
functions cannot be called at compile time.


By any chance were you compiling this on Windows previously 
rather than Linux? If so, that's likely why the code worked 
before and doesn't now. If you were always compiling on Linux, 
then I don't know why you were able to compile your code 
before. A quick glance at the repo history shows that fmod has 
had that same implementation since 2012, so there should be no 
way that it was callable on any Linux system even 6 years ago, 
let alone 6 months ago.


- Jonathan M Davis


Thanks for the reply. I haven't used Windows in the past two 
years so that isn't the issue in my case. After your comments I 
looked deeper, and I think my issue is related to compile time 
values, and me misunderstanding default arguments for structs.


import std.stdio;
import std.conv: to;
import std.math: fmod;

void main()
{
/// without default arguments
S s = S(64, 64);// case 1: works
// static S s = S(64, 64); // case 2: doesn't work

/// with default arguments
// static S s = S();   // case 3: works
}

struct S
{
this(size_t N, size_t M) {
// this(size_t N=64, size_t M=64) {
f(N, M);
}
}

void f(size_t N, size_t M)
{
int kj(int n)
{
return to!int(fmod(n, 2));
}
int k = kj(2);
}

If I'm understanding it correctly now, in case 1 the struct 
constructor isn't called at compile time, so the underlying C 
function (fmod) is not called. In case 2 because the struct is 
called in a static region, the constructor is called at compile 
time and fmod is called so it breaks. In case 3, with default 
struct arguments, I thought that the constructor I have defined 
was being called, however the default constructor was being 
called (this()) so fmod wasn't being called.


The reason why my old code worked was because it used the default 
arguments and I wasn't actually calling the constructor I 
defined. When I removed the default arguments in the constructor 
and tried case 2 it obviously didn't work.


Am I understanding correctly? Thanks




Old code no longer working on any DMD compilers

2019-09-05 Thread Jamie via Digitalmars-d-learn
I just picked up some of my old code that was working when I last 
used it (approximately 6 months ago) but now is no longer 
working. I thought it was due to using an updated compiler, so I 
have installed many old compilers in and attempt to make it work, 
but no luck. Using DVM I have tried 2.077.0, 2.078.0, 2.079.0, 
2.087.0, 2.088.0, and I think I was using 2.079.0 at the time, 
but none of these have worked. The actual issue is:


/home/jamie/.dvm/compilers/dmd-2.077.0/linux/bin/../../src/phobos/std/math.d(3702):
 Error: fmodl cannot be interpreted at compile time, because it has no 
available source code
called from here: called from here: fmod(cast(real)to(n), 
cast(real)to(2))


and

/home/jamie/.dvm/compilers/dmd-2.077.0/linux/bin/../../src/druntime/import/object.d(3067):
 Error: _d_arraysetcapacity cannot be interpreted at compile time, because it 
has no available source code
called from here: reserve(i_n, 1LU << cast(int)((p + 1LU) * 1LU))

I've looked in the directory it provides and as far as I can tell 
the code does exist. I.e. in std.math:

real fmod(real x, real y) @trusted nothrow @nogc
{
version (CRuntime_Microsoft)
{
return x % y;
}
else
return core.stdc.math.fmodl(x, y);
}

and in core.stdc.math:
   ///
double  fmod(double x, double y);
///
float   fmodf(float x, float y);
///
extern(D) real fmodl()(real x, real y) { return 
fmod(cast(double) x, cast(double) y); }


Thanks


Alias function with arguments

2019-07-10 Thread Jamie via Digitalmars-d-learn
Is it possible to alias a function and its arguments, but for 
that function to only be evaluated when the alias is used? For 
example


alias pragma(inline, true) inline

inline
void func(){}


Re: How to delete element from array container or dlist?

2019-04-26 Thread Jamie via Digitalmars-d-learn

On Sunday, 18 March 2018 at 16:14:06 UTC, Michael wrote:

On Sunday, 18 March 2018 at 15:42:18 UTC, Andrey Kabylin wrote:

On Sunday, 18 March 2018 at 15:32:47 UTC, Michael wrote:
On Sunday, 18 March 2018 at 14:58:52 UTC, Andrey Kabylin 
wrote:
In DList we have method remove, but I can't understand how 
this method works, I want write somethink like this:

void unsubscribe(EventsSubscriber subscriber) {
subscribers.remove(subscriber);
}


So I guess you would want something like

subscribers.remove!(a => a == subscriber));

which is the different definition of remove available here:
https://dlang.org/phobos/std_algorithm_mutation.html#.remove.2


Yes this works, thanks!


No problem, glad to help!


Just an FYI:
This didn't work as I expected -- the length of subscribers 
didn't change. What I needed here was

subscribers = subscribers.remove!(a => a == subscriber));

Otherwise this sort of behaviour resulted:
// code:
struct A {int i;}
A[] as = [A(1), A(2), A(3)];
writeln("as = ", as);
writeln(remove!(a => a == A(2))(as));
writeln("as = ", as);
writeln(remove!(a => a == A(3))(as));
writeln("as = ", as);

// output:
as = [A(1), A(2), A(3)]
[A(1), A(3)]
as = [A(1), A(3), A(3)]
[A(1)]
as = [A(1), A(3), A(3)]




Re: Do @property attributes not allow postincrement operators

2019-04-13 Thread Jamie via Digitalmars-d-learn

On Sunday, 14 April 2019 at 02:11:52 UTC, Mike Franklin wrote:

On Sunday, 14 April 2019 at 01:54:39 UTC, Jamie wrote:

Do @property attributes not allow postincrement operators?
...


It's a long standing issue (going on 7 years old)
...
I plan on getting to it, but there are other pressing things 
I'm trying to get out of the way.


Mike


Thanks Mike -- appears I didn't do a thorough enough search for 
this behaviour. Looking forward to it being implemented, cheers.


Do @property attributes not allow postincrement operators

2019-04-13 Thread Jamie via Digitalmars-d-learn

Do @property attributes not allow postincrement operators?

import std.stdio;

struct Foo {
@property bar() { return 10; }
@property bar(int x) { writeln(x); }
}

void main()
{
Foo foo;
writeln(foo.bar); // actually calls foo.bar();
foo.bar = 10; // calls foo.bar(10);

// following doesn't work
foo.bar++; // would expect this to call foo.bar(foo.bar() + 
1);

// have to use:
foo.bar = foo.bar + 1;
writeln(foo.bar);
}


Re: Are static variables available to other static variables?

2019-04-12 Thread Jamie via Digitalmars-d-learn

On Friday, 12 April 2019 at 10:49:19 UTC, Jamie wrote:
I was trying to declare a static variable dependent on another 
static variable, but it didn't work. Are static variables not 
known to other static variables at compile time?


void main()
{   
C c = new C();
}

class C
{
static size_t A = 2;
static size_t B = 2^^A; // A is not known at compile time
}


Ok I'm confused... why does that above not work but this does:

void main()
{   
C c = new C();
}
class C
{
static size_t A = 2;
static size_t B;
static this()
{
B = 2^^A;
}
}


Are static variables available to other static variables?

2019-04-12 Thread Jamie via Digitalmars-d-learn
I was trying to declare a static variable dependent on another 
static variable, but it didn't work. Are static variables not 
known to other static variables at compile time?


void main()
{   
C c = new C();
}

class C
{
static size_t A = 2;
static size_t B = 2^^A; // A is not known at compile time
}



Simultaneously assigning to all values in a tuple

2019-03-27 Thread Jamie via Digitalmars-d-learn
Is it possible to assign to all values in a tuple at once if they 
are the same type?

I.e.

Tuple!(double, "x", double, "y") t;
t[] = 1.0;



Re: Inherit from class based on bool value

2018-11-13 Thread Jamie via Digitalmars-d-learn

On Tuesday, 13 November 2018 at 07:29:30 UTC, Ali Çehreli wrote:

On 11/12/2018 11:10 PM, Jamie wrote:
> I would like my class to inherit from one of two classes ...
> Is this possible? I can't get it to work in the way I'm
showing above.
> Cheers

I got it working inside an eponymous template. D is pretty cool 
actually. :)


enum OPTION
{
FALSE = 0.,
TRUE = 1.
}

class One
{}

class Two
{}

template Top(OPTION option) {
static if (option == OPTION.TRUE) {
alias Base = One;

} else {
alias Base = Two;
}

class Top : Base
{}
}

void main() {
auto a = new Top!(OPTION.FALSE);
auto b = new Top!(OPTION.TRUE);
}

Ali


Wow that's nifty, thanks very much! And thanks for the speedy 
response


Inherit from class based on bool value

2018-11-12 Thread Jamie via Digitalmars-d-learn
I would like my class to inherit from one of two classes based on 
a boolean value known at compile time. Something like this:


void main()
{
Top!(OPTION.FALSE) top = new Top!(OPTION.FALSE);
}

enum OPTION
{
FALSE = 0.,
TRUE = 1.
}

class One
{}

class Two
{}

class Top(OPTION option) : option ? One : Two
{}

Is this possible? I can't get it to work in the way I'm showing 
above.

Cheers


Re: Error calling geqrs function from lubeck package.

2018-04-16 Thread Jamie via Digitalmars-d-learn

On Tuesday, 17 April 2018 at 03:26:25 UTC, Jamie wrote:


Sorry it's really an error calling geqrs function from mir-lapack 
package.





Error calling geqrs function from lubeck package.

2018-04-16 Thread Jamie via Digitalmars-d-learn
I'm attempting to use the lubeck package, as described here 
https://forum.dlang.org/post/axacgiisczwvygyef...@forum.dlang.org


I have lubeck, mir-algorithm, mir-blas, mir-lapack downloaded and 
accessible by the compiler, and I have installed liblapack-dev 
and libblas-dev.


When I attempt to run the example for geqrs, 
https://github.com/libmir/mir-lapack/blob/master/examples/geqrs/source/app.d , I get the following error


undefined reference to 'dgeqrs_'

Note that the issue comes from the line
geqrs(A_, B_, tau_, work_);

but the previous line works
geqrf(A_, tau_, work_);

After following the calls between the different packages and 
files, I find that the issue is likely the fact that

sgeqrf.o
dgeqrf.o
cgeqrf.o
zgeqrf.o

all exist in the liblapack-dev library and are hence callable, but
sgeqrs.o
dgeqrs.o
cgeqrs.o
zgeqrs.o

do not exist, and hence are not callable.

Is this an issue with mir-lapack? The fact that it is calling 
files/ functions that do not exist? Or is my version of 
liblapack-dev the incorrect one, as it doesn't contain the files/ 
functions being called?


Note that if I don't call the function geqrs(..); my code works, 
so I believe that I have set-up the mir- files correctly.


Re: Passing directory as compiler argument not finding file

2018-04-12 Thread Jamie via Digitalmars-d-learn

On Thursday, 12 April 2018 at 06:30:25 UTC, Tony wrote:

On Thursday, 12 April 2018 at 05:39:21 UTC, Jamie wrote:


Am I using the -I compiler option incorrectly?


I believe so. I think it is for finding import files, not the 
files you are compiling.


-
-I=directory
 Look for imports also in directory


Ahh yes I think you are correct. It sounds silly that I was 
compiling from a different spot to my file, but it was to 
demonstrate my situation. Really, it's more like:


A/
 a.d
module A.a;
import std.stdio;
import B.b;
void main()
{
writeln(f(4));
}
B/
 b.d
module B.b;
size_t f(size_t input)
{
return input * 2;
}

And in A/ I'm compiling
dmd -ofoutput a.d ../B/b.d

and instead I was thinking I could compile with
dmd -ofoutput a.d -I../B b.d

and would get the same result. The former works, the latter does 
not. Is there something like this that I can use or do I have to 
pass all the files with the direct path to them? Thanks




Passing directory as compiler argument not finding file

2018-04-11 Thread Jamie via Digitalmars-d-learn

With a directory structure as follows:

run/
A/
a.d

Where a.d is:
===
module A.d;


I'm attempting to compile from the run/ directory. If I run with
dmd ../A/a.d

it compiles successfully, however if I pass it the directory
dmd -I=../A a.d

it doesn't compile. Also, if I pass the exact directory
dmd -I=/../A a.d

it doesn't compile.

Both times I get the error
Error: module `a` is in the file 'a.d' which cannot be read

However it then shows the import path as being
import path[0] = ../A

for the first way and
import path[0] = /../A
for the second way.

Am I using the -I compiler option incorrectly?


Re: Assigning to slice of array

2018-03-01 Thread Jamie via Digitalmars-d-learn

On Thursday, 1 March 2018 at 23:17:11 UTC, Jonathan M Davis wrote:

So, something like

auto arr = new int[][][](3, 2, 1);
arr.length = 4;
arr[0].length = 5;
arr[0][0].length = 6;

is legal, but something like


Thanks Jonathan, this is exactly what I was looking for. I was 
getting confused with not being able to resize because I was 
looking at int[] arrays and I guess the way I was defining them 
caused them both to be dynamic (when I thought one was static).


On a similar not, is there an accepted way to assign across 
arrays? As Steve mentioned, cross-slicing isn't supported, so is 
the best way to iterate through the array and assign as necessary?

Thanks, Jamie







Re: Assigning to slice of array

2018-03-01 Thread Jamie via Digitalmars-d-learn

On Thursday, 1 March 2018 at 21:34:41 UTC, Jonathan M Davis wrote:

Don't put the indices within the brackets. What you want is

auto arr = new int[][][](3, 2, 1);


Okay thanks, but I don't understand what is the issue with having 
static arrays there instead? My functionality didn't change when 
I replaced the single line with your line?


And I couldn't resize either of them with array.length, which is 
also something I would like.

Thanks




Re: Assigning to slice of array

2018-03-01 Thread Jamie via Digitalmars-d-learn
On Thursday, 1 March 2018 at 21:31:49 UTC, Steven Schveighoffer 
wrote:
No, I think you did int[3][2], if you got that output. 
Otherwise it would have been:


[[[0,0,0],[0,0,0]]]


Yes apologies that was there from a previous attempt, you are 
correct.


Well, that's because that type of slicing isn't supported 
directly. You can't slice an array cross-wise like that.


You may be interested in ndslice inside mir: 
http://docs.algorithm.dlang.io/latest/mir_ndslice.html


Thanks I've just had a quick read and this looks promising for 
what I want (similar functionality to numpy), but I also want to 
understand arrays.



when I try
     arr[0 .. 2][0] = 3;   // which I think is equivalent to 
arr[0][0]


Consider the array:

int[] x = new int[2];

Now, what would the slice x[0 .. 2] be? That's right, the same 
as x.


So when you slice arr[0 .. 2], it's basically the same as arr 
(as arr has 2 elements).


So arr[0 .. 2][0] is equivalent to arr[0].


So if I do
arr[0 .. 1][0] = 3;
shouldn't this return
[[3, 0, 0], [0, 0, 0]] ? Because I'm taking the slice arr[0 
.. 1], or arr[0], which is the first [0, 0, 0]? Then assigning 
the first element to 3?

instead it returns
[[3, 3, 3], [0, 0, 0]]

One thing that is interesting is that you assigned 3 to an 
array, and it wrote it to all the elements. I did not know you 
could do that with static arrays without doing a proper slice 
assign. But it does compile (I learn something new every day).


-Steve

Well I'm learning a lot today :)




Assigning to slice of array

2018-03-01 Thread Jamie via Digitalmars-d-learn
I'm trying to understand arrays and have read a lot of the 
information about them on this forum. I think I understand that 
they are set-up like Type[], so that int[][] actually means an 
array of int[].


I create an array as per the following:
auto arr = new int[3][2][1];
which produces:
[[0, 0, 0], [0, 0, 0]]
(for each of the following assignments, assume that the array is 
set back to zeros)


and I can change the 2nd element of the 1st array using:
arr[0][1] = 4;
which produces:
[[0, 4, 0], [0, 0, 0]]

and I can change the entire 1st array using:
arr[0][0 .. 3] = 5;
which produces:
[[5, 5, 5], [0, 0, 0,]]

however when I try and change elements across arrays rather than 
within arrays my understanding breaks down.. when I try
arr[0 .. 2][0] = 3;   // which I think is equivalent to 
arr[0][0] and arr[1][0]

I'm expecting:
[[3, 0, 0], [3, 0, 0]]
but it produces:
[[3, 3, 3], [0, 0, 0]]
showing that arr[0][0 .. 2] is making the same index as arr[0 .. 
3][0] ?


Instead of using [0 .. 2] I can use the actual indices to get the 
result I desired:

arr[0][0] = 3;
arr[1][0] = 3;
which produces:
[[3, 0, 0], [3, 0, 0]]

Could I just get some help with understanding how the slice [0 .. 
2] actually works? Thanks


Re: Using file as input to stdin when compiling

2018-02-05 Thread Jamie via Digitalmars-d-learn

On Tuesday, 6 February 2018 at 06:10:30 UTC, Jamie wrote:
Hi, I'm following through TDPL and am trying to import a txt 
file during compiling for the stdin.byLine() function to read. 
Currently I have


#!/usr/bin/rdmd and would like it to analyse the supplied text file. Is this 
possible in the way that I'm thinking, or is there another way?


Thanks


I've figured out how to do it if I don't use the 1st line above, 
and manually compile and then execute:


$ rdmd code.d < file.txt

but still can't do it through the code file.



Using file as input to stdin when compiling

2018-02-05 Thread Jamie via Digitalmars-d-learn
Hi, I'm following through TDPL and am trying to import a txt file 
during compiling for the stdin.byLine() function to read. 
Currently I have


#!/usr/bin/rdmd and would like it to analyse the supplied text file. Is this 
possible in the way that I'm thinking, or is there another way?


Thanks