Re: Challenge Tuples

2024-04-27 Thread Sergey via Digitalmars-d-learn

On Friday, 26 April 2024 at 13:25:34 UTC, Salih Dincer wrote:
You have a 5-item data tuples as Tuple(1, 2, 3, [1, 3], 5) and 
implement the sum (total = 15) with the least codes using the 
sum() function of the language you are coding...



Let's start with D:

```d
import std.typecons : tuple;
import std.algorithm : sum;

void main()
{
  auto t = tuple(1, 2, 3, [1, 3], 5);

  int[] arr;
  t.each!(e => arr ~= e);
  assert(arr.sum == 15);
}
```
I bet you won't be able to do it this easily with other 
languages!  Note: I tried with C# and Python and it didn't work!


For Python it is possible to use something like:
```python
t = (1,2,3,[1,3],5)
for e in t:
a.append(e) if isinstance(e, int) else a.extend(e)
print(sum(a))
```



Re: Recommendations on porting Python to D

2024-04-25 Thread Sergey via Digitalmars-d-learn

On Wednesday, 24 April 2024 at 22:07:41 UTC, Chris Piker wrote:


Python-AST to D source converter may already exist?


Another possible way maybe is using C :)
Python -> C -> D
https://wiki.python.org/moin/PythonImplementations#Compilers


Re: Recommendations on porting Python to D

2024-04-24 Thread Sergey via Digitalmars-d-learn

On Wednesday, 24 April 2024 at 19:50:45 UTC, Chris Piker wrote:

Hi D

I have a somewhat extensive CGI based web service written in


There is also https://code.dlang.org/packages/arsd-official%3Acgi


Re: Why is this code slow?

2024-03-28 Thread Sergey via Digitalmars-d-learn

On Thursday, 28 March 2024 at 20:18:10 UTC, rkompass wrote:

D advantage is gone here, I would say.


It's hard to compare actually.
Std.parallelism has a bit different mechanics, and I think easier 
to use. The syntax is nicer.


OpenMP is an well-known and highly adopted tool, which is also 
quite flexible, but usually used with initially sequential code. 
And the syntax is not very intuitive.


Interesting point from Dr Russel here: 
https://forum.dlang.org/thread/qvksmhwkaxbrnggsv...@forum.dlang.org


However since 2012 OpenMP also got some development and 
improvement and HPC world is pretty conservative. So it is one of 
the most popular tool in the area: 
https://www.openmp.org/wp-content/uploads/sc23-openmp-popularity-mattson.pdf
With MPI.. But probably with AI and GPU revolution the balance 
will shift a bit to CUDA-like technologies.


Re: Why is this code slow?

2024-03-24 Thread Sergey via Digitalmars-d-learn

On Sunday, 24 March 2024 at 22:16:06 UTC, rkompass wrote:
Are there some simple switches / settings to get a smaller 
binary?


1) If possible you can use "betterC" - to disable runtime
2) otherwise
```bash
--release --O3 --flto=full -fvisibility=hidden 
-defaultlib=phobos2-ldc-lto,druntime-ldc-lto -L=-dead_strip -L=-x 
-L=-S -L=-lz

```


Re: Why is this code slow?

2024-03-24 Thread Sergey via Digitalmars-d-learn

On Sunday, 24 March 2024 at 19:31:19 UTC, Csaba wrote:
As you can see the function that does the job is exactly the 
same in C and D.

Not really..

The speed of Leibniz algo is mostly the same. You can check the 
code in this benchmark for example: 
https://github.com/niklas-heer/speed-comparison


What you could fix in your code:
* you can use enum for BENCHMARKS and ITERATIONS
* use pow from core.stdc.math
* use sw.reset() in a loop

So the main part could look like this:
```d
auto sw = StopWatch(AutoStart.no);
sw.start();
foreach (i; 0..BENCHMARKS) {
result += leibniz(ITERATIONS);
total_time += sw.peek.total!"nsecs";
sw.reset();
}
sw.stop();
```


Re: The std.file rename method fails in the docker environment.

2024-03-13 Thread Sergey via Digitalmars-d-learn

On Wednesday, 13 March 2024 at 21:49:55 UTC, zoujiaqing wrote:

this is bug in D.


It seems like a bug in Hunt-framework.
And Hunt - is an abandoned project.



Re: Recommendation about templating engine library

2024-03-11 Thread Sergey via Digitalmars-d-learn

On Monday, 11 March 2024 at 15:34:11 UTC, Andrea wrote:

There is also diet : https://code.dlang.org/packages/diet-ng


Is'nt `diet` specific for HTML / XML structured text ?


right. Just mentioned Go library also mostly for HTML generation.


Re: Recommendation about templating engine library

2024-03-11 Thread Sergey via Digitalmars-d-learn

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

Opinions ?

Many thanks


There is also diet : https://code.dlang.org/packages/diet-ng


Re: vibe.d still does not work on FreeBSD.

2024-02-18 Thread Sergey via Digitalmars-d-learn

On Sunday, 18 February 2024 at 13:23:53 UTC, Alain De Vos wrote:

DEFAULT_VERSIONS+= ssl=openssl111


Maybe also could be helpful to share your dub.json, compiler 
version and OS version as well.


Re: length's type.

2024-02-09 Thread Sergey via Digitalmars-d-learn

On Friday, 9 February 2024 at 08:04:56 UTC, Danilo wrote:

Rust, Nim, Zig, Odin…?

Here is the Forum for D(lang). ;)


But it is fine to see what others have..
Teach on their experience is useful

This is how research is going


Re: How to unpack a tuple into multiple variables?

2024-02-05 Thread Sergey via Digitalmars-d-learn

On Monday, 5 February 2024 at 21:12:58 UTC, Gary Chike wrote:
I hope all is well with everyone. I have come to an impasse. 
What is the best way to unpack a tuple into multiple variables 
in D similar to this Python code? Thank you!


### TL;DR
The direct implementation still not presented. But there are 
other ways to have similar functionality, as with AliasSeq 
example.


### Some related posts
* 
https://forum.dlang.org/post/rlrnhyaxcetaczjpd...@forum.dlang.org
* 
https://forum.dlang.org/thread/xaejpgrhjzccnllcv...@forum.dlang.org
* 
https://forum.dlang.org/thread/kvvvidfkasezljfhk...@forum.dlang.org


In those posts you can find other "solutions", Tuple DIP 
description and other useful ideas.


Re: Accessing array elements with a pointer-to-array

2024-01-26 Thread Sergey via Digitalmars-d-learn

On Friday, 26 January 2024 at 11:38:39 UTC, Stephen Tashiro wrote:

On Thursday, 25 January 2024 at 20:36:49 UTC, Kagamin wrote:
On Thursday, 25 January 2024 at 20:11:05 UTC, Stephen Tashiro 
wrote:

void main()
{
   ulong [3][2] static_array = [ [0,1,2],[3,4,5] ];
   static_array[2][1] = 6;
}


The static array has length 2, so index 2 is out of bounds, 
must be 0 or 1.


I understand that the index 2 is out of bounds in an array of 2 
things.  I'm confused about the notation for multidimensional 
arrays.  I thought that the notation uint[m][n] is read from 
right to left, so it denotes n arrays of m things in each 
array.  So I expected that static_array[k][j] would denotes the 
kth element of the jth array.


Yes, it is a bit tricky
Check this nice article if you are interested 
https://tastyminerals.github.io/tasty-blog/dlang/2020/03/22/multidimensional_arrays_in_d.html


Re: Accessing array elements with a pointer-to-array

2024-01-25 Thread Sergey via Digitalmars-d-learn
On Thursday, 25 January 2024 at 20:11:05 UTC, Stephen Tashiro 
wrote:
Can the elements of an array be accessed with a pointer using 
the usual indexing notation (e.g."[2][0]") for array elements? 
- or must we treat the elements associated with the pointer as 
1-dimensional list and use pointer arithmetic?


A more elementary question is why array index 2 is 
out-of-bounds in the following

code, which won't compile:



Be aware of the different dimension size of static and dynamic 
arrays


```d
void main()
{
import std;

ulong [3][2] static_array = [ [0,1,2],[3,4,5] ];
ulong [][] dynamic_array;

ulong *pointer;
ulong[]* dpointer;

dynamic_array = new ulong[][](3,2);

static_array[1][1] = 6;
dynamic_array[2][1] = 6;

writeln(static_array);
pointer = static_array.ptr.ptr;
writef("*pointer[1][1] = %d\n", *(pointer+4));

writeln(dynamic_array);
dpointer = dynamic_array.ptr;
writef("*pointer[2][1] = %d\n", dpointer[2][1]);
}
```



Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-14 Thread Sergey via Digitalmars-d-learn

On Sunday, 14 January 2024 at 17:11:27 UTC, Renato wrote:
If anyone can find any flaw in my methodology or optmise my 
code so that it can still get a couple of times faster, 
approaching Rust's performance, I would greatly appreciate 
that! But for now, my understanding is that the most promising 
way to get there would be to write D in `betterC` style?!


I've added port from Rust in the PR comment. Can you please check 
this solution?
Most probably it need to be optimized with profiler. Just 
interesting how close-enough port will work.


Re: The One Billion Row Challenge

2024-01-13 Thread Sergey via Digitalmars-d-learn

On Saturday, 13 January 2024 at 23:25:07 UTC, monkyyy wrote:

On Thursday, 11 January 2024 at 11:21:39 UTC, Sergey wrote:
On Thursday, 11 January 2024 at 08:57:43 UTC, Christian 
Köstlin wrote:

Did someone already try to do this in dlang?
I guess it will be very hard to beat the java solutions 
running with graalvm!


https://news.ycombinator.com/item?id=38851337

Kind regards,
Christian


I think C++ people already beated Java's performance 
https://github.com/buybackoff/1brc?tab=readme-ov-file#native


I feel we could beat c++ if they didn't radix sort


The project is very hard. Many optimizations and tricks were 
applied by others.
It requires a lot of skill to implement everything on a high 
level.


Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-13 Thread Sergey via Digitalmars-d-learn

On Saturday, 13 January 2024 at 19:35:57 UTC, Renato wrote:

On Saturday, 13 January 2024 at 17:00:58 UTC, Anonymouse wrote:

On Saturday, 13 January 2024 at 12:55:27 UTC, Renato wrote:

[...]
I will have to try it... I thought that `BigInt` was to blame 
for the slowness (from what I could read from the trace logs), 
but after replacing that with basically a byte array key (see 
[commit 
here](https://github.com/renatoathaydes/prechelt-phone-number-encoding/commit/0e9025b9aacdcfef5a2649be4cc82b9bc607fd6c)) it barely improved. It's still much slower than Common Lisp and very, very far from Java and Rust.


In the repo is hard to find the proper version.
I've checked the Rust from master branch and it looks a bit 
different from D implementation..


I would suggest to rewrite in the same way as Rust implemented.
Probably you would like to try:
* do not use BigInt from std. It could be quite slow. Try to use 
GMP library from Dub instead

* don't do "idup" every time
* instead of byLine, try byLineCopy
* instead of "arr ~= data" try to use Appender 
(https://dlang.org/library/std/array/appender.html)
* also you could try to use splitter 
(https://dlang.org/library/std/algorithm/iteration/splitter.html) 
to lazily process each part of the data
* isLastDigit function has many checks, but I think it could be 
implemented easier in a Rust way
* also consider to use functions from Range (filter, map) as you 
use it in Rust, instead of using for loops


Re: How to use ImportC to import WebGPU header

2024-01-12 Thread Sergey via Digitalmars-d-learn

On Friday, 12 January 2024 at 11:06:39 UTC, Bkoie wrote:

On Thursday, 11 January 2024 at 15:18:08 UTC, Sergey wrote:

On Wednesday, 10 January 2024 at 23:36:33 UTC, JN wrote:
I would like to use ImportC to automatically import a C 
header into my D project.


It was already done. Use it 
https://code.dlang.org/packages/wgpu-d

Don't reinvent the wheel :)


or if you push a package atleast document the code or give 
example
D is not like rust where you can just dive into a lib without 
docs or example


Not my package, but I see it has several separate sub-repos for 
examples:

This package provides sub packages which can be used individually:

wgpu-d:enumerate - Enumerate GPU adapters example
wgpu-d:headless - Headless (windowless) rendering example
wgpu-d:triangle - Triangle (windowed) example
wgpu-d:cube - Cube (windowed) example


Re: How to use ImportC to import WebGPU header

2024-01-11 Thread Sergey via Digitalmars-d-learn

On Wednesday, 10 January 2024 at 23:36:33 UTC, JN wrote:
I would like to use ImportC to automatically import a C header 
into my D project.


It was already done. Use it https://code.dlang.org/packages/wgpu-d
Don't reinvent the wheel :)



Re: The One Billion Row Challenge

2024-01-11 Thread Sergey via Digitalmars-d-learn
On Thursday, 11 January 2024 at 08:57:43 UTC, Christian Köstlin 
wrote:

Did someone already try to do this in dlang?
I guess it will be very hard to beat the java solutions running 
with graalvm!


https://news.ycombinator.com/item?id=38851337

Kind regards,
Christian


I think C++ people already beated Java's performance 
https://github.com/buybackoff/1brc?tab=readme-ov-file#native


Re: dlang.org/Learn "hello_world".sort.chain ...

2023-12-26 Thread Sergey via Digitalmars-d-learn

On Tuesday, 26 December 2023 at 13:58:54 UTC, tony wrote:

On Tuesday, 26 December 2023 at 11:19:29 UTC, Sergey wrote:


Use typeid, instead of typeof


Thanks!

Got quite a type but I will worry about that later: 
std.range.SortedRange!(Result, "a < b").SortedRange


Yes, because sort is returning special type, compatible with 
Ranges interface.
You can add 'sort(...).array' and the type will become 'int[]' 
(or which types arrays were before).


Ranges are specific things for D (one of the core feature of the 
lang and std), which can evaluated lazily. You can check some 
description how they are working in the documentation 
https://dlang.org/phobos/std_range.html


Re: dlang.org/Learn "hello_world".sort.chain ...

2023-12-26 Thread Sergey via Digitalmars-d-learn

On Tuesday, 26 December 2023 at 10:53:10 UTC, Tony wrote:
I just typed in the program that is on the first page of Learn. 
It has this line:


sort(chain(arr1, arr2, arr3));

I assigned that to a variable:

arr4 = sort(chain(arr1, arr2, arr3));

then printed it out

writefln("%s",arr4);   // works

and then tried to print out the type of arr4:

writefln("%s",typeof(arr4));

and got this error:

// HelloWorld.d:25:19: error: cannot pass type 
SortedRange!(Result, "a < b") as a function argument


What exactly is that type? Or maybe, what would it take to 
understand what that type is?


Use typeid, instead of typeof


Re: macOS Sonoma Linker Issue

2023-12-22 Thread Sergey via Digitalmars-d-learn

On Friday, 22 December 2023 at 17:45:27 UTC, Renato wrote:


I'm afraid I've lost interest to make it work at this point :(


Did you add "-L-ld_classic"?


Re: D is a great language, but I've had a bad experience getting started

2023-12-14 Thread Sergey via Digitalmars-d-learn

On Thursday, 14 December 2023 at 13:27:29 UTC, Renato wrote:

On Thursday, 14 December 2023 at 13:12:06 UTC, Richard (Rikki)

My build options are currently:

```
"dflags-dmd": [ "-v"],
"lflags": ["-ld_classic"]
```

I tried some variations but nothing worked.


Previously for macOS it was required to write “export 
MACOSX_DEPLOYMENT_TARGET=11”


Also remove dmd/dub first. Then try to use LDC from official 
GitHub Release. And update the PATH variable. Maybe script from 
the official download page is doing the same - idk.


At least this is what I’m using on macOS (but M1). DMD just 
doesn’t exist for me anymore)


Re: How to hash SHA256 from string?

2023-12-02 Thread Sergey via Digitalmars-d-learn

On Saturday, 2 December 2023 at 15:30:39 UTC, zoujiaqing wrote:

SHA

Sorry for OT, but don’t know different place to reach you out.
What is the status of Archttp? Is it discontinued/abandoned?


Re: Advent of Code 2023

2023-12-02 Thread Sergey via Digitalmars-d-learn
On Saturday, 2 December 2023 at 13:33:33 UTC, Johannes 
Miesenhardt wrote:


Day 1 solution here, since I swap them out based on a runtime 
argument.


In the Discord server we also have a topic about AoC2023. So feel 
free to join it as well.


Some other solutions that could be worth to check:

https://github.com/andrewlalis/AdventOfCode2023/blob/main/day_1/solution.d
https://github.com/schveiguy/adventofcode/blob/master/2023/day1/trebuchet.d


Re: Advent of Code 2023

2023-12-01 Thread Sergey via Digitalmars-d-learn
On Friday, 1 December 2023 at 01:01:31 UTC, Siarhei Siamashka 
wrote:
Advent of Code 2023 starts in a few hours from now. I suggest 
to discuss D language solutions here.
But to avoid spoilers, it's best to do this with a 24h delay 
after each puzzle is published.


Hi Siarhei. Nice to see that you are still around D forums. I 
thought you moved to Crystall.


Re: How do I install a package globally?

2023-11-11 Thread Sergey via Digitalmars-d-learn

On Saturday, 11 November 2023 at 01:50:54 UTC, Trevor wrote:
I'm just getting in to D , coming from a C and Python 
background. I've had a play with DUB and adding packages to my 
project, but it seems like there should be a way to install 
packages so they can be used in any D program I compile without 
creating a whole package. For example in Python you can just go 
"pip install abc" and then any script can use abc.


How does one install packages globally, and how can I write 
programs that use the third-party packages without being 
wrapped in a dub file?


And honestly it is not the best behavior. This is why in python 
world so popular solutions with conda/pip virtual environments.


Re: performance issues with SIMD function

2023-11-03 Thread Sergey via Digitalmars-d-learn

On Friday, 3 November 2023 at 15:11:31 UTC, Bogdan wrote:

Hi everyone,

I was playing around with the intel-intrinsics library, trying 
to improve the speed of a simple area function. I could not see 
any performance improvements from the non-SIMD implementation. 
The SIMD version is a little bit slower even with LDC2 and 
--o3. Can anyone help me to understand what I am missing?


Thanks!
Bogdan


In your SIMD algorithm has not so many gain from using SIMD. The 
length of the loop is the same.
Also probably compiler applying some optimizations in regular 
versions, that doing almost the same.


Re: What are the best available D (not C) File input/output options?

2023-11-02 Thread Sergey via Digitalmars-d-learn

On Thursday, 2 November 2023 at 15:46:23 UTC, confuzzled wrote:
I've ported a small script from C to D. The original C version 
takes roughly 6.5 minutes to parse a 12G file while the port 
originally took about 48 minutes.


In my experience I/O in D is quite slow.
But you can try to improve it:

Try to use std.outbuffer instead of writeln. And flush the result 
only in the end.


Also check this article. It is showing how manual buffers in D 
could speed up the processing of files significantly: 
https://tech.nextroll.com/blog/data/2014/11/17/d-is-for-data-science.html





Re: Question regarding mir.csv.

2023-11-01 Thread Sergey via Digitalmars-d-learn

On Wednesday, 1 November 2023 at 20:49:16 UTC, Zz wrote:

Hi,

Currently using std.csv and would like to do the following 
using mir.csv.


auto data = std.csv.csvReader!Layout(input).array;

Are there any examples out there on using mir.csv?

Regards,
Zz


you can find some examples in source code:
https://github.com/libmir/mir-ion/blob/master/source/mir/csv.d


Re: Symbolic computations in D

2023-10-30 Thread Sergey via Digitalmars-d-learn

On Monday, 30 October 2023 at 13:13:47 UTC, jmh530 wrote:

On Sunday, 29 October 2023 at 10:44:03 UTC, ryuukk_ wrote:
Julia is more an alternative to R, Matlab, Python than C++.


Not really.

Many especially popular and widely used (NumPy, PyTorch, 
data.table) libraries for R and Python implemented with C/C++. 
Without using them, it is just impossible to get good performance.


So there is "2 language" problem. Someone should create C++ 
engine + Python/R interface.
Julia propose to solve this issue - since you are able to 
implement fast engine and interface both in Julia.


Re: how to assign multiple variables at once by unpacking array?

2023-10-07 Thread Sergey via Digitalmars-d-learn

On Saturday, 7 October 2023 at 16:12:47 UTC, mw wrote:
Interesting: in terms of easy of coding, clarity and future 
maintenance, which one is superior?


There is no superior languages. They can successfully co-exist 
and play in different areas.


The one liner in Python, or your "solution" with dozen lines of 
code? BTW, is that a solution at all? Did it achieved what the 
original goal asked in the OP question?


AFAIK No, D doesn’t have this feature (still). But you can write 
some kind of workaround code that will do similar thing, but not 
exactly what you want. Probably solution in SO is the closest one.


Re: D web browser?

2023-09-08 Thread Sergey 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).


Seems something similar to Selenium tool (I've used it with 
Python in the past).


There is outdated package 
https://code.dlang.org/packages/selenium-d

Probably will be good to make it ~~great~~ alive again =)


Re: aarch64 plans for D lang ?

2023-08-28 Thread Sergey via Digitalmars-d-learn

On Monday, 28 August 2023 at 15:14:52 UTC, BrianLinuxing wrote:

On Monday, 28 August 2023 at 15:04:25 UTC, Sergey wrote:

On Monday, 28 August 2023 at 14:38:36 UTC, BrianLinuxing wrote:

Afternoon all,

I think D Lang has such potential :)


Both GDC and LDC should support Linux aarch64. LDC even has 
file in Releases 
https://github.com/ldc-developers/ldc/releases/tag/v1.34.0


Thank you that looks good :)

But is it the full installer and all of the bits?




Any helpful pointers would be useful, thanks :)


I never worked with Pi boards, but in the archive from release 
should be binaries and some internal libraries. Usually just 
unzip + put some environment variables/path is enough.


Also this is bit outdated example (not mine): 
https://gist.github.com/shabunin/8e3af1725c1c45f225174e9c2ee1557a

Maybe it could be reused.

There is also a docker container 
(https://github.com/Reavershark/ldc2-raspberry-pi) where you can 
try to build software for Pi on your regular computer.


Moreover you can try the same installation script as in your 
first message, but use -ldc instead of -dmd in the end. But I 
think using files from GitHub Releases of official LDC repo will 
be better and easier.




Re: aarch64 plans for D lang ?

2023-08-28 Thread Sergey via Digitalmars-d-learn

On Monday, 28 August 2023 at 14:38:36 UTC, BrianLinuxing wrote:

Afternoon all,

I think D Lang has such potential :)


Both GDC and LDC should support Linux aarch64. LDC even has file 
in Releases 
https://github.com/ldc-developers/ldc/releases/tag/v1.34.0





Re: parallel threads stalls until all thread batches are finished.

2023-08-23 Thread Sergey via Digitalmars-d-learn

On Wednesday, 23 August 2023 at 13:03:36 UTC, Joe wrote:

I use

foreach(s; taskPool.parallel(files, numParallel))
{ L(s); } // L(s) represents the work to be done.


If you make for example that L function return “ok” in case file 
successfully downloaded, you can try to use TaskPool.amap.


The other option - use std.concurrency probably.




Mach status support

2023-08-21 Thread Sergey via Digitalmars-d-learn
When I worked with one C code translation, I found that command 
clock_gettime, that available in POSIX systems is not implemented 
in MacOS.

This SO thread

https://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x

suggested some workaround implementations, which using some mach 
headers like mach.h and mach_time.h


But when I’ve checked dmd sources

https://github.com/dlang/dmd/tree/master/druntime/src/core/sys/darwin/mach

I didn’t find it. So currently I’ve used MonoTime as temporary 
solution (however I’m not sure if it is a proper alternative).


How full is dmd specific implementation of Darwin and Mach 
headers?

Any plans to improve it (in case it is not full right now)?


Re: dub does not correctly link on Macbook Pro 2019 (intel)

2023-08-19 Thread Sergey via Digitalmars-d-learn

On Saturday, 19 August 2023 at 21:35:25 UTC, Alexander wrote:

Completely new to D, and when trying to setup the toolchain,


Could you please specify the versions of macOS and DMD?
Probably DMD is broken for macOS - could you try to use LDC?

Maybe this thread is relative to the problem: 
https://github.com/ldc-developers/ldc/issues/3864




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

2023-08-14 Thread Sergey 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++
Error: linker exited with status 1


Hola.
On the page https://dlang.org/spec/cpp_interface.html
commands to run also have different flags. Did you try them?

g++ -c foo.cpp
dmd bar.d foo.o -L-lstdc++ && ./bar


Re: Garbage Collectors

2023-07-19 Thread Sergey via Digitalmars-d-learn

On Wednesday, 19 July 2023 at 07:24:06 UTC, IchorDev wrote:
So, D’s default garbage collector is the one named 
“conservative” in DRuntime…
I see there’s also “manual” which doesn’t actually function as 
a GC, which is interesting.

Nothing says what ProtoGC is… so I guess it’s useless.
Has anyone ever published any custom GCs? A search through the 
dub package registry yielded nothing. How hard would it be to 
port (for instance) a Java GC to D’s interface?


Forking GC was introduced some time ago. But I don't think it is 
quite different from regular 
(https://forum.dlang.org/post/tf8mbo$1jvp$1...@digitalmars.com)


There are some posts about it GCs, but I don't think anything was 
released.

https://forum.dlang.org/thread/jquklsqxtfgvsezrc...@forum.dlang.org?page=1
https://forum.dlang.org/post/yonbmhifafbyjhwpc...@forum.dlang.org



Re: Installing GDC / Linux / x86-64 when apt-get doesn’t work

2023-07-10 Thread Sergey via Digitalmars-d-learn

On Tuesday, 11 July 2023 at 04:11:38 UTC, Cecil Ward wrote:
I’m trying to install GDC on a new Linux box and I don’t know 
what I’m doing. Background: I have installed LDC successfully 
and have installed GDC on a Raspberry Pi using 32-bit ARM.


For some reason the apt-get command doesn’t work on this 
machine, don’t know why. The machine is a virtual server hosted 
on the internet and I can get support for the o/s.


What is the recommended procedure for fetching the x86-64 
prec-compiled GDC?


Check the web about reprex and write what have you tried to run, 
which error you got, some more information about the system, root 
rights.


Have you tried to download deb package manually and use dpkg 
command?


Re: Options for Cross-Platform 3D Game Development

2023-07-06 Thread Sergey via Digitalmars-d-learn

On Wednesday, 5 July 2023 at 22:27:46 UTC, Andrew wrote:
So, I've gotten the itch to have a go at game development in D, 
after doing a bit of it in Java last year. I've previously used 
LWJGL, which is a java wrapper for OpenGL, OpenAL, GLFW, and 
some other useful libs.


Are there any other recommendations for cross-platform 
rendering libraries? Of course I could use a pre-made game 
engine like Unity or Godot, but for me, most of the fun is in 
making the engine.


There is a Hipreme Engine (written in D):

Check it out on the GitHub:
https://github.com/MrcSnm/HipremeEngine


Re: Graphing

2023-07-01 Thread Sergey via Digitalmars-d-learn

On Saturday, 1 July 2023 at 01:00:46 UTC, anonymouse wrote:
How would I go about graphing time series data (specifically, 
candles, moving averages, etc) in D and dynamically updating 
such charts?


Thanks,
--anonymouse


For TS you can use http://mir-algorithm.libmir.org/mir_series.html
For plotting https://code.dlang.org/packages/ggplotd


Re: Lockstep iteration in parallel: Error: cannot have parameter of type `void`

2023-05-20 Thread Sergey via Digitalmars-d-learn

On Saturday, 20 May 2023 at 18:27:47 UTC, Ali Çehreli wrote:

On 5/20/23 04:21, kdevel wrote:
And I've just discovered something. Which one of the following 
is the expected documentation?


  https://dlang.org/library/std/parallelism.html

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

What paths did I take to get to those? I hope I will soon be 
motivated enough to fix such quality issues.


Ali


They both. Different versions of documentation generator afaik



Re: How does the function 'iota' get its name?

2023-02-12 Thread Sergey via Digitalmars-d-learn
On Sunday, 12 February 2023 at 19:39:49 UTC, Steven Schveighoffer 
wrote:

On 2/12/23 2:17 PM, ccmywish wrote:

Hi, everyone!

I'm very new to D. I see a function called 
[iota](https://dlang.org/library/std/range/iota.html)


`Iota` seems a [Greek 
letter](https://en.wikipedia.org/wiki/Iota). Why does it 
relate to range?


It came from C++. See notes here: 
https://en.cppreference.com/w/cpp/algorithm/iota


-Steve


Which took it from APL
https://aplwiki.com/wiki/Index_Generator


Re: Tab completion using neovim

2023-01-21 Thread Sergey via Digitalmars-d-learn

On Saturday, 21 January 2023 at 13:17:44 UTC, Alain De Vos wrote:

Let's say i write
"write" press tab in neovim i want it to guess "writeln".
How to configure neovim for this.
[ Note "ncm2" lets my neovim crash. But maybe there are 
alternatives ]


[ vscode is not an option as compiling electron takes ages]


Is Ctrl+Space doing suggestion?
It could also be “writefln”.. so it should make several 
suggestions.


Re: Pyd examples or resources for Python 3.x

2023-01-19 Thread Sergey via Digitalmars-d-learn

On Friday, 20 January 2023 at 00:39:47 UTC, Seamus wrote:

Howdy folks



Honestly in my opinion PyD looks kinda abounded.
I don’t know how much effort you need to spend to run spaCy.
Just to be sure that you’ve seen this documentation 
https://pyd.readthedocs.io/en/latest/index.html


Also probably if you will find C API (as it is written in Cython) 
it will be possible to make bindings for them using dstep, ctod 
or ImportC tools.


Or maybe it is possible to prepare D bindings like someone did 
for other C-like languages:

https://github.com/d99kris/spacy-cpp
https://github.com/AMArostegui/SpacyDotNet


Re: Solving optimization problems with D

2023-01-03 Thread Sergey via Digitalmars-d-learn

On Sunday, 1 January 2023 at 21:11:06 UTC, Ogi wrote:
I’ve read this [series if 
articles](https://www.gamedeveloper.com/design/decision-modeling-and-optimization-in-game-design-part-1-introduction) about using Excel Solver for all kinds of optimization problems. This is very neat, but of course, I would prefer to write models with code instead, preferably in D. I glanced at mir-optim but it requires knowledge of advanced math. Is there something more approachable for a layperson?


Maybe mir-optim and dopt are the only options.
You can check JuMP (Julia package and resources). Maybe port some 
of them to D will be the start of new optim solver package. But 
in general behind the optimisation problems always lying math..


Re: Float rounding (in JSON)

2022-12-30 Thread Sergey via Digitalmars-d-learn

On Thursday, 13 October 2022 at 19:00:30 UTC, Sergey wrote:
I'm not a professional of IEEE 754, but just found this 
behavior at rounding in comparison with other languages. I 
supose it happened because in D float numbers parsed as double 
and have a full length of double while rounding. But this is 
just doesn't match with behavior in other languages.


So there is no luck with std.json for me. But when std is not the 
solution, third party libraries could help. I've tried ASDF. This 
is kind of archived library, but it works well, its documentation 
is small and clear (mir-ion really needs to improve 
documentation).


So in asdf we could just serialize the json and it will 
automatically round numbers with the same **magic** logic for 
floating as other languages do.


The only thing: some numbers which are usually double could be 
presented in JSON as integers. Automatically asdf convert them to 
double too. In case you need to process them exactly as integers 
you could use Variant!(int, double) as a type of the data. And 
provide your custom serializer/deserializer as it is proposed in 
asdf documentation example.

http://asdf.libmir.org/asdf_serialization.html#.serializeToAsdf

PS Thanks to Steven for his suggestions in Discord.



Re: How to create a API server?

2022-12-18 Thread Sergey via Digitalmars-d-learn

On Friday, 16 December 2022 at 20:57:30 UTC, Dariu Drew wrote:
Hi! i need help in can i create a serve API, what library i 
should use? what documentation i should read?


Check the bench: https://github.com/tchaloupka/httpbench
there are a lot of web servers in D. You can find one that fits 
your needs :)


Re: How to compiler dlang code on Apple M1?

2022-12-14 Thread Sergey via Digitalmars-d-learn
On Tuesday, 13 December 2022 at 15:21:41 UTC, Steven 
Schveighoffer wrote:

On 12/13/22 10:20 AM, Steven Schveighoffer wrote:
Yeah, that's a known issue: 
https://github.com/ldc-developers/ldc/issues/3864


Try building with `-b plain` to avoid the debug build


Oh, also, I have MACOSX_DEPLOYMENT_TARGET=11 in my environment, 
that helps to avoid it as well.


-Steve


This export solves the issue (at least for me). Thanks Steven!


Re: unique_ptr | Unique for autoclose handle

2022-12-14 Thread Sergey via Digitalmars-d-learn
On Wednesday, 14 December 2022 at 11:30:07 UTC, Vitaliy Fadeev 
wrote:

Teach me the most beautiful way.
How to make beautiful?
Thanks!


Just for information there is a library that also could be 
helpful https://code.dlang.org/packages/autoptr


Re: Advent of Code 2022

2022-12-10 Thread Sergey via Digitalmars-d-learn
On Saturday, 10 December 2022 at 20:49:03 UTC, Christian Köstlin 
wrote:

Is anybody participating with dlang in the advent of code 22?
It would be interesting to discuss dlang specific things from 
the puzzles.


Kind regards,
Christian


https://forum.dlang.org/thread/adkugbopvfbcycknx...@forum.dlang.org


Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Sergey via Digitalmars-d-learn

On Sunday, 4 December 2022 at 12:37:08 UTC, Adam D Ruppe wrote:
All of the top 5 most popular libraries on code.dlang.org 
embrace the GC.


Interesting. It seems that most of the community suppose that 
“library” should be used from D :-)
But in my opinion - “foreign library experience” is much more 
important. The usage of D is not that wide… but if it will be 
possible to write library in D and use it from 
C/++/Python/R/JVM(JNI)/Erlang(NIF)/nameYourChoice smoothly it 
will be a win. Run fast (it could be Rust, Zig) extension/library 
from more high level/less safe/slower dynamic languages. And not 
only run but also write fast(here is D and Nim could be chosen).


Many languages do not have GC inside.. and others have their own. 
And if your library is going to manipulate objects from other 
languages with different memory management approach - it could be 
tricky to do that with GC. You need to make that both GC become 
friends


Re: Is defining get/set methods for every field overkill?

2022-11-22 Thread Sergey via Digitalmars-d-learn

On Tuesday, 22 November 2022 at 03:04:03 UTC, []() {}() wrote:

On Tuesday, 22 November 2022 at 02:16:16 UTC, []() {}() wrote:




nevermind ;-)  .. seems clear nobody wants something like this 
in D.


https://forum.dlang.org/post/kbl20f$2np9$1...@digitalmars.com

and... 20 years later ... .. .


Based on this (not too old) post the idea remains the same and 
approved by Walter’s experience:

https://dlang.org/blog/2018/11/06/lost-in-translation-encapsulation/
I saw some posts at forum about private-class-scope, but 
community of core-D is fine with module-unit approach I think.


Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Sergey via Digitalmars-d-learn

On Saturday, 19 November 2022 at 04:27:14 UTC, []() {}() wrote:
By making your class member variables public, it is not clear 
whether you forgot that you needed to validate incoming and 
outgoing values, or whether you don't need to do this (not 
ever).


If you did it because of the former, you're fired ;-)

If you did it because of the latter, you're also fired ;-)


Functional programming developers be like: "meh" :)


Re: Unit testing a function returning void

2022-11-03 Thread Sergey via Digitalmars-d-learn

On Thursday, 3 November 2022 at 10:00:27 UTC, Bruno Pagis wrote:

Good morning,

I would like to unit test the print function (yes, I know, not 
very useful on the above example since print is merely a 
duplicate of writeln...). Is there a way to use assert to test 
the output of the print function to stdout? Something like:


Just for curiosity: we have this tremendous list of testing 
libraries https://code.dlang.org/search?q=test


Maybe one of them has the 'capture stdout' 
(https://docs.pytest.org/en/7.1.x/how-to/capture-stdout-stderr.html) feature?


Re: dmd for Haiku OS

2022-10-31 Thread Sergey via Digitalmars-d-learn

On Thursday, 28 February 2019 at 13:17:44 UTC, MGW wrote:

Sorry for Zombie-thread. Just saw the news that wayland was 
ported to Haiku and was curious if somebody using D in it 
(https://discuss.haiku-os.org/t/my-progress-in-wayland-compatibility-layer/12373).


I have recently looked through Haiku OS and got surprised to 
find there dmd 2.072.
There was only running file but Phobos and DrinTime were 
missing.


Are there any plans to port dmd to Haiku OS nowadays?
Is there a manual (example) on dmd porting on Haiku OS?


I'm not sure, because there are many more important and more 
valuable things to do for main core developers. Haiku has very 
low market share and users.
But AFAIK Haiku is using GCC and has C++. So maybe (actually I 
don't know) it is possible to bootstrap GDC from some older 
versions.


Also some related links below, which could be helpful, just in 
case someone will find this thread and decided to try.

Haiku and DMD related links:
https://github.com/scythx/dlang-dmd-haiku
https://forum.dlang.org/post/bmflikxzfdvlbazfw...@forum.dlang.org
https://depot.haiku-os.org/#!/?bcguid=bc1-KHWR=besly,fatelk,haikuports=x86_64=FEATURED=dmd

Story about porting to OpenBSD:
https://briancallahan.net/blog/20210320.html

Good luck and have fun :)


Re: dub ldc2 static linking

2022-10-28 Thread Sergey via Digitalmars-d-learn

On Friday, 28 October 2022 at 04:02:15 UTC, ryuukk_ wrote:

On Friday, 28 October 2022 at 02:46:42 UTC, ryuukk_ wrote:

On Friday, 28 October 2022 at 01:35:04 UTC, kinke wrote:
For fully static linking on Linux, you'll need to move away 
from glibc to e.g. the musl C runtime, as used by the Alpine 
distro.


I'm just right now having an issue with glibc version mismatch 
for my server, so i'm looking to move to musl to avoid that 
kind of issues


Is there any guide to compile ldc with musl and then static 
link it?


Actually nvm, `-static` as mentioned above seems to be enough


Static on alpine is possible - be aware of ‘ldc-static’ package. 
But static and LTO is something harder.. is it even possible 
without re-compilation of ldc-runtime?
 
https://forum.dlang.org/thread/newwjfrebckphgwga...@forum.dlang.org




Re: Design question regarding saving changes in the original array and/or returning a new set

2022-10-23 Thread Sergey via Digitalmars-d-learn

On Sunday, 23 October 2022 at 15:47:27 UTC, matheus wrote:

Hi H. S. Teoh,

I think you misunderstood my question, since English is not my 
first language maybe this was a problem from my part, but 
anyway, I'm not talking about "sort" from main library.


This example was if I had designed my "own version".

Matheus.


Hi, Matheus. I'm not an expert in programming :)
But I believe it should be up to you. How you make your function.
If you will use "ref" in the parameter - you could operates 
exactly the same memory which will received in the parameter;
Also there are 'in','out', 'inout' parameters that could help 
with management on that question.


Re: Find in assoc array then iterate

2022-10-21 Thread Sergey via Digitalmars-d-learn

On Friday, 21 October 2022 at 22:03:53 UTC, Kevin Bailey wrote:

I'm trying to do this equivalent C++:

unordered_map map;

for (auto i = map.find(something); i != map.end(); ++i)
...do something with i...

in D, but obviously with an associative array. It seems that 
it's quite
easy to iterate through the whole "map", but not start from the 
middle.

Am I missing something obvious (or not so obvious) ?


How should that work, if map is unordered?

In D:
Implementation Defined: The built-in associative arrays do not 
preserve the order of the keys inserted into the array. In 
particular, in a foreach loop the order in which the elements are 
iterated is typically unspecified.

https://dlang.org/spec/hash-map.html


Alpine: static compilation

2022-10-21 Thread Sergey via Digitalmars-d-learn

Hi D-community.

I try to build and run very simple code on Alpine docker image - 
but have no luck with static builds and LTO.


The desired aim is to be able build it similar to C code 
compilation:

```c
gcc leibniz.c -o leibniz -O3 -s -static -flto -march=native 
-mtune=native -fomit-frame-pointer -fno-signed-zeros 
-fno-trapping-math -fassociative-math

```

I'd like to find working examples for both LDC and GDC for static 
compilation. If you have one, share it here please.


For LDC I've tried to install this packages:
```
RUN apk add --no-cache ldc gcc ldc-static binutils-gold
```
and build it with parameters:
```
cc=gcc ldc2 -O3 -release -mcpu=native -flto=full -linker=gold 
-flto-binary=/usr/bin/ld.gold 
-defaultlib=phobos2-ldc-lto,druntime-ldc-lto -m64 -static 
leibniz.d

```
Some issues that I've faced while trying different options:
- 'cc=clang' suddenly is not working. It still saying "can't find 
cc"
- Without explicit 'flto-binary=' the error was about "LLVMgold 
(plugin) not found".


The code:
```d
import std.stdio;
import std.file;

double pi = 1.0;
uint rounds;

void main() {
auto file = File("./rounds.txt", "r");
file.readf!"%d\n"(rounds);
rounds += 2u;
foreach(i; 2u .. rounds) {
double x = -1.0 + 2.0 * (i & 0x1);
pi += (x / (2u * i - 1u));
}
pi *= 4.0;
writefln("%.16f", pi);
}
```


Re: Catching C errors

2022-10-20 Thread Sergey via Digitalmars-d-learn
On Thursday, 20 October 2022 at 09:52:05 UTC, data pulverizer 
wrote:
I'm currently writing a D interop with R, the dynamic 
statistical programming language. There's a function called


How is your project related to EmbedR?

The description of the project could be found here: 
https://dlang.org/blog/2020/01/27/d-for-data-science-calling-r-from-d/


AFAIK Lance wants to re-write it to the second version with some 
improvements in the code.


Re: Hipreme's #1 Tip of the day

2022-10-20 Thread Sergey via Digitalmars-d-learn

On Wednesday, 19 October 2022 at 23:28:46 UTC, Hipreme wrote:
Hey guys, I'm going to start making a tip of the day (although 
I'm pretty sure I won't be able to give every day a tip), but 
those things are really interesting to newcomers to know and 
may be obvious to some of the old schoolers there.




Cool things! Thanks for you tips! Looking forward to see new ones 
to come soon :)


How do you think - if it will be possible to save them in some 
dedicated page (even just GitHub or blog) and share the link with 
community somewhere here:


https://wiki.dlang.org/The_D_Programming_Language (The structure 
of the page looks a little messy)


https://wiki.dlang.org/Tutorials - for example section of “Best 
practices”


And also two my fav sites in this theme D idioms - 
https://p0nce.github.io/d-idioms/ and D Garden - 
https://garden.dlang.io/
They could be good examples of how the page with tips could look 
like.





Re: library to solve the system of linear equations

2022-10-15 Thread Sergey via Digitalmars-d-learn

On Friday, 14 October 2022 at 21:38:45 UTC, Yura wrote:

On Friday, 14 October 2022 at 18:37:00 UTC, Sergey wrote:
however, when I try to compile it (gdc el.d) it gives me the 
following error message:


el.d:11:8: error: module ndslice is in file 'mir/ndslice.d' 
which cannot be read

 import mir.ndslice;
^
import path[0] = /usr/lib/gcc/x86_64-linux-gnu/8/include/d

What am I doing wrong? Should I specify the library upon 
compilation?


I am sorry, I am feeling I am asking too basic question.

Thank you!


Did you try to use 'dub build'?
You should run it in the same folder where dub.sdl is located.
Also maybe you will have to specify compiler in dub:
```
dub build --compiler=gdc
```

Some details about DUB you could find here https://dub.pm/


Re: library to solve the system of linear equations

2022-10-14 Thread Sergey via Digitalmars-d-learn

On Friday, 14 October 2022 at 17:41:42 UTC, Yura wrote:

Dear All,

I am very new to D, and it has been a while since I coded in 
anything than Python. I am using just notepad along with the 
gdc compiler.


At the moment I need to solve the system of liner equations:

A00*q0 + A01*q1 + A02*q2 ... = -V0
A10*q0 + A11*q1 + A12*q2 ... = -V1
...

Could someone please provide a quick d solution for this, 
including details on how to install the library & link it to 
the code? I do not need anything advanced, just the easiest 
option.


I am sorry for too basic question, just want to check my idea 
quickly. Thank you!


Firstly I will suggest to install dub - the D package manager. It 
will be easier to isntall other libraries using it.


Install openblas in your Ubuntu system. After that you can create 
a new folder and type in terminal

```
dub init
```

The main part will be about "dependencies". Type "lubeck".
After that you could check the example of the simple program here:
https://github.com/kaleidicassociates/lubeck/blob/master/example/source/app.d

It is exactly solving simple system of linear equations.
Link to the package where you can find additional details and 
documentation: https://code.dlang.org/packages/lubeck


Re: Float rounding (in JSON)

2022-10-13 Thread Sergey via Digitalmars-d-learn
On Thursday, 13 October 2022 at 19:27:22 UTC, Steven 
Schveighoffer wrote:


Thank you Steven, for your very detailed answer.

It doesn't look really that far off. You can't expect floating 
point parsing to be exact, as floating point does not perfectly 
represent decimal numbers, especially when you get down to the 
least significant bits.


This is sad - because "exact" match is what I need in this toy 
example.



But I want to point out something you may have missed:


Actually I've meant those things too :)

But look also at f3, and how actually D is closer to the 
expected value than with the other languages.


If you want exact representation of data, parse it as a string 
instead of a double.


Unfortunately it is not helped me in this task (which is pretty 
awkward): it parses some GeoData from JSON file. Then create 
representation of that data into string format and use hash from 
that string. Because they use the Hash - I need exact the same 
string representation to match the answer.


I'm assuming you are comparing for testing purposes? If you 
are, just realize you can never be accurate here. You just have 
to live with the difference. Typically when comparing floating 
point values, you use an epsilon to ensure that the floating 
point value is "close enough", you can't enforce exact 
representation.


-Steve


Actually it was my attempt to implement the benchmark-game: 
https://programming-language-benchmarks.vercel.app/problem/json-serde


As you can see many languages have passed tests which I assume 
they have exactly same representation of that float numbers.
Maybe I am wrong and did not understand code from other 
realizations. But at least I test python and crystal and found 
pretty confusing their results (what you wrote about more 
accurate example of f3), but what surpsised me even more: they 
have exactly same confused results with those floating numbers.
That's why I've made a conclusion that maybe it is some special 
and declared behavior/rule for that and I just can't find how to 
replicate that "well known behavior" in D.





Float rounding (in JSON)

2022-10-13 Thread Sergey via Digitalmars-d-learn
I'm not a professional of IEEE 754, but just found this behavior 
at rounding in comparison with other languages. I supose it 
happened because in D float numbers parsed as double and have a 
full length of double while rounding. But this is just doesn't 
match with behavior in other languages.


I'm not sure if this is somehow connected with JSON realizations.

Is it possible in D to have the same results as in others? 
Because explicit formatting is not the answer, since length of 
rounding could be different. That's why just specify "%.XXf" will 
not resolve the issue - two last numbers have 14 and 15 positions 
after the dot.


**Code Python**
```python
import json

str = '{ "f1": 43.47637900065, "f2": 43.49971899987, 
"f3": 43.49971800087, "f4": 43.41805299986 }'

print(json.loads(str))
```
**Result**
```
{'f1': 43.47637900065, 'f2': 43.49971899985, 'f3': 
43.4997180009, 'f4': 43.41805299986}

```

**Code Crystal**
```crystal
require "json"

str = "{ \"f1\": 43.47637900065, \"f2\": 43.49971899987, 
\"f3\": 43.49971800087, \"f4\": 43.41805299986 }"


puts JSON.parse(str)
```
**Result**
```
{"f1" => 43.47637900065, "f2" => 43.49971899985, "f3" => 
43.4997180009, "f4" => 43.41805299986}

```

**Code D**
```d
import std;

void main() {
string s = `{ "f1": 43.47637900065, "f2": 
43.49971899987, "f3": 43.49971800087, "f4": 
43.41805299986 }`;

JSONValue j = parseJSON(s);
writeln(j);
}
```
**Result**
```
{"f1":43.476379000654,"f2":43.499718999847,"f3":43.499718000867,"f4":43.418052999862}
```


Re: cannot gdb LDC build binary: Segmentation fault

2022-10-08 Thread Sergey via Digitalmars-d-learn

On Friday, 7 October 2022 at 04:40:34 UTC, mw wrote:

Hi,

I have a LDC (1.30.0) built binary on Ubuntu 18.04.5 LTS 
x86_64, the program core dumps somewhere, so I want to debug


Did you try to use GDC? As gdb more gcc tool
And for llvm should be lldb..



Re: Replacing tango.text.Ascii.isearch

2022-10-06 Thread Sergey via Digitalmars-d-learn
On Thursday, 6 October 2022 at 08:15:10 UTC, Siarhei Siamashka 
wrote:

On Wednesday, 5 October 2022 at 21:50:32 UTC, torhu wrote:


Please don’t tell us that D will be slower than Python again?)




Re: Visual D doesn't work, now Visual Studio Code / D doesn't work!!!! ....

2022-10-02 Thread Sergey via Digitalmars-d-learn
On Sunday, 2 October 2022 at 11:00:06 UTC, Daniel Donnell, Jr 
wrote:

I thought I set everything up correctly, and now:

```
Exception thrown at 0x7FF7D6E2E230 in metamath-d.exe: 
0xC096: Privileged instruction.
Unable to open natvis file 
'c:\Users\fruit\.vscode\extensions\webfreak.code-d-0.23.2\dlang-debug\dlang_cpp.natvis'.

```

So what the hell do you D developers use to code with if A) 
Visual D doesn't work - it just ate my app.obj file and can't 
find it anymore no matter if I clean or re-order the executable 
paths in settings.


B) VS Code doesn't work out-of-the-box.

Every. Single. Time I get around to using D, there's always 
something that pops up and doesn't work right.  And it never 
gets fixed.   How the heck do you expect me to debug without a 
proper debugging IDE :|


Did you try DlangIDE or Dexed?
They could be a solution



Re: Can you access the same classes from C++ and D and vise versa, or do the classes have to not form dependency cycle?

2022-09-12 Thread Sergey via Digitalmars-d-learn

Pretty new video from ContextFreeCode covers interop with C++
D also mentioned there :)

https://youtu.be/RdypYCxhWtw



Re: OpenXR library bindings etc

2022-09-10 Thread Sergey via Digitalmars-d-learn

On Friday, 9 September 2022 at 06:13:07 UTC, brian wrote:
I'd like to use D for some visualisation in XR, but without 
OpenXR, I'm stuck before I even start.


I have tried before to write the library bindings 
(https://github.com/infinityplusb/OpenXR-D), but got stuck and 
honestly don't know enough about what needs doing to fix it.
Apparently it is beyond my capability to do alone, regardless 
of how "easy" library bindings apparently are in D.


Is anyone interested in writing/collaborating on writing a 
library binding to OpenXR, before I resort to C++/C#/Python?


If it has C API - maybe try to use ImportC here?


Re: Supporting Arabic in GUI

2022-08-08 Thread Sergey via Digitalmars-d-learn

On Sunday, 7 August 2022 at 23:48:22 UTC, pascal111 wrote:
I have no idea about GUI or Rad programming in D; it's not its 
time, but I'm curious to know if D is fine supporting for 
Arabic language in the GUI applications or we will have some 
issues like I met - in my experience - in Free Pascal.


This is a topic where we trying to make a custom message box 
supporting Arabic as what's supposed to be, but we didn't reach 
although that the degree we want:


https://forum.lazarus.freepascal.org/index.php/topic,59765.0.html


I think it is possible to find framework to solve the issues in 
D..

my guess is based on information from the project ArabiaWeather

https://dlang.org/orgs-using-d.html

They have a YouTube talk about D. Maybe you could find their 
contacts and ask your questions related to their techstack and 
framework.


Re: Arbitrary precision decimal numbers

2022-08-06 Thread Sergey via Digitalmars-d-learn
On Thursday, 4 August 2022 at 13:01:30 UTC, Ruby The Roobster 
wrote:
Is there any implementation in phobos of something similar to 
BigInt but for non-integers as well?  If there isn't is there a 
dub package that does this, and if so, which one?


Also you could find usefull such projects:

http://mir-algorithm.libmir.org/mir_bignum_decimal.html

https://github.com/huntlabs/hunt-extra/blob/2d286f939193fc0cd55c799906f7657cec502dc8/source/hunt/math/BigDecimal.d


Re: ePub/Mobi/AZW3/PDF of Phobos Runtime Library

2022-06-30 Thread Sergey via Digitalmars-d-learn

On Tuesday, 28 June 2022 at 18:42:11 UTC, Marcone wrote:

Beloved,


I love programming in D. D is my favorite programming language. 
I'm not a professional programmer, but I love to program. I 
would like to learn D deeply. Most programming languages have a 
PDF/CHM/MOBI/ePub version of the standard library. But D still 
doesn't have such a portable version of the Phobos Runtime 
Library. I humbly ask you to make available a portable version 
of the Phobos library, to better disseminate the D programming 
language.



Thank you


Hi there!
First of all at page of Language reference is available Mobi 
version

https://dlang.org/spec/spec.html

Also please check this thread 
https://forum.dlang.org/post/qkxtppiaobehdjoro...@forum.dlang.org


There are plenty of links and resources:
https://d-apt.sourceforge.io/

https://devdocs.io/d/

I believe almost everything is ready, someone just should bring 
it all together and put the up2date links on official web-site in 
“Offline documentation” page


Have a nice day D-community!



Re: Reading parquet files from D

2022-06-23 Thread Sergey via Digitalmars-d-learn

On Thursday, 23 June 2022 at 12:48:20 UTC, test123 wrote:

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

On Monday, 14 October 2019 at 20:13:43 UTC, jmh530 wrote:

On Monday, 14 October 2019 at 19:27:04 UTC, Andre Pany wrote:

[snip]

I found this tool https://github.com/gtkd-developers/gir-to-d 
from Mike Wey which translates GObject GIR files to D headers.


It might be interesting for some of this functionality to get 
included in dpp.


maybe some project like https://github.com/hannes/miniparquet 
can be done by D


There is a code example, that could be possibly used

https://github.com/rostyboost/darrow



Re: D for data science and statistics

2022-06-04 Thread Sergey via Digitalmars-d-learn

On Saturday, 4 June 2022 at 20:26:54 UTC, Nicolas wrote:

Hi all!

Pleased to meet you. I am currently deep-diving into data 
analysis and statistics with R and SQL. I got mid-level 
programming experience, focusing on algorithms and innovation 
instead of sticking to one programming language.


I only got three questions:

1. Is there any extensive, up-to-date documentation on D? I 
really like its syntax and potential, so I am going to try and 
study anything regarding this programming language.


2. What about its integration with data analysis tools? Do you 
think it could be an alternative to, let's say, Python?


3. What IDE do you recommend when it comes to D?

Thank you all. You're awesome ^-^


Hi there!

1) Phobos documentation is available online. Great book also 
http://ddili.org/ders/d.en/index.html


2) R integration: 
https://dlang.org/blog/2020/01/27/d-for-data-science-calling-r-from-d/

Python integration: https://pyd.readthedocs.io/en/latest/
D usage in Data Science example: 
https://tech.nextroll.com/blog/data/2014/11/17/d-is-for-data-science.html

Stats package: https://github.com/DlangScience/dstats

3) one of the best is “Code-d” LSP server, which could be used 
from VS Code or Vim/NeoVim


PS there are several Machine Learning libraries: vectorflow from 
Netflix, grain and rnnlib
But all of them are far away from modern libs like TF or PyTorch 
or OpenAI




Re: UI Library

2022-05-28 Thread Sergey via Digitalmars-d-learn

On Saturday, 28 May 2022 at 02:39:41 UTC, Jack wrote:

On Friday, 20 May 2022 at 12:32:37 UTC, ryuukk_ wrote:
Avoid GTK, it's bloated, GTK4 looks like a toolkit to design 
mobile apps, and you need runtime dependencies on windows


adam's gui library is very nice, 0 dependencies

I personally prefer IMGUI, 0 dependencies, you bring the



could you send me please the link for this lib?

windowing library of your choice, i pick GLFW since it's 
minimal


IMGUI is fully capable, someone made a Spotify client with it!

https://user-images.githubusercontent.com/3907907/81094458-d20d9200-8f03-11ea-81e0-e72c0063b3a7.png


There are several bindings.
https://code.dlang.org/search?q=Imgui


Re: D WebAssembly working differently than C++, Zig

2022-05-17 Thread Sergey via Digitalmars-d-learn

On Monday, 16 May 2022 at 17:32:20 UTC, Allen Garvey wrote:
I'm working on a comparison of WebAssembly performance for 
error propagation dithering using D, C++ and Zig. So far C++ 
and Zig work as expected, but for D, despite using the same 
algorithm and similar code the output is different.


Hm D version is the slowest one?!



Re: How to work with hashmap from memutils properly?

2022-03-04 Thread Sergey via Digitalmars-d-learn

On Wednesday, 16 February 2022 at 13:37:28 UTC, ikod wrote:
On Wednesday, 16 February 2022 at 10:31:38 UTC, Siarhei 
Siamashka wrote:

On Friday, 11 February 2022 at 19:04:41 UTC, Sergey wrote:
Is this an attempt to implement a high performance solution 
for the Benchmarks Game's LRU problem in D language?


Yes. There is no D version there. And I'm just curious how 
fast is D in those problems.


Sorry for late question - I can't find page with benchmark 
results, can you please share url?


Thanks


Hi. I'm not sure which results did you mean..
Official page with LRU (and great implementation in Crystal from 
Siarhei) is here: 
https://programming-language-benchmarks.vercel.app/problem/lru


Results with my version in D is here:
https://github.com/cyrusmsk/lang_benchmark/tree/main/lru/bin

But the code is not the same that used in original 
implementation. To speed-up the D solution I thought to play 
around with @safe and @nogc.. but currently no time for that..


Btw ikod packages was used instead of built-in AA. And I've made 
the version with memutils - but unfortunately it is the slowest 
one.


Re: How to work with hashmap from memutils properly?

2022-02-11 Thread Sergey via Digitalmars-d-learn
On Friday, 11 February 2022 at 02:43:24 UTC, Siarhei Siamashka 
wrote:

On Thursday, 10 February 2022 at 20:39:45 UTC, Sergey wrote:

Code could be found here: 
https://github.com/cyrusmsk/lang_benchmark/tree/main/lru/source/d_comparison/mem


Is this an attempt to implement a high performance solution for 
the Benchmarks Game's LRU problem in D language?


Yes. There is no D version there. And I'm just curious how fast 
is D in those problems.



It can be further tuned for better performance if necessary.


Thank you for your version.
It is interesting finding about the size of the LRU. Already seen 
your comment in the benchmark github.


Though version with memutils still not working :)

What is also interesting - it is quite different results based 
not only for size of cache, but also the number of iterations.


P.S. surprised to see you here. I've seen your participation in 
contests at codeforces - there are much smaller D-community)


How to work with hashmap from memutils properly?

2022-02-10 Thread Sergey via Digitalmars-d-learn

Could someone help with memutils library?
It seems (based on some posts in 2018) that memutils is one of 
the fastest hashmap in Dlang world (if you know it is not - 
please help me find the fastest hashmap realisation).


I've made some benchmarks with the same code for regular AA, 
ikod-container and memutils. And the last one gave the different 
results. In the realisation is used the same operations: get, 
put, in.
The master version (compiled locally) is used, because last 
version available in dub is broken (issue already in the github 
since August 2021).


Can someone help to find out how to make it works?
Because there is no any kind of documetation for this package at 
all :(


Code could be found here: 
https://github.com/cyrusmsk/lang_benchmark/tree/main/lru/source/d_comparison/mem


PS it seems that almost all realisations of hashmap/dict/AA in D 
very slow :(


Re: Meaning of in, out and inout

2022-01-20 Thread Sergey via Digitalmars-d-learn

On Thursday, 20 January 2022 at 13:28:54 UTC, Paul Backus wrote:

On Thursday, 20 January 2022 at 13:19:06 UTC, Sergey wrote:

[...]


The explanation you quoted is from 2005, and `inout` does not 
mean the same thing in 2022 as it did in 2005.


The current meaning of inout is explained in the D language 
specification on dlang.org. Here is a link to the relevant 
section:


https://dlang.org/spec/function.html#inout-functions


Thanks a lot.


Meaning of in, out and inout

2022-01-20 Thread Sergey via Digitalmars-d-learn

https://forum.dlang.org/post/17nwtnp4are5q$.1ddtvmj4e23iy@40tude.net

On Tuesday, 10 May 2005 at 01:06:14 UTC, Derek Parnell wrote:

On Tue, 10 May 2005 00:30:57 + (UTC), Oliver wrote:


Hello D-ers

The documentation is very short on the keywords in, out and 
inout.
Is is inout sth like a reference ? But then, what is in and 
what is out?



in:
The argument is preserved, such that when control returns to 
the caller,
the argument as passed by the caller is unchanged. This means 
that the
called function can do anything it likes to the argument but 
those changes
are never returned back to the caller. There is a bit of 
confusion here
when it comes to passing class objects and dynamic arrays. In 
both these
cases, a reference to the data is passed. Which means that for 
'in'
references, the called function is free to modify the reference 
data (which
is what is actually passed) in the full knowledge that any 
changes will
*not* be returned to the caller. However, if you make any 
changes to the
data being referenced, that modified data is 'returned'. Which 
means that,
for example, if you pass a char[] variable, the reference will 
be preserved

but the data in the string can be changed.

out:
The argument is always initialized automatically by the called 
function
before its code is executed. Any changes to the argument by the 
called
function are returned to the caller. The called function never 
gets to see
the value of the argument as it was before the called function 
gets
control. The argument must a RAM item and not a literal or 
temporary value.


inout:
The argument is passed to the called function without before 
its code is
executed. Any changes to the argument by the called function 
are returned
to the caller. In other words, the called function can see what 
value was
passed to it before changing it.  The argument must a RAM item 
and not a

literal or temporary value.


Examples:

  char[] a;
  intb;

  void func_one(in char[] X, in int Y)
  {
  X[0] = 'a';   // Modifies the string contents.
  X = "zxcvb";  // Modifies the string reference but is not 
returned.


  Y = 3; // Modifies the data but is not returned.
  }


  a = "qwerty";
  b = 1;
  func_one(a,b);

  writefln("%s %d", a,b); // --> awerty 1

  void func_two(out char[] X, out int Y)
  {
  X[0] = 'a';   // Modifies the string contents.
  X = "zxcvb";  // Modifies the string reference.
  if (b == 1)
Y = 3; // never executed because Y is always zero on 
entry.

  else
Y = 4; // Modifies the data.
  }


  a = "qwerty";
  b = 1;
  func_two(a,b);

  writefln("%s %d", a,b); // --> zxcvb 4

  void func_three(inout char[] X, inout int Y)
  {
  X[0] = 'a';   // Modifies the string contents.
  X = "zxcvb";  // Modifies the string reference.
  if (b == 1)
Y = 3; // Modifies the data.
  else
Y = 4; // Modifies the data.
  }


  a = "qwerty";
  b = 1;
  func_two(a,b);

  writefln("%s %d", a,b); // --> zxcvb 3


Thanks a lot for your explanation.
I started to learn D language recently and I have trouble with 
understanding some part of language.
I do your example on Linux and it works very well, especially 
func_rthee().

when I try to repeat code on Windows 10, I get errors:
   Error: cannot modify `inout` expression `X[0]`
   Error: cannot modify `inout` expression `X`
   Error: cannot modify `inout` expression `Y`
   Error: cannot modify `inout` expression `Y`
Very strange situation for me.
I expect next behavior of the parameters X and Y could get value 
and could change it on Windows but now I am not sure what is goin 
on.


PS. I am using DMD64 D Compiler v2.098.1-dirty on Debian 10 Linux 
and Windows 10.


Check an entire XML document for well-formedness in KXML

2015-07-08 Thread Sergey via Digitalmars-d-learn

Hello!

I try to use KXML and I need very simple: check an entire XML 
document for well-formedness. How is it better to do?


Thanks in advance.


Re: kxml help.

2015-07-08 Thread Sergey via Digitalmars-d-learn

Hello!

I try to use KXML and I need very simple: check an entire XML 
document for well-formedness. How is it better to do?


Thanks in advance.


Re: Check an entire XML document for well-formedness in KXML

2015-07-08 Thread Sergey via Digitalmars-d-learn

On Wednesday, 8 July 2015 at 12:18:46 UTC, Gary Willoughby wrote:

On Wednesday, 8 July 2015 at 07:30:51 UTC, Sergey wrote:

Hello!

I try to use KXML and I need very simple: check an entire XML 
document for well-formedness. How is it better to do?


Thanks in advance.


Maybe use the command line:

$ sudo apt-get install libxml2
$ xmllint --schema schema.xsd --stream file.xml

or are you after a D solution?


I need a solution on d.
Now I program (work) on windows.