Re: How to import modules from another folder ?

2020-05-13 Thread Vinod K Chandran via Digitalmars-d-learn

On Wednesday, 13 May 2020 at 22:10:02 UTC, Vinod K Chandran wrote:

Hi all,
I am practicing some win32 api coding in D. So far so good. But 
when i tried to import some d files from another folder, i 
wonder how do this. This is my folder structure.


--> Source Folder
--> app.d  //This is my main file. I am importing 
guiLib in this main file.
--> guiLib.d // This file contains some public imports 
like, Gui.d, Button.d etc

--> LibFolder // this is a folder
-> Gui.d
-> Button.d
-> Label.d

Do i need to pass the exact path ?


Hi all,
Sorry for bothering you. I think i found the answer myself.
If a d file which you want to import in your main file is in 
another directory, then just write this - "import 
YourDirectory.YourFile"


How to import modules from another folder ?

2020-05-13 Thread Vinod K Chandran via Digitalmars-d-learn

Hi all,
I am practicing some win32 api coding in D. So far so good. But 
when i tried to import some d files from another folder, i wonder 
how do this. This is my folder structure.


--> Source Folder
--> app.d  //This is my main file. I am importing guiLib 
in this main file.
--> guiLib.d // This file contains some public imports 
like, Gui.d, Button.d etc

--> LibFolder // this is a folder
-> Gui.d
-> Button.d
-> Label.d

Do i need to pass the exact path ?



Re: Compilation error

2020-05-13 Thread chrissutton via Digitalmars-d-learn

On Wednesday, 7 October 2015 at 12:24:49 UTC, Loic wrote:

On Wednesday, 7 October 2015 at 12:08:08 UTC, Loic wrote:

On Tuesday, 15 September 2015 at 15:25:27 UTC, Loic wrote:
On Tuesday, 15 September 2015 at 12:37:46 UTC, Adam D. Ruppe 
wrote:

[...]


Hello Adam,

I installed with the exe installer, and set my path to 
C:\D\dmd2\windows\bin

Maybe I forget to configure some file(s) ?

Thank you

Loic


I'am still trying to resolve my issue on Windows 7 64 bits.
No one have an idea about this error ?

Thank you

Best

Loic


Finally, I found the solution, by just changed the entry of 
"Environment" in sc.ini.


sorry

Thank you

Loic


change it to what you fkin retard? people like you deserve a 
bullet


Re: How should I move in a DList ?

2020-05-13 Thread Gabriel via Digitalmars-d-learn
On Wednesday, 13 May 2020 at 14:29:53 UTC, Steven Schveighoffer 
wrote:
I would never recommend either DList or SList for actual linked 
lists (for stacks or queues, they are OK), as they are very 
unweildy and don't do what most people want linked lists to do.


-Steve

[1] https://github.com/schveiguy/dcollections


Thanks a lot for this answer, I think the doubly-linked-list I 
found on Rosetta Code will do the job.


[GTK-D] dub run leads to lld-link: error: could not open libcmt.lib: no such file or directory

2020-05-13 Thread BoQsc via Digitalmars-d-learn

A simple example I tried to run.

#!/usr/bin/env dub
/+ dub.sdl:
name "hello"
dependency "gtk-d" version="~>3.9.0"
+/

import gtk.MainWindow;
import gtk.Label;
import gtk.Main;

void main(string[] args)
{
Main.init(args);
MainWindow win = new MainWindow("Hello World");
win.setDefaultSize(200, 100);
win.add(new Label("Hello World"));
win.showAll();
Main.run();
}


This is how I tried to run it.

C:\Users\vaida\Desktop\Command prompt shell>dub run --single gui.d
Performing "debug" build using C:\D\dmd2\windows\bin\dmd.exe for 
x86_64.
gtk-d:gtkd 3.9.0: target for configuration "library" is up to 
date.
gtk-d:gstreamer 3.9.0: target for configuration "library" is up 
to date.
gtk-d:peas 3.9.0: target for configuration "library" is up to 
date.

gtk-d:sv 3.9.0: target for configuration "library" is up to date.
gtk-d:vte 3.9.0: target for configuration "library" is up to date.
hello ~master: building configuration "application"...
Linking...
lld-link: error: could not open libcmt.lib: no such file or 
directory
lld-link: error: could not open OLDNAMES.lib: no such file or 
directory

Error: linker exited with status 1
C:\D\dmd2\windows\bin\dmd.exe failed with exit code 1.


Re: Error running concurrent process and storing results in array

2020-05-13 Thread wjoe via Digitalmars-d-learn

On Friday, 8 May 2020 at 13:43:40 UTC, data pulverizer wrote:
[...] I also chose kernel matrix calculations, you can't always 
call a library, sometimes you just need to write performant 
code.


Aren't kernel function calls suffering a context switch though ?


Re: How should I move in a DList ?

2020-05-13 Thread Steven Schveighoffer via Digitalmars-d-learn

On 5/13/20 5:57 AM, Gabriel wrote:

Hello,

As I am totally new to D (my background is mainly C++) I am having 
trouble porting an algorithm that simplifies a polyline in 2D, very 
similar to this one: http://psimpl.sourceforge.net/reumann-witkam.html


Here is what I would like:
1) Use a doubly-linked list, preferably one from a standard library (I 
need fast insertion/removal anywhere inside the list).
2) Have multiple "cursors" (ref to a list node, pointers, iterators 
etc.) that I move forward in my list when needed.
3) Remove and add some elements in the list (at/between "cursor" 
positions).


I am fine with having "unsafe" code for this example (the function is 43 
lines long in C++, does not have too many cases and would be tested on a 
lot of data).


What "cursor" should I use to get something similar to C++'s std::list's 
iterators, or C#'s LinkedListNode that I was able to use to port the 
algorithm in C++ and C# ? (I am benching languages).




This is one of the things I wanted when I made dcollections [1] 
(probably not working today due to 10+ years of bitrot).


In dcollections, a "cursor" was what you got when you did any operations 
that would return an iterator normally in C++.


A cursor was a one-element range, with only a reference to that one 
element. It can't be advanced further than "after" the given element, 
and so is safe like a range. So it's a bit different from C++, because 
you can't iterate with cursors, you iterate with ranges. But you can 
convert back and forth from those things easily.


For example:

auto ll = new LinkList!int(1, 2, 3, 4, 5);

auto r = ll[]; // get a range
assert(r.front == 1);

auto cursor = r.begin;
ll.insert(cursor, 5);

assert(ll[].equal([5, 1, 2, 3, 4, 5]);

r = ll[].find(3);
// move back one

r = ll[ll.begin .. r.begin];
assert(r.back == 2);

Andrei was not keen on incorporating such a concept in Phobos, so it's 
not really present in the main library, instead you have to do some 
strange things with range acrobatics. If you want to move forward, you 
have to use popFront. If you want to move backwards, you are out of luck 
(unless you are interested in moving back from the end of the list).


I would never recommend either DList or SList for actual linked lists 
(for stacks or queues, they are OK), as they are very unweildy and don't 
do what most people want linked lists to do.


-Steve

[1] https://github.com/schveiguy/dcollections


Re: Sum string lengths

2020-05-13 Thread MoonlightSentinel via Digitalmars-d-learn

On Wednesday, 13 May 2020 at 13:52:13 UTC, Andrey wrote:

Hi,
I want to sum lengths of all strings in array:

auto data = ["qwerty", "az", ""];


Fold and reduce doesn't work:

auto result = data.fold!`a + b.length`(0U);


gives error:
static assert:  "Incompatible function/seed/element: 
binaryFun/uint/string"


How to do it in one line?


The problem is that you provide a uint as seed (which determines 
the type of the accumulated value) but your function returns a 
ulong (or rather size_t).


You can fix this by changing the type of your seed, either use 
ulong or size_t.


auto result = data.fold!`a + b.length`(0UL);

auto result = data.fold!`a + b.length`(size_t(0));


Re: Sum string lengths

2020-05-13 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 13, 2020 at 01:52:13PM +, Andrey via Digitalmars-d-learn wrote:
> Hi,
> I want to sum lengths of all strings in array:
> > auto data = ["qwerty", "az", ""];

data.map!(s => s.length).sum;


T

-- 
It only takes one twig to burn down a forest.


Sum string lengths

2020-05-13 Thread Andrey via Digitalmars-d-learn

Hi,
I want to sum lengths of all strings in array:

auto data = ["qwerty", "az", ""];


Fold and reduce doesn't work:

auto result = data.fold!`a + b.length`(0U);


gives error:
static assert:  "Incompatible function/seed/element: 
binaryFun/uint/string"


How to do it in one line?


Re: How to port C++ std::is_reference to D ?

2020-05-13 Thread wjoe via Digitalmars-d-learn

On Monday, 11 May 2020 at 19:08:09 UTC, Q. Schroll wrote:

[...]

1. You can have variables ("data members") of reference type in 
structs. (They work like head-const pointers; if D had 
head-const or at least head-const pointers, those would be 
practically the same, only that references cannot be null.)

[...]



That's also something I don't really know how to correctly port 
to D.
Anyways, that was insightful. Thank you very much for your 
explanations.


Re: declaration of inner function is already defined

2020-05-13 Thread Paul Backus via Digitalmars-d-learn

On Wednesday, 13 May 2020 at 13:18:58 UTC, Andrey wrote:

On Wednesday, 13 May 2020 at 12:58:11 UTC, Adam D. Ruppe wrote:

On Wednesday, 13 May 2020 at 12:45:06 UTC, Andrey wrote:

Why this works:


It's just defined that way. Local functions follow local 
variable rules - must be declared before use and names not 
allowed to overload each other.


There might be a deeper reason too but like that's the main 
thing, they just work like any other local vars.


Overload for local functions will be very useful thing. 
Otherwise it is PHP or C.


If you want to define a set of overloaded functions inside 
another function, you can do it like this:


void main() {
import std.stdio: writeln;

static struct Overloads {
static void fun(int n) { writeln("int overload"); }
static void fun(string s) { writeln("string overload"); }
}
alias fun = Overloads.fun;

fun(123); // int overload
fun("hello"); // string overload
}


Re: declaration of inner function is already defined

2020-05-13 Thread Andrey via Digitalmars-d-learn

On Wednesday, 13 May 2020 at 12:58:11 UTC, Adam D. Ruppe wrote:

On Wednesday, 13 May 2020 at 12:45:06 UTC, Andrey wrote:

Why this works:


It's just defined that way. Local functions follow local 
variable rules - must be declared before use and names not 
allowed to overload each other.


There might be a deeper reason too but like that's the main 
thing, they just work like any other local vars.


Overload for local functions will be very useful thing. Otherwise 
it is PHP or C.


Re: declaration of inner function is already defined

2020-05-13 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 13 May 2020 at 12:45:06 UTC, Andrey wrote:

Why this works:


It's just defined that way. Local functions follow local variable 
rules - must be declared before use and names not allowed to 
overload each other.


There might be a deeper reason too but like that's the main 
thing, they just work like any other local vars.


declaration of inner function is already defined

2020-05-13 Thread Andrey via Digitalmars-d-learn

Hi,

Why this works:
void setBases(string type)(ref int data, string base, string[] 
syllables)

{

}

void setBases(string type, T)(ref int data, const ref T source)
{

}

void main()
{
int q = 6;
setBases!"tt"(q, "qwerty", ["tg", "jj"]);
setBases!"tt"(q, q);
}


and this doesn't work:

void main()
{
void setBases(string type)(ref int data, string base, 
string[] syllables)

{

}

void setBases(string type, T)(ref int data, const ref T 
source)

{

}

int q = 6;
setBases!"tt"(q, "qwerty", ["tg", "jj"]);
setBases!"tt"(q, q);
}


The error is:
declaration setBases(string type, T)(ref int data, ref const T 
source) is already defined


?


Handle FormatSpec!char in the virtual toString() method of a class.

2020-05-13 Thread realhet via Digitalmars-d-learn

Hello,

Is there a way to the following thing in a class instead of a 
struct?


--
static struct Point
{
int x, y;

void toString(W)(ref W writer, scope const ref 
FormatSpec!char f)

if (isOutputRange!(W, char))
{
// std.range.primitives.put
put(writer, "(");
formatValue(writer, x, f);
put(writer, ",");
formatValue(writer, y, f);
put(writer, ")");
}
}
--

I think the problem is that the toString() in a class is virtual, 
and don't let me to have multiple overloaded methods.


Is there a way to let format() deal with classes too?

Thank You!


How should I move in a DList ?

2020-05-13 Thread Gabriel via Digitalmars-d-learn

Hello,

As I am totally new to D (my background is mainly C++) I am 
having trouble porting an algorithm that simplifies a polyline in 
2D, very similar to this one: 
http://psimpl.sourceforge.net/reumann-witkam.html


Here is what I would like:
1) Use a doubly-linked list, preferably one from a standard 
library (I need fast insertion/removal anywhere inside the list).
2) Have multiple "cursors" (ref to a list node, pointers, 
iterators etc.) that I move forward in my list when needed.
3) Remove and add some elements in the list (at/between "cursor" 
positions).


I am fine with having "unsafe" code for this example (the 
function is 43 lines long in C++, does not have too many cases 
and would be tested on a lot of data).


What "cursor" should I use to get something similar to C++'s 
std::list's iterators, or C#'s LinkedListNode that I was able to 
use to port the algorithm in C++ and C# ? (I am benching 
languages).


Thanks in advance,



Re: Get unknown symbol (struct, method, class) tagged with User Defined Attributes

2020-05-13 Thread Jacob Carlborg via Digitalmars-d-learn

On 2020-05-12 06:02, Steven Schveighoffer wrote:

If you want a list of ALL symbols that have the UDA in the application, 
that would require some form of runtime reflection (like Java). D has 
very limited support for runtime reflection. In D, you would use some 
form of registration to tell the system about your symbols.


I think it's possible to implement the `RTInfo` template in `object.d`. 
But that requires a custom druntime.


`RTInfo` is a template that is instantiated once for each type in the 
program.


--
/Jacob Carlborg