Re: FIFO

2024-05-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Monday, 13 May 2024 at 15:07:39 UTC, Andy Valencia wrote:

On Sunday, 12 May 2024 at 22:03:21 UTC, Ferhat Kurtulmuş wrote:

https://dlang.org/phobos/std_container_slist.html

This is a stack, isn't it?  LIFO?

Ahh yes. Then use dlist


Thank you.  I read its source, and was curious so I wrote a 
small performance measurement: put 10,000 things in a FIFO, 
pull them back out, and loop around that 10,000 times.  My FIFO 
resulted in:


real0m1.589s
user0m1.585s
sys 0m0.004s

And the dlist based one:

real0m4.731s
user0m5.211s
sys 0m0.308s

Representing the FIFO as a linked list clearly has its cost, 
but I found the increased system time interesting.  OS memory 
allocations maybe?


The code is spaghetti, fifo/dlist, but it seemed the easiest 
way to see the two API's being used side by side:


version(fifo) {
import tiny.fifo : FIFO;
} else {
import std.container.dlist : DList;
}

const uint ITERS = 10_000;
const uint DEPTH = 10_000;

void
main()
{
version(fifo) {
auto d = FIFO!uint();
} else {
auto d = DList!uint();
}
foreach(_; 0 .. ITERS) {
foreach(x; 0 .. DEPTH) {
version(fifo) {
d.add(x);
} else {
d.insertBack(x);
}
}
foreach(x; 0 .. DEPTH) {
version(fifo) {
assert(x == d.next());
} else {
assert(x == d.front());
d.removeFront();
}
}
}
}


thank you for sharing the results. Everything I read about queues 
recommends doublylinked lists. With your array based 
implementatio if you are consuming the elements faster than 
pushing new elements, your array buffer never resize which is 
costly. This should explain why your array based queue is more 
performant.


Re: Find homography in D?

2024-05-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Sunday, 21 April 2024 at 14:57:33 UTC, Paolo Invernizzi wrote:

Hi,

Someone can point me to a D implementation of the classical 
OpenCV find homography matrix?


Thank you,
Paolo


Now, we can do image stitching using DCV. It needs improvements 
though.


https://github.com/libmir/dcv/tree/master/examples/imagestitchinghomography


Re: FIFO

2024-05-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Saturday, 11 May 2024 at 23:44:28 UTC, Andy Valencia wrote:
I need a FIFO for a work scheduler, and nothing suitable jumped 
out at me.  I wrote the following, but as a newbie, would be 
happy to receive any suggestions or observations.  TIA!


[...]


I don't know your use case, maybe you have a similar problem I 
had to solve years ago.


https://forum.dlang.org/post/xktftztisodpngcow...@forum.dlang.org


Re: FIFO

2024-05-12 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Sunday, 12 May 2024 at 21:08:24 UTC, Andy Valencia wrote:

On Sunday, 12 May 2024 at 19:45:44 UTC, Ferhat Kurtulmuş wrote:

On Saturday, 11 May 2024 at 23:44:28 UTC, Andy Valencia wrote:
I need a FIFO for a work scheduler, and nothing suitable 
jumped out at me.

...
https://dlang.org/phobos/std_container_slist.html


This is a stack, isn't it?  LIFO?

Andy


Ahh yes. Then use dlist


Re: FIFO

2024-05-12 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Saturday, 11 May 2024 at 23:44:28 UTC, Andy Valencia wrote:
I need a FIFO for a work scheduler, and nothing suitable jumped 
out at me.  I wrote the following, but as a newbie, would be 
happy to receive any suggestions or observations.  TIA!


[...]


"next" is not a usual range primitive word in dlang. Why not just 
using slist.


Re: FIFO

2024-05-12 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Saturday, 11 May 2024 at 23:44:28 UTC, Andy Valencia wrote:
I need a FIFO for a work scheduler, and nothing suitable jumped 
out at me.  I wrote the following, but as a newbie, would be 
happy to receive any suggestions or observations.  TIA!


[...]

https://dlang.org/phobos/std_container_slist.html


Re: Find homography in D?

2024-04-30 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Sunday, 21 April 2024 at 14:57:33 UTC, Paolo Invernizzi wrote:

Hi,

Someone can point me to a D implementation of the classical 
OpenCV find homography matrix?


Thank you,
Paolo


Just for future records in the forum.

// 
https://math.stackexchange.com/questions/3509039/calculate-homography-with-and-without-svd


/+dub.sdl:
dependency "lubeck" version="~>1.5.4"
+/
import std;
import mir.ndslice;
import kaleidic.lubeck;

void main()
{
double[2] x_1 = [93,-7];
double[2] y_1 = [63,0];
double[2] x_2 = [293,3];
double[2] y_2 = [868,-6];
double[2] x_3 = [1207,7];
double[2] y_3 = [998,-4];
double[2] x_4 = [1218,3];
double[2] y_4 = [309,2];

auto A = [
-x_1[0], -y_1[0], -1, 0, 0, 0, x_1[0]*x_1[1], 
y_1[0]*x_1[1], x_1[1],
0, 0, 0, -x_1[0], -y_1[0], -1, x_1[0]*y_1[1], 
y_1[0]*y_1[1], y_1[1],
-x_2[0], -y_2[0], -1, 0, 0, 0, x_2[0]*x_2[1], 
y_2[0]*x_2[1], x_2[1],
0, 0, 0, -x_2[0], -y_2[0], -1, x_2[0]*y_2[1], 
y_2[0]*y_2[1], y_2[1],
-x_3[0], -y_3[0], -1, 0, 0, 0, x_3[0]*x_3[1], 
y_3[0]*x_3[1], x_3[1],
0, 0, 0, -x_3[0], -y_3[0], -1, x_3[0]*y_3[1], 
y_3[0]*y_3[1], y_3[1],
-x_4[0], -y_4[0], -1, 0, 0, 0, x_4[0]*x_4[1], 
y_4[0]*x_4[1], x_4[1],
0, 0, 0, -x_4[0], -y_4[0], -1, x_4[0]*y_4[1], 
y_4[0]*y_4[1], y_4[1]

].sliced(8, 9);

auto svdResult = svd(A);

auto homography = svdResult.vt[$-1].sliced(3, 3);
	auto transformedPoint = homography.mtimes([1679,  128, 
1].sliced.as!double.slice);

transformedPoint[] /= transformedPoint[2];

writeln(transformedPoint); //[4, 7, 1]
}


Re: Find homography in D?

2024-04-21 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Sunday, 21 April 2024 at 14:57:33 UTC, Paolo Invernizzi wrote:

Hi,

Someone can point me to a D implementation of the classical 
OpenCV find homography matrix?


Thank you,
Paolo


Kinda some work but it should be doable using DCV and mir.lubeck 
in theory


DCV can compute, not sift or surf b, but similar features 
https://github.com/libmir/dcv/blob/master/examples/features/source/app.d


Lubeck computes singular value decomposition
https://github.com/kaleidicassociates/lubeck

And this method but with mir ndslices

https://medium.com/all-things-about-robotics-and-computer-vision/homography-and-how-to-calculate-it-8abf3a13ddc5






Re: Statically compiled binary with C interop crashes.

2024-04-17 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Wednesday, 17 April 2024 at 11:03:22 UTC, yabobay wrote:
I'm using [dray](https://code.dlang.org/packages/dray) in my 
project with dub, here's the relevant parts of the dub.json:


[...]


İt seems your issue is related to the raylib itself, neither the 
binding you use nor the d programming language. İnstalling x11 
development package may resolve the issue.


Re: How to set include paths of a c source in dub when using importc

2024-04-17 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Wednesday, 17 April 2024 at 00:40:28 UTC, Alex Bryan wrote:
If you're not using gdc exclusively, you'll want to take a look 
at this: https://github.com/dlang/dub/pull/2818


I knew there was something wrong there.


Re: How to set include paths of a c source in dub when using importc

2024-04-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 13 April 2024 at 22:00:16 UTC, Ferhat Kurtulmuş 
wrote:
On Saturday, 13 April 2024 at 21:41:41 UTC, Ferhat Kurtulmuş 
wrote:
On Saturday, 13 April 2024 at 21:39:10 UTC, Ferhat Kurtulmuş 
wrote:
On Saturday, 13 April 2024 at 21:21:24 UTC, Richard (Rikki) 
Andrew Cattermole wrote:

[...]


Another question how can one define a preprocessor var for a 
c source from dub.json?


for instance: c source has #ifdef ORT_DLL_IMPORT

normally we do it like -D ORT_DLL_IMPORT


ohh I found it: -P


no this does not work:

"dflags": ["-P=SOME_FLAG"],

c1: fatal error C1083: Cannot open source file: 'SOME_FLAG': No 
such file or directory


The docs need an example. I was too stupid to figure this out 
quickly. "-P-DORT_DLL_IMPORT"


Re: How to set include paths of a c source in dub when using importc

2024-04-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 13 April 2024 at 21:41:41 UTC, Ferhat Kurtulmuş 
wrote:
On Saturday, 13 April 2024 at 21:39:10 UTC, Ferhat Kurtulmuş 
wrote:
On Saturday, 13 April 2024 at 21:21:24 UTC, Richard (Rikki) 
Andrew Cattermole wrote:

On 14/04/2024 8:59 AM, Ferhat Kurtulmuş wrote:


These don't work for me:

"dflags": ["-Iinclude"]

"importPaths": [
     "include"
],

The importc docs do not help either.


Appears it hasn't been documented in new dub docs.

It is ``cSourcePaths`` and ``cImportPaths``.

https://github.com/dlang/dub-docs/issues/91


Another question how can one define a preprocessor var for a c 
source from dub.json?


for instance: c source has #ifdef ORT_DLL_IMPORT

normally we do it like -D ORT_DLL_IMPORT


ohh I found it: -P


no this does not work:

"dflags": ["-P=SOME_FLAG"],

c1: fatal error C1083: Cannot open source file: 'SOME_FLAG': No 
such file or directory


Re: How to set include paths of a c source in dub when using importc

2024-04-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 13 April 2024 at 21:39:10 UTC, Ferhat Kurtulmuş 
wrote:
On Saturday, 13 April 2024 at 21:21:24 UTC, Richard (Rikki) 
Andrew Cattermole wrote:

On 14/04/2024 8:59 AM, Ferhat Kurtulmuş wrote:


These don't work for me:

"dflags": ["-Iinclude"]

"importPaths": [
     "include"
],

The importc docs do not help either.


Appears it hasn't been documented in new dub docs.

It is ``cSourcePaths`` and ``cImportPaths``.

https://github.com/dlang/dub-docs/issues/91


Another question how can one define a preprocessor var for a c 
source from dub.json?


for instance: c source has #ifdef ORT_DLL_IMPORT

normally we do it like -D ORT_DLL_IMPORT


ohh I found it: -P


Re: How to set include paths of a c source in dub when using importc

2024-04-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 13 April 2024 at 21:21:24 UTC, Richard (Rikki) 
Andrew Cattermole wrote:

On 14/04/2024 8:59 AM, Ferhat Kurtulmuş wrote:


These don't work for me:

"dflags": ["-Iinclude"]

"importPaths": [
     "include"
],

The importc docs do not help either.


Appears it hasn't been documented in new dub docs.

It is ``cSourcePaths`` and ``cImportPaths``.

https://github.com/dlang/dub-docs/issues/91


Another question how can one define a preprocessor var for a c 
source from dub.json?


for instance: c source has #ifdef ORT_DLL_IMPORT

normally we do it like -D ORT_DLL_IMPORT


Re: How to set include paths of a c source in dub when using importc

2024-04-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 13 April 2024 at 21:21:24 UTC, Richard (Rikki) 
Andrew Cattermole wrote:

On 14/04/2024 8:59 AM, Ferhat Kurtulmuş wrote:


These don't work for me:

"dflags": ["-Iinclude"]

"importPaths": [
     "include"
],

The importc docs do not help either.


Appears it hasn't been documented in new dub docs.

It is ``cSourcePaths`` and ``cImportPaths``.

https://github.com/dlang/dub-docs/issues/91


thank you Rikki.




How to set include paths of a c source in dub when using importc

2024-04-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn



These don't work for me:

"dflags": ["-Iinclude"]

"importPaths": [
"include"
],

The importc docs do not help either.


Re: How to add a character literal to a string without ~ operator?

2024-04-04 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Thursday, 4 April 2024 at 21:23:00 UTC, user1234 wrote:
On Thursday, 4 April 2024 at 19:56:50 UTC, Ferhat Kurtulmuş 
wrote:

[...]


```d
module runnable;

import std.stdio : writeln;
import std.range : chain;

void main() @nogc
{
auto s = chain("as ", "df ", "j"); // s is lazy
writeln(s);
}
```

Bad example. The range is indeed a `@nogc` lazy input range but 
`writeln` is not a `@nogc` consumer.



[...]


The input range consumer has to be @nogc as well.


I don't understand your point sorry. I didn't imply anything 
about @nogc. I of course know writeln is not nogc. I just kept 
the example simple.


Re: How to add a character literal to a string without ~ operator?

2024-04-04 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Thursday, 4 April 2024 at 18:14:54 UTC, BoQsc wrote:
I'm looking for more readable standard function to add a 
**character** literal to a **string**.


The `~` operator is clearly not great while reading a source 
code.
I'm not here to discuss that. I'm looking for a function inside 
standard library.


The function should be straightforward, up to two words.

Here is what I expect from a programming language:

Pseudo example:
```
import std;
void main(){
string word = hello;
join(word, 'f', " ", "World");
writeln(word);  // output: hellof World

}

```


My favorite d feature is lazy ranges. No allocation here.

```
auto s = chain("as ", "df ", "j"); // s is lazy
writeln(s);
```

Of course you can allocate a new string from the chained range:
```
string str = cast(string)s.array.assumeUnique; // without a cast 
it is a dstring (why though?)

```



Re: Alguien me dice como podria conectarme a una base de datos en SQL server?

2024-03-14 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Thursday, 14 March 2024 at 16:42:04 UTC, dany wrote:
Hola a todos necesito conectarme a una base de datos sql y ps 
no me sale :'(

quisiera saber como podria porfis, ayuda :')


import std.stdio;
import std.json;
//import std.database.mysql;
//import raylib;
import ddbc;


void main() {

	//string urlServer = 
"ddbc:sqlserver://DESKTOP-HLK011R\\MSSQLSERVER02,1433?user=dany,password=1234567890";
	//string urlServer = 
"ddbc:sqlserver://DESKTOP-RNTV16H:1433";


auto conn = createConnection(urlServer);

scope(exit) conn.close();

}


Deberias preguntar en Ingles en este foro. No mucha gente que 
habla Espanol aqu. Puedes buscar un biblioteca en 
https://code.dlang.org/search?q=sql. Usa un biblioteca de allı. 
No se como se lol hace con MySQL pero se lo hace con MySQL:


https://code.dlang.org/packages/mysql-native
import mysql.safe;

Connection conn;

Connection connectDB(){
auto connectionStr = 
"host=localhost;port=3306;user=root;pwd=;db=deneyler";

return new Connection(connectionStr);
}

Tines que usar una otra biblioteca por MySQL, por supuesto




Re: Recommendation about templating engine library

2024-03-11 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Monday, 11 March 2024 at 14:26:01 UTC, Andrea wrote:

Hi folks,

Working on a side project I have the need to generate text 
files (mainly D source code) via a templating system. My use 
case is to have some JSON data populated at runtime from an API 
and fill-in placeholders in the text with the ability of doing 
loops over arrays, simple conditions and so on, mostly what 
https://pkg.go.dev/text/template provides for Go.


Any recommendation on a good library to use ?

I tried https://code.dlang.org/packages/temple but I don't wand 
to bring in the whole vibe-d dependency ; other projects I 
found in DUB like `mustache-d`, `jax` or `djinn` seems mostly 
unmaintained. Opinions ?


Many thanks


You have already mentioned mustache-d. If it compiles with the 
recent compilers go for it. I used it some time a go for a 
similar task involving in d code gen.


Re: Are exceptions caught in unittests?

2024-02-16 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Friday, 16 February 2024 at 08:48:08 UTC, Jonathan M Davis 
wrote:
On Friday, February 16, 2024 1:06:26 AM MST Ferhat Kurtulmuş 
via Digitalmars- d-learn wrote:

[...]


1. assertThrown does not test whether something somewhere in 
what you called threw an exception. It asserts that it catches 
an exception. Your example here is catching the exception and 
returning so the exception never escapes the division function, 
and there's nothing for assertThrown to catch.


[...]


Hi Jonathan, thank you for clearly explaining in detail how it 
works. I added trailing parenthesis to the lambda inside 
assertThrown, which worked as expected.


Ferhat


Re: Are exceptions caught in unittests?

2024-02-16 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Friday, 16 February 2024 at 07:43:24 UTC, Ferhat Kurtulmuş 
wrote:
When I tried to catch exceptions in my unit test, I found that 
exceptions were not thrown or caught in the unit test blocks. 
So, I cannot use assertThrown at all. Is this a bug or expected 
behavior that I don't know?


Using LDC 1.36.0 on Windows.

https://github.com/aferust/evalex/blob/main/source/evalex.d#L694


Even a test code like this does not work:

```d
string division(int a, int b) {
   string result = "";

   try {
  if( b == 0 ) {
 throw new Exception("Cannot divide by zero!");
  } else {
 result = format("%s",a/b);
  }
   } catch (Exception e) {
  result = e.msg;
   }

   return result;
}

assertThrown({division(50, 0);});
```


Re: Are exceptions caught in unittests?

2024-02-16 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Friday, 16 February 2024 at 07:54:01 UTC, Richard (Rikki) 
Andrew Cattermole wrote:

This should be working.

I don't know what is going on.

All I can suggest is to use a debugger to see if it is indeed 
throwing and then catching.


A test code like this works, but unittest doesn't. This is crazy:

```d
import std.stdio;
import evalex;

void main(){
string text = "2 + * 3";
try {
auto evaluator = new Eval!double(text);
auto result = evaluator.result;
writeln(result);
}catch (ParserException e){
writeln(e.msg);
}

}
```


Are exceptions caught in unittests?

2024-02-15 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
When I tried to catch exceptions in my unit test, I found that 
exceptions were not thrown or caught in the unit test blocks. So, 
I cannot use assertThrown at all. Is this a bug or expected 
behavior that I don't know?


Using LDC 1.36.0 on Windows.

https://github.com/aferust/evalex/blob/main/source/evalex.d#L694


Re: D: Convert/parse uint integer to string. (@nogc)

2023-11-24 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Friday, 24 November 2023 at 09:35:00 UTC, BoQsc wrote:

I tried to look into https://dlang.org/phobos/std_conv.html

Most of the functions inside `std.conv` seem to be dependant on 
[Garbage Collection](https://dlang.org/spec/garbage.html).


And I couldn't find a straightforward way to produce a `string` 
value out of `uint` value.


How to convert or parse `uint` value to a `string` in `@nogc` 
way?


I guess there are third-party libraries doing this. One would use 
stdc functions such as sprintf. Probably, there should be a more 
d-ish way.

```
import core.stdc.stdio : sprintf;
import core.stdc.math : log10;

import std.exception : assumeUnique;
import std.stdio : writeln;

size_t nod(int num){
  return cast(size_t)((num==0)?1:log10(num)+1);
}

void main()
{
   int myint = 23;

   char[80] str;

   sprintf(str.ptr, "%d", myint);

   string _dstring = str[0..nod(myint)].assumeUnique;

   writeln(_dstring);

}
```


Re: extern (c)

2023-10-11 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Wednesday, 11 October 2023 at 12:36:58 UTC, Paul wrote:

What does the extern (c) attribute(?) do?
Does it tell the compiler/linker to build the function like a C 
compiler would build a C function? If so what does that mean?
Does it tell the compiler/linker to let C functions know it 
exists? If so what does that mean?

Is it meant for the compiler or linker or both?

Thanks for any assistance.


It is about name mangling. It prevents symbol names from using 
D's name mangling.


https://dlang.org/blog/2017/12/20/ds-newfangled-name-mangling/


Re: Struct nested function

2023-09-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Wednesday, 13 September 2023 at 05:58:13 UTC, vino wrote:

Hi All,

  Request your help, I have a struct which has many functions, 
I need to run a function from within another function(From 
Display function execute the runner function), an example as 
below


From,
Vino


The problem starts here:

```string *runnerptr = ```

You are trying to assign a delegate to string*. Even if we fix 
this, we hit another error because D programming language does 
not allow capturing a reference to this, which is not permitted 
in tasks (IMHO). We fix this using a lambda ```auto result = 
task(() => runner());```. Then the final code that runs should be 
like:


```d
import std.stdio: writeln;
import std.algorithm: joiner;
import std.parallelism: task;
import std.typecons: tuple;

struct MainEngine {
int rno;
string firstname;
string lastname;
int age;

this(in int _rno) { rno = _rno; }
auto ref FirstName(in string _firstname) { firstname = 
_firstname; return this; }
auto ref LastName(in string _lastname) { lastname = 
_lastname; return this; }

auto ref Age(in int _age) { age = _age; return this; }
auto Display () {
auto runner(string status = "Male")
{
auto record = tuple([firstname,",",lastname].joiner, 
age, status);

return record;
}

auto result = task(() => runner());
//writeln(typeof(result).stringof);
result.executeInNewThread;
result.yieldForce;
return result;
}
}

void main () {
auto mrunner = 
MainEngine(1).FirstName("Fname").LastName("Lname").Age(25).Display();
writeln((*mrunner).yieldForce); // Access the result field to 
get the value returned by the task

}
```


Re: D web browser?

2023-09-08 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Friday, 8 September 2023 at 06:42:13 UTC, Joe wrote:
Is there a D library that lets one access the web through a 
browser like interface? I need to access some URLS as if I was 
browsing them(it needs to run scripts in the page).


E.g., C# has WebBrowser that lets one programmatically control 
a browser. I'd like something similar. It does not need to be 
graphical but it does need to be able to handle javascript and 
forms and allow programmatic interaction and ideally quite 
light(else it almost defeats the purpose).


Those are some works that I remember.

https://github.com/skoppe/spasm an example code: 
https://github.com/skoppe/spasm/tree/master/examples/fetch



https://github.com/adamdruppe/arsd and its docs:
http://arsd-official.dpldocs.info/arsd.html#web-scraper
https://github.com/adamdruppe/webassembly/blob/master/tetris.d

Probably, more can be found at 
https://code.dlang.org/?sort=updated=20=library.web


Re: How can I execute C++ functions from Dlang?

2023-08-19 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Saturday, 19 August 2023 at 20:50:23 UTC, thePengüin wrote:
On Saturday, 19 August 2023 at 20:16:47 UTC, Ferhat Kurtulmuş 
wrote:

On Saturday, 19 August 2023 at 19:41:47 UTC, thePengüin wrote:
On Monday, 14 August 2023 at 07:36:31 UTC, Ferhat Kurtulmuş 
wrote:

[...]


estoy usando el de 64 o almenos eso es lo que me dice cuando 
hago un dmd --version:

DMD64 D Compiler v2.104.2-dirty
Copyright (C) 1999-2023 by The D Language Foundation, All 
Rights Reserved written by Walter Bright


por cierto "cl" en ves de g++, creo que es la abreviatura de 
"compilador" no? porque cl no me sale como comando en el 
mingw64x84


Estoy escribendo en mi celular. Entonces no tomo ayudar de 
Google translate. Mi español no es bueno, disculpa. Nunca uso 
un mesclar de mingw-g++ y algun d compilador en Windows. cl es 
el comando del Visual C++. No sé si g++ y dmd son binarias 
compatibles. Yo siempre uso LDC en Windows. Creo que tu 
deberias installar e uso Visual studio c++ community edition. 
Los compiladores msvc juega bien con los compiladores de dlang.


Que es cl.exe: 
https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options?view=msvc-170


- te refieres al ldc de Dlang en windows no?


Sí, yo queria decir esto. Lo puedes descargar aqui: 
https://github.com/ldc-developers/ldc/releases/tag/v1.33.0


Por favor te recorda que cuando tu installaste msvc, siempre 
ejecuta tus comandos del compiladores (cl, ldc2 o dmd, etc.) en 
terminal del msvc. Puedes buscarlo en menu de inicio de windows 
porque automatiza link con bibliotheca de stdc++.


Re: How can I execute C++ functions from Dlang?

2023-08-19 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Saturday, 19 August 2023 at 19:41:47 UTC, thePengüin wrote:
On Monday, 14 August 2023 at 07:36:31 UTC, Ferhat Kurtulmuş 
wrote:

On Monday, 14 August 2023 at 06:40:04 UTC, thePengüin wrote:

hola a todos quisiera ejecutar este codigo de c++
`
#include \

using namespace std;

int main() {

return 0;
}

int foo(int i, int j) {
cout \<\< i\<\

?Tu usas ambos de 64 bit o 32 bit para compiladores?

No puedo reproducir tu codigo. Pero yo puedo ejecutar esto en 
Windows:


cppcode.cpp

```d
#include 

using namespace std;

// no nececitamos un main aqui

int foo(int i, int j) {
cout << i << endl;
cout << j << endl;
return 7;
}

```

main.d

```d
extern(C++) int foo(int i, int j);

void main () {
foo(3,6);
}
```


La compulacion:

cl cppcode.cpp -c
dmd main.d cppcode.obj


estoy usando el de 64 o almenos eso es lo que me dice cuando 
hago un dmd --version:

DMD64 D Compiler v2.104.2-dirty
Copyright (C) 1999-2023 by The D Language Foundation, All 
Rights Reserved written by Walter Bright


por cierto "cl" en ves de g++, creo que es la abreviatura de 
"compilador" no? porque cl no me sale como comando en el 
mingw64x84


Estoy escribendo en mi celular. Entonces no tomo ayudar de Google 
translate. Mi español no es bueno, disculpa. Nunca uso un mesclar 
de mingw-g++ y algun d compilador en Windows. cl es el comando 
del Visual C++. No sé si g++ y dmd son binarias compatibles. Yo 
siempre uso LDC en Windows. Creo que tu deberias installar e uso 
Visual studio c++ community edition. Los compiladores msvc juega 
bien con los compiladores de dlang.


Que es cl.exe: 
https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options?view=msvc-170




Re: Mir-algorithm tutorial?

2023-08-19 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Saturday, 19 August 2023 at 01:44:16 UTC, Kyle Ingraham wrote:
On Friday, 18 August 2023 at 12:14:45 UTC, Ferhat Kurtulmuş 
wrote:
I think the main problem is the mir libraries won't get 
updates since Ilya recently said that he was not an open 
source developer anymore.


That’s unfortunate for D but hopefully beneficial for Ilya. Was 
it said somewhere publicly where I can read more on it?


https://forum.dlang.org/post/u7r1i8$rn7$1...@digitalmars.com


Re: Mir-algorithm tutorial?

2023-08-18 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Friday, 18 August 2023 at 09:57:11 UTC, Ki Rill wrote:
On Friday, 18 August 2023 at 09:32:31 UTC, Ferhat Kurtulmuş 
wrote:
I believe the most recent docs for mir-algorithm is here 
http://mir-algorithm.libmir.org/


Thanks. Yes, that's the only thing.

However, it's not a good starting point for someone who just 
wants to get to know the library and play around...


Yes there isn't many guides around. Those are some of them.

https://tastyminerals.github.io/tasty-blog/dlang/2020/03/22/multidimensional_arrays_in_d.html

https://jackstouffer.com/blog/nd_slice.html

Also this piece of code was converted from python-numpy to d-mir.

https://github.com/libmir/dcv/blob/master/source/dcv/imgproc/threshold.d#L138

I converted many more from python for DCV.

I think the main problem is the mir libraries won't get updates 
since Ilya recently said that he was not an open source developer 
anymore.


Re: Mir-algorithm tutorial?

2023-08-18 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Friday, 18 August 2023 at 07:54:04 UTC, Ki Rill wrote:

Is there an up-to-date tutorial?

It's just painful that I cannot find anything helpful on this 
topic. The official mir-algorithm GitHub repo links to articles 
with old code that won't build if I copy-paste it. I'm left 
hunting down the changes and guessing how things should really 
work.


I believe the most recent docs for mir-algorithm is here 
http://mir-algorithm.libmir.org/




Re: Finding duplicate elements

2023-08-16 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Tuesday, 15 August 2023 at 17:59:27 UTC, vino wrote:

Hi All,

 Request your help in finding duplicate element without sorting 
as per the below example


```
Example:
string[] args = [" test3", "test2 ", " test1 ", " test1 ", " "];

Output Required:
If duplicate element found then print "Duplicate element found: 
"

else print ["test3", "test2", "test1"];
```
From,
Vino.B


Another approach would be using a rbtree as container at the 
first place.


Re: How can I execute C++ functions from Dlang?

2023-08-14 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Monday, 14 August 2023 at 06:40:04 UTC, thePengüin wrote:

hola a todos quisiera ejecutar este codigo de c++
`
#include \

using namespace std;

int main() {

return 0;
}

int foo(int i, int j) {
cout \<\< i\<\

?Tu usas ambos de 64 bit o 32 bit para compiladores?

No puedo reproducir tu codigo. Pero yo puedo ejecutar esto en 
Windows:


cppcode.cpp

```d
#include 

using namespace std;

// no nececitamos un main aqui

int foo(int i, int j) {
cout << i << endl;
cout << j << endl;
return 7;
}

```

main.d

```d
extern(C++) int foo(int i, int j);

void main () {
foo(3,6);
}
```


La compulacion:

cl cppcode.cpp -c
dmd main.d cppcode.obj




Re: Loading Textures in OpenGL

2023-07-23 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Sunday, 23 July 2023 at 18:06:46 UTC, Ruby The Roobster wrote:

On Sunday, 23 July 2023 at 17:45:53 UTC, Ferhat Kurtulmuş wrote:
On Sunday, 23 July 2023 at 17:35:03 UTC, Ruby The Roobster 
[SNIP]


Thank you.  I'm still trying to work out how it works.  It 
seems as if the creator tried the same thing that I did, and 
then commented it out.  Perhaps for the same reason?


It is me who did it. I was getting some weirdly distorted 
images. And you see my final solution. I am writing on my 
mobil so cannot help you further.


Ah.  Anyhow, I fixed it.  I had to use .scanline to fill the 
Image data, but in the end it worked.  Thank you very much.


Nice to hear that.



Re: Loading Textures in OpenGL

2023-07-23 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Sunday, 23 July 2023 at 17:35:03 UTC, Ruby The Roobster wrote:

On Sunday, 23 July 2023 at 17:02:40 UTC, Ferhat Kurtulmuş wrote:
On Sunday, 23 July 2023 at 16:21:05 UTC, Ruby The Roobster 
wrote:
I'm currently trying to load two textures and apply them to a 
rectangle, following
[this](https://learnopengl.com/Getting-started/Textures) 
which is linked to from the README file of the bindbc OpenGL 
bindings.


[...]


DCV uses gamut for image input, and opengl for displaying 
stuff. You can take a look at the sources:


https://github.com/libmir/dcv/blob/master/source/dcv/imageio/image.d#L399

https://github.com/libmir/dcv/blob/master/source/dcv/plot/drawprimitives.d#L126


Thank you.  I'm still trying to work out how it works.  It 
seems as if the creator tried the same thing that I did, and 
then commented it out.  Perhaps for the same reason?


It is me who did it. I was getting some weirdly distorted images. 
And you see my final solution. I am writing on my mobil so cannot 
help you further.


Re: Loading Textures in OpenGL

2023-07-23 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Sunday, 23 July 2023 at 16:21:05 UTC, Ruby The Roobster wrote:
I'm currently trying to load two textures and apply them to a 
rectangle, following
[this](https://learnopengl.com/Getting-started/Textures) which 
is linked to from the README file of the bindbc OpenGL bindings.


[...]


DCV uses gamut for image input, and opengl for displaying stuff. 
You can take a look at the sources:


https://github.com/libmir/dcv/blob/master/source/dcv/imageio/image.d#L399

https://github.com/libmir/dcv/blob/master/source/dcv/plot/drawprimitives.d#L126



Re: How to read live output from another process ?

2023-06-29 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Friday, 23 June 2023 at 23:37:29 UTC, Vinod K Chandran wrote:

Hi all,
I am trying to create a program which burns time codes to a 
video. I am using ffmpeg for this. So far, I can successfully 
start ffmpeg in another thread and stop it when I need. But I 
can't read the live outputs from ffmpeg. This is my code.

```d
void onBtnBurnClick(Control c, EventArgs e) {
if (!burnStarted) {
burnStarted = true;
btnBurn.text = "Stop Burning";
auto ffCmd = makeFFMPEGCommand(selVideo);
  // ffPipe is a global ProcessPipes
auto tsk = task!runFFMPEG(ffCmd, , frm.handle);
tsk.executeInNewThread();
} else {
ffPipe.stdin.writeln("q");
ffPipe.stdin.close();
btnBurn.text = "Burn Time Code";
}
}
```
This is a button's click event.

I used something similar here:

https://github.com/aferust/oclcv/blob/main/examples/threshold-video/source/app.d



Re: How to setup dub project for contributing to a dub package?

2023-06-24 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Friday, 23 June 2023 at 15:22:33 UTC, Ki Rill wrote:
Recently, I tried to set up `dcv` with `dub` to improve a few 
things in the library, but I faced some strange issues.


[...]
I recommend adding DCV sub packages separately. Don't add the 
entire thing to your dub dependencies. Just only add what you 
need. Ffmpeg-d in only needed for DCV videoing. You can add 
subpacks like:


"dependencies": {
"dcv:core": ...,
"dcv:plot": {"path": "../../"},
"dcv:imageio": {"path": "../../"},
"mir-random": "*"
}


Re: How to setup dub project for contributing to a dub package?

2023-06-24 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Friday, 23 June 2023 at 15:52:44 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
First things first, dcv is added to the dub-registry, so use 
this.


https://code.dlang.org/packages/dcv

```json
"dependencies": {
"dcv": "~>0.3.0"
}
```

For ffmpeg the binding tells you what to add for search paths 
in the lflags directive.


https://github.com/ljubobratovicrelja/ffmpeg-d#adding-to-dub

All I can suggest is make sure you have the right dev packages 
for ffmpeg installed and findable by the linker.


Just to make things clear,

I don't recommend to use DCV from dub registry, it's outdated. I 
have an opinion that the docs should be updated before creating a 
new version updating the dub repo. There are so many API changes 
between the last dub repo version and the master repo. I don't 
know if I will find time and motivation anytime soon. I doubt 
someone else will do it too (it is a huge welcome though).


Re: pregunta preguntona, acerca de el resultado de remoteAddress()

2023-06-14 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Wednesday, 14 June 2023 at 19:50:21 UTC, Danico wrote:
que significa los ultimos numeros de 192.168.0.13:50732 , 
cuando hago un remoteAddress() y en un servidor socket?


Es un numero de puerto. No estoy seguro que preguntar en un 
idioma otra que ingles es un buena idea aqui. Lee esto por favor: 
https://es.m.wikipedia.org/wiki/Puerta_de_enlace





Re: What's dxml DOMEntity(R) type ?

2023-06-06 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Tuesday, 6 June 2023 at 14:16:37 UTC, Steven Schveighoffer 
wrote:

On 6/5/23 6:43 AM, Ferhat Kurtulmuş wrote:

On Monday, 5 June 2023 at 10:01:01 UTC, John Xu wrote:

[...]

```d
import dxml.dom;
import std.stdio;

     DOMEntity!string xmlRoot;
     int main()
     {
     string xml = "";
     auto dom = parseDOM(xml);
     writeln(typeof(dom.children[0]).stringof); // yields 
"DOMEntity!string"

     xmlRoot = dom.children[0];
     return 0;
     }
     ```



In general, the easiset thing to do is use typeof, though it's 
not always pretty (and not always obvious how to write it). 
However, it's required for voldemort types.


```d
typeof(parseDom("")) DomEntity;
```

-Steve
İt is one of the nicest features of d. I believe it should not be 
used too often because it may cause longer compilation times, 
worse code reading, less comfort with d code scanners, editors 
etcetera.


Re: What's dxml DOMEntity(R) type ?

2023-06-05 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Monday, 5 June 2023 at 10:01:01 UTC, John Xu wrote:
The parseDOM returns a DOMEntity(R) type, how do I write a 
xmlRoot as global variable?

I need its detailed type (auto / Variant doesn't work).


import dxml.dom;
?? xmlRoot;
int main() {
string xml = readText("a.xml");
auto dom = parseDOM(xml);
xmlRoot = dom.children[0];
}

```d
import dxml.dom;
import std.stdio;

DOMEntity!string xmlRoot;
int main()
{
string xml = "";
auto dom = parseDOM(xml);
writeln(typeof(dom.children[0]).stringof); // yields 
"DOMEntity!string"

xmlRoot = dom.children[0];
return 0;
}
```


Re: what is the aftermath of dip74

2023-05-10 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Wednesday, 10 May 2023 at 18:15:36 UTC, Richard (Rikki) Andrew 
Cattermole wrote:

We do not, no.

Reference counting is not currently in the language, although 
you can fake it with structs.


Its a huge shame, but it should be added at some point because 
the compiler would tell the backend that it is possible to 
elide pair calls.


However it'll have to wait for the DIP queue to reopen (slight 
process adjustment to make things easier is incoming).


Thank you Rikki for the clarification. I think d need this 
without ugly workarounds.


Re: Getting a total from a user defined variable

2023-04-20 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Thursday, 20 April 2023 at 19:41:21 UTC, Joel wrote:

```d
import std;

struct Person {
string name;
ulong age;
}

void main() {
auto p=[Person("Joel", 43), Person("Timothy", 40)];
writeln("Total: ", p.reduce!((a,b) => a.age+b.age)(0UL)); 
// how do I get the total of ages added together?

}
```


```d
import std;

struct Person {
string name;
ulong age;
}

void main() {
auto p=[Person("Joel", 43), Person("Timothy", 40)];

writeln("Total: ", p.map!(a => a.age).reduce!"a + b");
}
```


Re: Variable length arrays under -betterC?

2023-04-18 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Tuesday, 18 April 2023 at 06:20:43 UTC, Richard (Rikki) Andrew 
Cattermole wrote:

On 18/04/2023 1:33 PM, Salih Dincer wrote:
I understand from the thread this: D gives us -betterC but 
nothing from the Phobos.  So he says, see what you have, do 
what the hell you want!


Am I wrong about this?


Nope.

-betterC means you have no runtime or standard library support.

You are very much on your own.


With betterC, some Phobos functionality work. For instance, most 
of std.range and std.algorithm will work. Problem is that there 
is no list of those in the docs. If something does GC allocations 
(std.container) or throws exceptions, it will not work. Based on 
my experience, -betterC, as its name implies, still provides a 
good programming experience rather than C.






Re: What do you think about using Chat GPT to create functions in D?

2023-04-14 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Monday, 3 April 2023 at 23:38:52 UTC, Marcone wrote:
What do you think about using Chat GPT to create functions in 
D? I asked Chat-GPT to create a function in D that was similar 
to the rsplit() function in Python. It returned this code to me:



import std.algorithm;
import std.array;
import std.string;

string[] rsplit(string input, string separator, size_t maxsplit 
= size_t.max) {
auto splitter = splitter(input, separator, 
SplitterFlag.all);

auto results = splitter.array;
if (maxsplit < results.length - 1)
results = results[results.length - maxsplit - 1 .. $];
return results;
}


Recently, it helped me figure out an OpenGL task using d.

This is the code it suggests after I provide some details to 
it about the case and the error I get:

```d
Slice!(RCI!ubyte, 3LU, Contiguous) plot2imslice() @nogc 
nothrow

{
import mir.rc;

Slice!(RCI!ubyte, 3LU, Contiguous) imgslice = 
rcslice!ubyte([height, width, 3], 0);


glfwMakeContextCurrent(_glfwWindow);

// create and bind framebuffer
GLuint fbo;
glGenFramebuffers(1, );
glBindFramebuffer(GL_FRAMEBUFFER, fbo);

// create and bind texture
GLuint texture;
glGenTextures(1, );
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, 
GL_RGB, GL_UNSIGNED_BYTE, null);
glFramebufferTexture2D(GL_FRAMEBUFFER, 
GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);


// render scene to framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
// render your scene here

// read pixel data from framebuffer
glReadPixels(0, 0, width, height, GL_RGB, 
GL_UNSIGNED_BYTE, imgslice.ptr);


// flip image vertically
for (size_t y = 0; y < height / 2; y++) {
for (size_t x = 0; x < width; x++) {
// swap rows
swap(imgslice[y][x], imgslice[height - y - 1][x]);
}
}

// unbind framebuffer and cleanup
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDeleteTextures(1, );
glDeleteFramebuffers(1, );

return imgslice;
}
```

And this is the code after required modifications:
```d
auto plot2imslice() @nogc nothrow
{
import mir.rc;

Slice!(RCI!ubyte, 3LU, Contiguous) imgslice = 
rcslice!ubyte([height, width, 3], 0);


glfwMakeContextCurrent(_glfwWindow);

// create and bind framebuffer
GLuint fbo;
glGenFramebuffers(1, );
glBindFramebuffer(GL_FRAMEBUFFER, fbo);

// create and bind texture
GLuint texture;
glGenTextures(1, );
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 
0, GL_RGB, GL_UNSIGNED_BYTE, null);
glFramebufferTexture2D(GL_FRAMEBUFFER, 
GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);


// render scene to framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, fbo);

// render scene here
render();

// read pixel data from framebuffer
glReadPixels(0, 0, width, height, GL_RGB, 
GL_UNSIGNED_BYTE, imgslice.ptr);


import mir.utility : swap;
// flip image vertically to correct generated image
foreach (y; 0..height / 2) {
each!swap(imgslice[y], imgslice[height - y - 1]);
}
// unbind framebuffer and cleanup
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDeleteTextures(1, );
glDeleteFramebuffers(1, );

return imgslice;
}
```

This comment of chatGPT saved the day :) // render your scene here


Re: better video rendering in d

2023-03-21 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Tuesday, 21 March 2023 at 17:46:00 UTC, H. S. Teoh wrote:
On Tue, Mar 21, 2023 at 05:29:22PM +, monkyyy via 
Digitalmars-d-learn wrote:

On Tuesday, 21 March 2023 at 17:18:15 UTC, H. S. Teoh wrote:
> [...]

I vaguely remember an hour and half for 5 minutes of video 
when its extremely lightweight and raylib trivially does 
real-time to display it normally and realistically I wouldn't 
be surprised if it could do 1000 frames a second.


Coping several gb of data to disk(that probably asking the gpu 
one pixel at a time) to be compressed down into a dozen mb of 
video is just... temp shit.  I should just do something that 
isnt stressing hard drives extremely unnecessarily.


You could try to feed the frames to ffmpeg over stdin instead 
of storing the frames on disk. See this, for example:



https://stackoverflow.com/questions/45899585/pipe-input-in-to-ffmpeg-stdin

Then you can just feed live data to it in the background while 
you generate frames in the foreground.



T


This is how I use pipe process with d and ffmpeg. I am reading 
video frames but other way may work too.

https://github.com/aferust/oclcv/blob/main/examples/rgb2gray-video/source/app.d


Re: compile: link dynamic OR static library in Windows

2023-02-04 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 4 February 2023 at 15:52:33 UTC, Alexander Zhirov 
wrote:


PS C:\sources\pxe-restore\source> dmd -i app.d 
-LC:\msys64\home\user\postgresql-15.1\installed\mingw64\lib\libpq.dll
lld-link: error: 
C:\msys64\home\user\postgresql-15.1\installed\mingw64\lib\libpq.dll: bad file type. Did you specify a DLL instead of an import library?
lld-link: error: could not open 'pq.lib': no such file or 
directory

Error: linker exited with status 1



through a simple `dmd`?


On Windows, dub's default behavior is to search for "foo.lib", 
usually compiled with Visual Studio C/C++ compilers. However, you 
have mingw-compiled "libfoo.a". I would not use MinGW-compiled 
libs with d compilers. I don't know how d compilers improved to 
support it, but in the past, I experienced ABI compatibility 
issues with d and MinGW.


I took a quick look at https://www.postgresql.org/download/. When 
I tried to download, I saw that the archive contained *.lib 
files. So, why don't you use them?


you will also need definitions of the functions in your d code 
like `extern(C) void fooDB();`. I am not sure how 
[importC](https://dlang.org/spec/importc.html) is usable with 
PostgreSQL. In addition, there are some bindings in the dub 
registry https://code.dlang.org/search?q=PostgreSQL.




Re: Are there some helpers in Phobos equivalent to std::set_difference of ugly c++

2023-02-03 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Friday, 3 February 2023 at 15:53:35 UTC, Richard (Rikki) 
Andrew Cattermole wrote:

```d
import std.stdio, std.algorithm.setops, std.array;

void main() {
int[] v1 = [1, 2, 5, 5, 5, 9];
int[] v2 = [2, 5, 7];
int[] v3 = setDifference(v1, v2).array;

writefln!"%s \\ %s = %s"(v1, v2, v3);
}
```

[1, 2, 5, 5, 5, 9] \ [2, 5, 7] = [1, 5, 5, 9]


Thank you very much. I am surprised that I couldn't find it using 
many keywords on the site and google.


Are there some helpers in Phobos equivalent to std::set_difference of ugly c++

2023-02-03 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
I could not find a thing doing this. And I don't want to write it 
from scratch. Getting a range as output is ok too. What I need is 
the following:


```c++
const std::vector v1{1, 2, 5, 5, 5, 9};
const std::vector v2{2, 5, 7};
std::vector diff;

std::set_difference(v1.begin(), v1.end(), v2.begin(), 
v2.end(),

std::inserter(diff, diff.begin()));
print(v1, "∖ ");
print(v2, "= ");
print(diff, "\n");

// yielding { 1 2 5 5 5 9 } ∖ { 2 5 7 } = { 1 5 5 9 }
```


Re: Graphical progressive fill

2022-12-11 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Sunday, 11 December 2022 at 06:50:44 UTC, Joel wrote:
I've been trying to fill in areas with a colour but can't work 
it out. I want something like the effect where it fills with 
diamonds. Not all at once but building up in the main program 
loop.



#  #
#  #
#  #  #
#  #
#  #



#  #
#  #  #
#   ####
#  #  #
#  #



## #
# ####
#  # #
# ###   #
## #



https://rosettacode.org/wiki/Bitmap/Flood_fill


Re: Allocate a string via the GC

2022-05-23 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Monday, 23 May 2022 at 09:38:07 UTC, JG wrote:

Hi,

Is there any more standard way to achieve something to the 
effect of:


```d
  import std.experimental.allocator;
  string* name = theAllocator.make!string;
 ```


Pointers are not used for strings in d. string is an alias for 
immutable(char)[]. So, you can do:

```d
import std.exception : assumeUnique; // makes char[] immutable

string str = (new char[15]).assumeUnique;

str = "hmm. my string!";
```

a slice in d (e.g. char[]) is roughly considered as a struct with 
a pointer and length. I also suspect that your question is not 
that simple, maybe you really need a string pointer, and I 
couldn't understand what you are actually asking. I am sorry if 
those are not what you were looking for the answers to.


Here is how you GC allocate a pointer to a string.
```d
string* strptr = new string[1].ptr;
// Since slices are reference types just use this instead:
string[] strptr = new string[1];
```
Maybe you need a pointer to the first char of a string then:
```d
string str; // allocated somehow

immutable(char)* chr = str.ptr;
```


Re: I need some help for my DCV update

2021-11-27 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Saturday, 27 November 2021 at 11:35:21 UTC, Salih Dincer wrote:

I also found similar errors but couldn't solve them. I think it 
has to do with mir.slice.kind. Exactly Kind Topology...


I won't use parallel for it as a workaround until it is solved in 
the mir-algorithm.


Re: I need some help for my DCV update

2021-11-27 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Friday, 26 November 2021 at 09:16:56 UTC, Ferhat Kurtulmuş 
wrote:
I am working on the DCV to make it compilable with the recent 
versions of LDC, mir libraries, and stuff. I have not yet 
simply forked it to work on it. I am including modules one by 
one for my convenience instead. Hope, I am close to the end. 
Here is my temporary repo:


https://github.com/aferust/ddcv



After dealing with, various problems, it turns out the main 
problem was ndiota with pool.parallel.

https://github.com/aferust/ddcv/blob/main/source/dcv/imgproc/filter.d#L564
```
foreach (row; /*pool.parallel(*/ndiota(input.shape)/*)*/) // 
parallel loop causes a linker error

{
row.each!(i => calcGradientsImpl(fx[i], fy[i], mag[i], 
orient[i]));

}
```
The parallel loop causes a linker error here?

 error LNK2019: unresolved external symbol 
_D3mir7ndslice5slice__T9mir_sliceTSQBhQBg8iterator__T13FieldIteratorTSQCqQCp5field__T11ndIotaFieldVmi2ZQsZQCbVmi1VEQEjQEiQEd14mir_slice_kindi2ZQEq__T10lightScopeZQnMxFNaNbNdNiNfZSQGvQGuQGp__TQGmTQGfVmi1VQDli2ZQHe referenced in function _D3mir7ndslice5slice__T9mir_sliceTSQBhQBg8iterator__T13FieldIteratorTSQCqQCp5field__T11ndIotaFieldVmi2ZQsZQCbVmi1VEQEjQEiQEd14mir_slice_kindi2ZQEq__T8opEqualsTQEvVQBxi2ZQuMxFNaNbNiNeKxSQHbQHaQGv__TQGsTQGlVmi1VQDri2ZQHkZb

.dub\build\application-debug-windows-x86_64-ldc_v1.28.0-24645713CE34BFE817BFD3D964187D0E\ddcv.exe
 : fatal error LNK1120: 1 unresolved externals


Re: I need some help for my DCV update

2021-11-26 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Friday, 26 November 2021 at 09:31:42 UTC, drug wrote:

On 26.11.2021 12:16, Ferhat Kurtulmuş wrote:


InputTensor = Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) 
and KernelTensor = Slice!(float*, 2LU, 
mir_slice_kind.contiguous). The key argument of slices is a 
pointee type - InputTensor pointee has ubyte type and 
KernelTensor has float. I'm not sure this solves your problem 
but at least I'd start from here.


Yes, but this is how the original code was written.


I need some help for my DCV update

2021-11-26 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
I am working on the DCV to make it compilable with the recent 
versions of LDC, mir libraries, and stuff. I have not yet simply 
forked it to work on it. I am including modules one by one for my 
convenience instead. Hope, I am close to the end. Here is my 
temporary repo:


https://github.com/aferust/ddcv

I run into some problems with module convolution, especially the 
function conv invoked by the below code which calls canny edge 
filter:

```
Image image = imread("lena.png");
auto slice = image.sliced.rgb2gray;
//auto equalized = 
slice.histEqualize(slice.flattened.calcHistogram);


slice.asImage.imshow("Original");
auto edge = slice.canny!ubyte(15);
edge.asImage.imshow("edge");
waitKey();
```
Somehow, the compiler fails in deducting the types. I need some 
help from Ilya or other people familiar with mir.ndslice.


To reproduce it, download my repo and try to compile it as it is. 
There is a main with the test code in the repo. Just be sure you 
have a glfw3.dll/.so.


```
source\dcv\imgproc\filter.d(547,18): Error: template 
`dcv.imgproc.convolution.conv` cannot deduce function from 
argument types `!()(Slice!(ubyte*, 2LU, 
mir_slice_kind.contiguous), Slice!(float*, 2LU, 
mir_slice_kind.contiguous), Slice!(float*, 2LU, 
mir_slice_kind.contiguous), Slice!(float*, 2LU, 
mir_slice_kind.contiguous), TaskPool)`
source\dcv\imgproc\filter.d(548,18): Error: template 
`dcv.imgproc.convolution.conv` cannot deduce function from 
argument types `!()(Slice!(ubyte*, 2LU, mir_sut, KernelTensor 
kerlice_kind.contiguous), Slice!(float*, 2LU, 
mir_slice_kind.contiguous), Slice!(float*, 2LU, 
mir_slice_kind.contiguous), Slice!(float*, 2LU, 
mir_slice_kind.contiguous), TaskPool)`
  
   lice_kind.contiguous
source\dcv\imgproc\convolution.d(78,13):Candidate is: 
`conv(alias bc = neumann, InputTensor, KernelTensor, MaskTensor = 
KernelTensor)(InputTensor input, KernelTensor kernel, InputTensor 
prealloc = InputTensor.init, MaskTensor mask = MaskTensor.init, 
TaskPool pool = taskPool)`  ut, 
KernelTensor ker
source\dcv\imgproc\filter.d(674,18): Error: template instance 
`dcv.imgproc.filter.calcGradients!(Slice!(ubyte*, 2LU, 
mir_slice_kind.contiguous), float)` error instantiating   
  
 
r instantiating
source\dcv\imgproc\filter.d(694,24):instantiated from 
here: `canny!(ubyte, ubyte, mir_slice_kind.contiguous)`
source\app.d(48,34):instantiated from here: 
`canny!(ubyte, ubyte, mir_slice_kind.contiguous)`

```

I tried explicitly passing template parameters in 
dcv.imgproc.filter.calcGradients like below, but in that way, I 
am getting some other compilation errors:

```
alias Empty2Type = Slice!(V*, 2LU, SliceKind.contiguous);
fx = input.conv(neumann, typeof(input), Empty2Type, Empty2Type)
(kx, emptySlice!(2LU, V), emptySlice!(2LU, V), pool);
fy = input.convinput.conv(neumann, typeof(input), Empty2Type, 
Empty2Type)

 (ky, emptySlice!(2LU, V), emptySlice!(2LU, V), pool);
```

Thanks in advance!


Re: I need some help for my DCV update

2021-11-26 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Friday, 26 November 2021 at 09:16:56 UTC, Ferhat Kurtulmuş 
wrote:
I am working on the DCV to make it compilable with the recent 
versions of LDC, mir libraries, and stuff. I have not yet 
simply forked it to work on it. I am including modules one by 
one for my convenience instead. Hope, I am close to the end. 
Here is my temporary repo:


[...]


Upps
alias Empty2Type = Slice!(V*, 2LU, SliceKind.contiguous);
fx = input.conv!(neumann, typeof(input), Empty2Type, 
Empty2Type)

(kx, emptySlice!(2LU, V), emptySlice!(2LU, V), pool);
fy = input.conv!(neumann, typeof(input), Empty2Type, 
Empty2Type)

 (ky, emptySlice!(2LU, V), emptySlice!(2LU, V), pool);


Re: Data conversion

2021-11-16 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Tuesday, 16 November 2021 at 19:44:04 UTC, Ferhat Kurtulmuş 
wrote:

On Tuesday, 16 November 2021 at 19:18:50 UTC, pascal111 wrote:

[...]


sscanf of C is an option where you cannot use to!T. However, it 
is a c library function, and it doesn't throw an exception on 
unexpected inputs.


https://dlang.org/library/core/stdc/stdio/scanf.html
https://www.tutorialspoint.com/c_standard_library/c_function_sscanf.htm



Upps

https://dlang.org/library/core/stdc/stdio/sscanf.html


Re: Data conversion

2021-11-16 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Tuesday, 16 November 2021 at 19:18:50 UTC, pascal111 wrote:
I used "to" keyword which "std.conv" includes for data 
conversions, but I think that there are some other ways for 
data conversions, or maybe there are common ways like casting, 
I hope to know about. For example, next program are using "to":


// D programming language

import std.stdio;
import std.conv;
import std.string;

int main()
{

char[] s;
int x=0, e;


do{

try{
e=1;
write("Enter a numeric value: ");
readln(s);
s=strip(s);
x=to!int(s);}

catch (Exception err){
stderr.writefln!"Warning! %s"(err.msg);
e=0;}

}while(!e);

writeln("Correct numeric value!");

return 0;

}


sscanf of C is an option where you cannot use to!T. However, it 
is a c library function, and it doesn't throw an exception on 
unexpected inputs.


https://dlang.org/library/core/stdc/stdio/scanf.html
https://www.tutorialspoint.com/c_standard_library/c_function_sscanf.htm



Re: Crosscompile to Windows

2021-11-05 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Friday, 5 November 2021 at 18:11:35 UTC, Luis wrote:
There is a obvious way to crosscompile a dub project to Windows 
from a Linux dev machine ?


I don't know if it is possible with dmd. But with LDC you can use 
mtriple.

https://wiki.dlang.org/Cross-compiling_with_LDC




Re: I need a detailed document about druntime.

2021-10-11 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Monday, 11 October 2021 at 15:24:07 UTC, Adam D Ruppe wrote:
On Monday, 11 October 2021 at 15:18:11 UTC, Ferhat Kurtulmuş 
wrote:
"Each call to initialize must be paired by a call to 
terminate.'


It is so the refcount works out.

When you call initialize, it does something like:

if(refcount == 0)
   actually intialize; // calls constructors etc
refcount++;


When you call terminate, it does:

refcount--;
if(refcount == 0)
   actually terminate; // calls destructors etc



If you don't pair it, the refcount will be off, so the next 
call to terminate will still see ref > 0 and not actually 
terminate.


The D main inserts a call to init before main and a call to 
terminate after main automatically.


That makes sense, now I see, thank you again Adam.


Re: I need a detailed document about druntime.

2021-10-11 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Monday, 11 October 2021 at 15:09:12 UTC, Adam D Ruppe wrote:
On Monday, 11 October 2021 at 14:56:19 UTC, Ferhat Kurtulmuş 
wrote:
What I want is to bypass runtime initialization if it is 
already initialized.


That what it does by itself, you can call it and it has an 
internal count.


Thank you for your response. But this confuses me:

"Each call to initialize must be paired by a call to terminate.'


https://dlang.org/library/core/runtime/runtime.initialize.html


I need a detailed document about druntime.

2021-10-11 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
I want to know what happens if either Runtime.initialize or 
terminate is called without matching each other. And why there is 
no ready-to-use thing like initCount which is accessible in the 
code? What I want is to bypass runtime initialization if it is 
already initialized. The below code is my workaround, but it can 
only keep track of my initializations, not the one that 
automatically get fired where there is a dmain.


Should İ use "bool runMain" to differentiate between the 
compilations of dll and executable?


```d
private {
import core.runtime;
import core.atomic;

shared size_t initCount;

void initRT(){
if(!atomicLoad!(MemoryOrder.acq)(initCount)){
Runtime.initialize();
atomicOp!"+="(initCount, 1);
}
}

void termRT(){
if(atomicLoad!(MemoryOrder.acq)(initCount) > 0){
Runtime.terminate();
atomicOp!"-="(initCount, 1);
}
}
}
```


Re: Template mixin problem with EnumMembers

2021-10-02 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Saturday, 2 October 2021 at 22:24:56 UTC, Adam Ruppe wrote:
On Saturday, 2 October 2021 at 22:07:23 UTC, Ferhat Kurtulmuş 
wrote:

[...]


You used .stringof. That's undefined behavior. Never use 
stringof. (except for debugging writes)


[...]


Thank you Adam! I should stop using stringof. Even the docs say 
it, I ve just seen that 
https://dlang.org/spec/property.html#stringof.


Probably, I will go for your second solution.

I appreciate it.


Template mixin problem with EnumMembers

2021-10-02 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
The below code works as expected on https://run.dlang.io/, but 
not on my computer. And I don't know why?


I want to access enum members like Options.OUT_FILE_NAME instead 
of Options.StringOption.OUT_FILE_NAME.


Please note that the solutions like "alias something = int;" 
don't work for me. that is not what I need.


In my local computer, pragma(msg, fullname) outputs like:
cast(StringOption)0
cast(StringOption)1
cast(StringOption)2

some error messages I get:
...\options.d-mixin-86(86,11): Error: declaration expected, not )
...\options.d-mixin-86(86,11): Error: no identifier for 
declarator tion


```d
import std.stdio;

class Options{
public:

enum StringOption {
OUT_FILE_NAME,
RPT_FILE_NAME,
MAP_FILE_NAME
}

import std.traits: EnumMembers;
mixin template StrOptAliases()
{
static foreach(fullname; [EnumMembers!(StringOption)]){
mixin("alias " ~ fullname.stringof[13..$] ~ " = " ~ 
"Options." ~
   
fullname.stringof ~ ";\n");

pragma(msg, fullname);
}
}

mixin StrOptAliases;
}

void main()
{
int opt = Options.OUT_FILE_NAME;
writeln(opt);
}
```


Re: How to do "C++ classes"?

2021-09-20 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Monday, 20 September 2021 at 15:56:44 UTC, Ferhat Kurtulmuş 
wrote:
On Monday, 20 September 2021 at 15:45:08 UTC, Adam D Ruppe 
wrote:
On Monday, 20 September 2021 at 15:35:02 UTC, Ferhat Kurtulmuş 
wrote:

I thought it's stack-allocated and scoped.


It is.

But when I try to return a class instance from a function, it 
still works?


dmd only makes that an error if you specify `@safe` and i 
think `-dip1000`. Try adding one or both of those and 
recompiling and see what happens.


Note that even if the compiler doesn't error on it, it is 
undefined behavior to return the stack reference so be sure to 
treat it right.


That is what I thought too. I only tried this on the online 
compiler. Thank you. Have a great day or night captain.


I also think this is a dirty corner of the complier since it must 
raise an error for scoped instances of classes.




Re: How to do "C++ classes"?

2021-09-20 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Monday, 20 September 2021 at 15:45:08 UTC, Adam D Ruppe wrote:
On Monday, 20 September 2021 at 15:35:02 UTC, Ferhat Kurtulmuş 
wrote:

I thought it's stack-allocated and scoped.


It is.

But when I try to return a class instance from a function, it 
still works?


dmd only makes that an error if you specify `@safe` and i think 
`-dip1000`. Try adding one or both of those and recompiling and 
see what happens.


Note that even if the compiler doesn't error on it, it is 
undefined behavior to return the stack reference so be sure to 
treat it right.


That is what I thought too. I only tried this on the online 
compiler. Thank you. Have a great day or night captain.


Re: How to do "C++ classes"?

2021-09-20 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 18 September 2021 at 22:16:32 UTC, Adam D Ruppe 
wrote:

On Saturday, 18 September 2021 at 15:38:38 UTC, rempas wrote:
I'm seeing in the page about "BeterC" and in the part about 
the [retained 
features](https://dlang.org/spec/betterc.html#retained), the 
#11 says about "COM classes and C++ classes". What are the 
"C++ classes"? I tried to create a class using "extern(C++)" 
but this didn't worked. Can someone make an example on that?


extern(C++)
class Foo {}

void main() {
scope Foo foo = new Foo();
}


I thought it's stack-allocated and scoped. But when I try to 
return a class instance from a function, it still works? Captain 
Adam I need an explanation please.


Re: How to simply parse and print the XML with dxml?

2021-09-09 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Thursday, 9 September 2021 at 17:17:23 UTC, tastyminerals 
wrote:
Maybe I missed something obvious in the docs but how can I just 
parse the XML and print its content?


```
import dxml.parser;

auto xml = parseXML!simpleXML(layout);
xml.map!(e => e.text).join.writeln;
```

throws 
`core.exception.AssertError@../../../.dub/packages/dxml-0.4.3/dxml/source/dxml/parser.d(1457): text cannot be called with elementStart`.


I am not fully experienced with it, but once I used it for 
reading glade files [1]. I used dxml.dom. Hope it helps.


1: 
https://github.com/aferust/makegtkdclass/blob/master/source/gladeparser.d#L43


Re: foreach() behavior on ranges

2021-08-24 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Tuesday, 24 August 2021 at 19:06:44 UTC, Alexandru Ermicioi 
wrote:

On Tuesday, 24 August 2021 at 09:15:23 UTC, bauss wrote:

[...]


Actually the range contracts don't mention that it needs to be 
a by value type. It can also be a reference type, i.e. a class.



[...]


True for any forward range and above, not true for input 
ranges. The problem with them is that some of them are structs, 
and even if they are not forward ranges they do have this 
behavior due to implicit copy on assignment, which can 
potentially make the code confusing.



[...]


If we follow the definition of ranges, they must not be 
copy-able at all. The only way to copy/save, would be to have 
.save method and call that method. This again is not being 
properly followed by even phobos implementations.


Note, that a better approach would be to replace .save in 
definition of forward range with a copy constructor, then all 
non-compliant ranges would become suddenly compliant, while 
those that have .save method should be refactored to a copy 
constructor version.



[...]


You should add .save on assignment if range is a forward range, 
or just remove the assignment if it is not.


Best regards,
Alexandru.


Just out of curiosity, if a range implementation uses malloc in 
save, is it only possible to free the memory with the dtor? I 
worry about that especially when using those nogc range 
implementations with standard library. I don't have a list of the 
functions calling save in phobos. Is a save function only 
meaningful for GC ranges?


Re: How to get element type of a slice?

2021-08-23 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Saturday, 21 August 2021 at 02:59:39 UTC, Jesse Phillips wrote:

On Thursday, 19 August 2021 at 04:03:31 UTC, jfondren wrote:
On Thursday, 19 August 2021 at 03:32:47 UTC, Jesse Phillips 
wrote:
On Tuesday, 17 August 2021 at 12:33:03 UTC, Ferhat Kurtulmuş 
wrote:
Hey, thank you again but, I don't want an instance of 
Point[] I need:


alias T = Point[];

alias ElementOfPointSlice =  // element type of T





so, what's the problem? This passes tests:

```d
import std.range : ElementType;

struct Point { int x, y; }
alias T = Point[];
alias ElementOfPointSlice = ElementType!(T);

unittest {
assert(is(ElementOfPointSlice == Point));
}
```


No issue just trying to give Ferhat a final answer to his 
question.


Thank you. I appreciate it.



Re: How to call destructor before free without dropping @nogc?

2021-08-19 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Thursday, 19 August 2021 at 15:38:19 UTC, evilrat wrote:

On Thursday, 19 August 2021 at 15:12:03 UTC, Ferhat Kurtulmuş


Btw, based on 
https://github.com/dlang/druntime/blob/master/src/object.d#L4209:


import core.lifetime;
import core.stdc.stdio;
import core.stdc.stdlib;

extern (C) void rt_finalize(void *data, bool det=true) @nogc 
nothrow; // cheap hack here

alias destroy = rt_finalize;

class SomeClass
{
int a = 42;

this() @nogc { }
~this() @nogc {printf("nogc\n");}
this(int val) @nogc { a = val; }
}



@nogc void main()
{
	SomeClass dynAlloc = cast(SomeClass) 
malloc(__traits(classInstanceSize, SomeClass));

dynAlloc = emplace!SomeClass(dynAlloc, 123);
printf("dynamic %d\n", dynAlloc.a); // 123
//rt_finalize(cast(void*)dynAlloc);
destroy(cast(void*)dynAlloc); // cast needed :/ dunno 
consequences though

}


Re: How to call destructor before free without dropping @nogc?

2021-08-19 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Thursday, 19 August 2021 at 15:38:19 UTC, evilrat wrote:

On Thursday, 19 August 2021 at 15:12:03 UTC, Ferhat Kurtulmuş


This is cool, but even in unit tests for malloc wrapper there 
is only simple case with class without references to another 
class and no dtor.


If you examine the entire library, there are various use cases of 
nogc classes. For instance, a derived class containing references 
to other class objects [1]. I am not using classes heavily with 
D. I just once happily used dplug's nogc facilities. When I saw 
this thread, I just wanted to share it here.


Seems like the issue is that one have to add @nogc 
constructor/destructor overloads for emplace/destroy, and the 
author can't have @nogc dtor because of writeln (IIRC @nogc 
using GC is allowed with `debug` anyway), and all class members 
of another classes must recursively provide them as well.


I agree with you. D needs more nogc facilities for OOP. It would 
not be so hard to include those overloads. Probably, this would 
violate the strictly defended safety principles of D?


[1]: 
https://github.com/AuburnSounds/Dplug/blob/f67c14fd5ba44225d6669e87f942d641c8bf8ab8/window/dplug/window/cocoawindow.d


Re: How to call destructor before free without dropping @nogc?

2021-08-19 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Thursday, 19 August 2021 at 07:30:38 UTC, Bienlein wrote:

Hello,

I allocate some instance of class C manually and then free the 
memory again:


[...]


I just wanted to leave this here.
https://github.com/AuburnSounds/Dplug/blob/master/core/dplug/core/nogc.d


Re: How to get element type of a slice?

2021-08-17 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 13:14:44 UTC, Steven Schveighoffer 
wrote:

On 8/17/21 8:21 AM, Ferhat Kurtulmuş wrote:

Hello folks,

Hope everyone is doing fine. Considering the following code, 
in the first condition, I am extracting the type Point from 
the slice Point[]. I searched in the std.traits, and could not 
find a neater solution something like ElementTypeOf!T. Is 
there any neater solution for it? Thanks in advance.


```d
     static if (isArray!VecPoint){
     VecPoint dummy;
     alias Point = typeof(dummy[0]);
     } else static if (isRandomAccessRange!VecPoint){
     alias ASeq2 = TemplateArgsOf!VecPoint;
     alias Point = ASeq2[0];
     } else
     static assert(0, typeof(VecPoint).stringof ~ " type 
is not supported");

```


If you want the element type of a range (i.e. the thing 
returned by `range.front`), you can use `ElementType!T` (from 
std.range.primitives).


This returns the element type of the range, which for every 
array *except* character arrays, gives you the element type of 
the array.


If you want always the element type of the array, even for 
auto-decoded ranges, use `ElementEncodingType!T`.


If you know it's an array, you can just use Paul's solution.

Your `isRandomAccessRange` branch seems very suspect.

-Steve


Very informative, thanks. My code is lying here[1]. I want my 
struct to accept 2d static arrays, random access ranges, and 
"std.container.Array". I could achieve it with its present form, 
and I will probably slightly modify it based on your comments.


[1]: 
https://github.com/aferust/earcut-d/blob/master/source/earcutd.d#L34


Re: How to get element type of a slice?

2021-08-17 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Tuesday, 17 August 2021 at 12:49:02 UTC, drug wrote:

17.08.2021 15:21, Ferhat Kurtulmuş пишет:

[...]


https://dlang.org/library/std/range/primitives/element_type.html


Yes, that is neat. Thank you.


Re: How to get element type of a slice?

2021-08-17 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Tuesday, 17 August 2021 at 12:32:45 UTC, Paul Backus wrote:
On Tuesday, 17 August 2021 at 12:21:31 UTC, Ferhat Kurtulmuş 
wrote:

Hello folks,

Hope everyone is doing fine. Considering the following code, 
in the first condition, I am extracting the type Point from 
the slice Point[]. I searched in the std.traits, and could not 
find a neater solution something like ElementTypeOf!T. Is 
there any neater solution for it? Thanks in advance.


`typeof(T.init[0])`

Note that `std.range.ElementType` will probably not give the 
result you expect for character arrays (such as `char[]` and 
`wchar[]`), due to autodecoding.


Thank you. This one looks better.


Re: How to get element type of a slice?

2021-08-17 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Tuesday, 17 August 2021 at 12:26:36 UTC, jfondren wrote:
On Tuesday, 17 August 2021 at 12:21:31 UTC, Ferhat Kurtulmuş 
wrote:

[...]


This one's not in std.traits:

```d
import std.range : ElementType;

struct Point { int x, y; }

unittest {
Point[] points;
assert(is(ElementType!(typeof(points)) == Point));
}
```


Hey, thank you again but, I don't want an instance of Point[] I 
need:


alias T = Point[];

alias ElementOfPointSlice =  // element type of T



Re: How to get element type of a slice?

2021-08-17 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Tuesday, 17 August 2021 at 12:26:36 UTC, jfondren wrote:
On Tuesday, 17 August 2021 at 12:21:31 UTC, Ferhat Kurtulmuş 
wrote:

[...]


This one's not in std.traits:

```d
import std.range : ElementType;

struct Point { int x, y; }

unittest {
Point[] points;
assert(is(ElementType!(typeof(points)) == Point));
}
```


Awesome! Have a great day.


How to get element type of a slice?

2021-08-17 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

Hello folks,

Hope everyone is doing fine. Considering the following code, in 
the first condition, I am extracting the type Point from the 
slice Point[]. I searched in the std.traits, and could not find a 
neater solution something like ElementTypeOf!T. Is there any 
neater solution for it? Thanks in advance.


```d
static if (isArray!VecPoint){
VecPoint dummy;
alias Point = typeof(dummy[0]);
} else static if (isRandomAccessRange!VecPoint){
alias ASeq2 = TemplateArgsOf!VecPoint;
alias Point = ASeq2[0];
} else
static assert(0, typeof(VecPoint).stringof ~ " type is 
not supported");

```

Ferhat


Re: Can I make system calls directly from D?

2021-07-09 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Friday, 9 July 2021 at 08:08:57 UTC, rempas wrote:
I just wonder if I'm able to do system calls directly from D or 
If I have to create bindings from "unistd.h" from C


I don't know if it covers what you want but, druntime has those 
definitions:


https://github.com/dlang/druntime/blob/master/src/core/sys/posix/unistd.d

import core.sys.posix.unistd;

... do stuff


Re: Trivial simple OpenGl working example

2021-07-09 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Friday, 9 July 2021 at 06:16:08 UTC, Ferhat Kurtulmuş wrote:

On Friday, 9 July 2021 at 05:17:28 UTC, Виталий Фадеев wrote:

[...]



[...]


Dear Vitaly (Google translates it like that :)), I didn't touch 
that game for a while. I have just tried to compile and those 
are the steps to build and run it:


[...]


You may also need to use the exact version of "bettercmath": 
"0.3.1".


Re: Trivial simple OpenGl working example

2021-07-09 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Friday, 9 July 2021 at 05:17:28 UTC, Виталий Фадеев wrote:
On Thursday, 8 July 2021 at 17:20:14 UTC, Ferhat Kurtulmuş 
wrote:

On Thursday, 8 July 2021 at 13:51:51 UTC, Виталий Фадеев wrote:

Hi!




Each ends with error.


Dear Vitaly (Google translates it like that :)), I didn't touch 
that game for a while. I have just tried to compile and those are 
the steps to build and run it:


Using a Windows 10 x64. (Webassembly build needs crazy efforts, 
don't try it for now. If you are on a posix system please delete 
*.a folders from the root folder because they are for webassembly)


1) Open the dub.json or dub.selections.json, and change "bcaa": 
"~>0.0.5" to "bcaa": "0.0.5" (Recently a contributor and I have 
made some breaking changes in bcaa).


2) Have those lib and dll files in the root folder of the project:

chipmunk.lib // I manually compiled this one
libfreetype-6.dl
libjpeg-9.dll
libpng16-16.dll
libtiff-5.dll
libwebp-7.dll
SDL2_image.dll
SDL2_image.lib
SDL2_ttf.dll
SDL2_ttf.lib
SDL2.dll
SDL2.lib
zlib1.dll

basically, those are win 64-bit builds of SDL2, its friends, and 
their dependencies. If you provide an email, I can send them to 
you via wetransfer.


For posix builds, you will have to figure those out.


Re: Trivial simple OpenGl working example

2021-07-08 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Thursday, 8 July 2021 at 13:51:51 UTC, Виталий Фадеев wrote:

Hi!

I searching trivial simple D/OpenGL working in 2021 year 
example.


It may be triangle.
It may be based on any library: SDL, GLFW, Derelict, etc.

Can you help me ?


this one of mine [1] was very simple in the beginning. It even 
runs on browser now.


[1] https://github.com/aferust/drawee


Re: How to use a shared library created in cython?

2021-04-12 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Sunday, 11 April 2021 at 20:08:15 UTC, affonso elias ferreira 
junior wrote:
Hi everyone, I'm trying to use a shared library created in 
Cython. example.


[...]


I am on my mobile phone, and cannot reproduce. But i see that 
this cast(int function()) should be cast(int function(int)). Try 
correcting function signatures throughout the code. And extern 
(c) int test() is irrelevant here because you are loading it via 
a different mechanism.


Re: Creating a .di file for a custom C library

2021-03-30 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Tuesday, 30 March 2021 at 04:01:12 UTC, Brad wrote:
I would like to use an updated version of the Termbox library 
(written in C) with D.  I have the .h file.  This is new 
territory for me (why try something easy - right?).  I think I 
need to create a .di file that corresponds to the .h file.  I 
also suspect that I need to put the library file (C code) into 
the project as a file somehow.  I am probably just not looking 
in the right place for the documentation, but I cannot seem to 
find a lot of guidance in this area.


Thanks in advance.


I never needed or used .di files. Dstep[1] can create d modules 
containing c header definitions. Recently, I used to create a d 
binding [2] for shapelib[3]. I just added "module shapelib;" at 
the beginning of the file, nothing else. Some c headers may 
require extra steps IMO.



1: https://github.com/jacob-carlborg/dstep
2: https://github.com/aferust/shapelib-d/blob/main/shapelib.d
3: https://github.com/OSGeo/shapelib



Re: Creating 1000 instances

2021-02-19 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Friday, 19 February 2021 at 10:02:05 UTC, Siemargl wrote:
On Friday, 19 February 2021 at 08:29:36 UTC, Ferhat Kurtulmuş 
wrote:


Since classes are reference types all instances of files will 
be the same reference of "new File()", which you probably 
don't want.


Is any differences between x and y definitions?

MyClass [] x, y;
x = new MyClass[7];

y= new MyClass[](8);


Although I don't usually use the latter, I can say online d 
editor yields the same ASM output for both:


File[] files = new File[10];
File[] files = new File[](10);


Re: Creating 1000 instances

2021-02-19 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Friday, 19 February 2021 at 08:29:36 UTC, Ferhat Kurtulmuş 
wrote:
On Friday, 19 February 2021 at 08:04:19 UTC, Виталий Фадеев 
wrote:

[...]


files = new File[]( 1000 );
files[] = new File(); // add this

Since classes are reference types all instances of files will 
be the same reference of "new File()", which you probably don't 
want.


You can do

files[].each!((ref a) => a = new File);


Re: Creating 1000 instances

2021-02-19 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Friday, 19 February 2021 at 08:41:06 UTC, Ferhat Kurtulmuş 
wrote:
On Friday, 19 February 2021 at 08:29:36 UTC, Ferhat Kurtulmuş 
wrote:
On Friday, 19 February 2021 at 08:04:19 UTC, Виталий Фадеев 
wrote:

[...]


files = new File[]( 1000 );
files[] = new File(); // add this

Since classes are reference types all instances of files will 
be the same reference of "new File()", which you probably 
don't want.


You can do

files[].each!((ref a) => a = new File);


oh, now we can remove brackets

files.each!((ref a) => a = new File);


Re: Creating 1000 instances

2021-02-19 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Friday, 19 February 2021 at 08:04:19 UTC, Виталий Фадеев wrote:

We have:
class File
{
// WIN32_FIND_DATAW data;
}

void fastReadDir()
{
File[] files;

// reserve space, allocating instances
files = new File[]( 1000 );  // <--- trouble here ?

// filling instances
auto file = files.ptr;

writeln( file.data );// <--- or trouble here ?

// ...
}

Got:
SegFault

Goal:
Allocate memory for 1000 instances at once.

Source:
https://run.dlang.io/is/xfaXcv

Question:
What is the true, fastest, beauty way to create 1000 
instances of the class File ?


files = new File[]( 1000 );
files[] = new File(); // add this

Since classes are reference types all instances of files will be 
the same reference of "new File()", which you probably don't want.




Re: Web crawler/scraping

2021-02-17 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Wednesday, 17 February 2021 at 12:12:56 UTC, Carlos Cabral 
wrote:

Hi,
I'm trying to collect some json data from a website/admin panel 
automatically, which is behind a login form.


Is there a D library that can help me with this?

Thank you


I found this but it looks outdated:

https://github.com/gedaiu/selenium.d


Re: Real simple unresolved external symbols question...

2021-02-10 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Tuesday, 9 February 2021 at 19:37:17 UTC, WhatMeWorry wrote:


I'm trying to create a super simple dynamic library consisting 
of two files:


[...]


remove /NOENTRY, and include "mixin SimpleDllMain;" in one of the 
sources. And link with druntime.


link /DLL file2.obj fileB.obj druntime-ldc.lib msvcrt.lib


Need help for opencvd git submoduling

2021-02-07 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
I am wrapping opencv::cuda modules based on c/c++ wrapper files 
of gocv. This might be more of a git question. Can one link a 
folder from a repo to be a subfolder of another git repo?

Do I have any option other than submoduling the entire Go repo?

I want "https://github.com/hybridgroup/gocv/tree/release/cuda; to 
be "https://github.com/aferust/opencvd/tree/master/c/cuda;


Re: list system drives

2021-02-01 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Tuesday, 2 February 2021 at 06:31:27 UTC, Виталий Фадеев wrote:

Give, please, Dlang tools for list system drives.

Some like a:
enumVolumes(); // [ 'C:\', 'D:\' ]


I have found this code by a google search. I don't know who the 
author was. I had to touch it a little since the codebase was old.


https://gist.github.com/aferust/5cc3209a6b6caf1062271a082c093b87


Re: How do I get the output of the time bash command?

2021-01-27 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Wednesday, 27 January 2021 at 09:35:21 UTC, Anthony wrote:


I'm trying to read the timed output of a pipeShell command but 
it only results in empty output.


Does anyone know why this is?


```
auto p = pipeShell("time ls");

foreach(str; p.stdout.byLine) {
writefln("%s",str);
}
```


Probably, just getting a string output is not enough. It looks a 
little outdated, but there is this library:


https://code.dlang.org/packages/dexpect


Re: How to covert dchar and wchar to string?

2021-01-25 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Monday, 25 January 2021 at 18:45:11 UTC, Rempas wrote:
Actually what the title says. For example I have dchar c = 
'\u03B3'; and I want to make it into string. I don't want to 
use "to!string(c);". Any help?


if you are trying to avoid GC allocations this is not what you 
want.


dchar c = '\u03B3';

string s = "";
s ~= c;

writeln(s);
writeln(s.length); // please aware of this

Some useful things:

string is immutable(char)[]
wstring is immutable(wchar)[]
dstring is immutable(dchar)[]

if you have a char[]:
you can convert it to a string using assumeUnique:

import std.exception: assumeUnique;

char[] ca = ...

string str = assumeUnique(ca); // similar for dchar->dstring and 
wchar->wstring




Re: Can we use strings with scanf?

2021-01-25 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Monday, 25 January 2021 at 17:38:21 UTC, Rempas wrote:

On Monday, 25 January 2021 at 10:33:14 UTC, Mike Parker wrote:

On Monday, 25 January 2021 at 09:16:11 UTC, Rempas wrote:

[...]


The * has a different meaning for scanf than for printf ([1] 
vs [2]).


There's also the issue that a string is immutable(char)[].

If you really, really, really, must use scanf:

```
char[bufSize] buf;
scanf("%s", buf.ptr);
```

But please don't. This is D, not 1990s C.

[1] https://www.cplusplus.com/reference/cstdio/scanf/
[2] https://www.cplusplus.com/reference/cstdio/printf/


Thanks! Actually for some reason. It won't accept a char[size]. 
I created a heap allocated (with pureFree and pureMalloc) 
chrar*, then used fgets() and created an empty string and 
looped through the result adding one by one character until the 
'\n' which is not included.


char[buffsize] works if buffsize is a compile time constant. Or 
just char[1024]. İt is a static array, and it's size must be 
defined at compile time.


Re: How define accepted types in a template parameter?

2021-01-16 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Saturday, 16 January 2021 at 18:39:03 UTC, Marcone wrote:
For example, I want my function template to only accept integer 
or string;


There are different ways of doing that. I'd say this one is easy 
to follow:


import std.stdio;

void print(T)(T entry) if(is(T==string) || is(T==int))
{
writeln(entry);

}

void main(){
int i = 5;
string foo = "foo";

double j = 0.6;

print(i);
print(foo);
print(j); // compilation error
}


  1   2   3   >