Re: There is Dlang Telegram Bot based on the official Telegram Bot API?

2020-04-05 Thread Denis Feklushkin via Digitalmars-d-learn

On Friday, 3 April 2020 at 16:10:55 UTC, Baby Beaker wrote:
I create Bots for Telegram using Python or PHP. But I love 
Dlang and would like to create my Bots in Dlang. Is there any 
support for Dlang to create Telegram Bots?


My bots use https://code.dlang.org/packages/telega without any 
problem




Re: Fixing race issues the right way

2020-04-05 Thread Mathias LANG via Digitalmars-d-learn

On Sunday, 5 April 2020 at 22:24:27 UTC, solidstate1991 wrote:
My game engine is currently broken due to some race issue I 
don't really know how to resolve.


It seems that the compiler tries to skip instructions that are 
not locked with a `writeln()` or something similar. Usually I 
can safely remove the writeln after compiling it once with that 
way. However I've once ran into an issue when a previously 
working code just started to emit random junk data depending on 
CPU usage, and in that case the aforementioned workaround only 
partially worked (delaying crashes, etc).


I've heard something about Mutex, however I lack the experience 
with multithreading.


Is there public code you can link to ?
Look for any usage of `__gshared`. Are you using `shared` as well 
? Turn on `-preview=nosharedaccess` to get better diagnostic. Are 
you using any `extern` code ? How do you communicate between 
threads ? Message passing, or simple shared memory ?


Cross module inline, LDC, dub dependencies.

2020-04-05 Thread NaN via Digitalmars-d-learn
OK so I am using the intel intrinsics library, I ws just copying 
it into my source tree. So in the interests of automation I added 
it as a dependency in dub, but now my code is anywhere up to 3 
times slower. So I figure maybe as its being compiled as a 
library, it's not getting inlined because i remember something 
about LDC not doing cross module inlining unless you tell it to.. 
So I pass "-enable-cross-module-inlining" to LDC, and then I get 
this...


source\dg2d\misc.d(11,15): Error: module `inteli` is in file 
'inteli.d' which cannot be read


so i'm guessing LDC needs the source file to do the cross module 
inlining?


Any ideas what I should do?


Re: Fixing race issues the right way

2020-04-05 Thread Stefan Koch via Digitalmars-d-learn

On Sunday, 5 April 2020 at 22:24:27 UTC, solidstate1991 wrote:
My game engine is currently broken due to some race issue I 
don't really know how to resolve.


It seems that the compiler tries to skip instructions that are 
not locked with a `writeln()` or something similar. Usually I 
can safely remove the writeln after compiling it once with that 
way. However I've once ran into an issue when a previously 
working code just started to emit random junk data depending on 
CPU usage, and in that case the aforementioned workaround only 
partially worked (delaying crashes, etc).


I've heard something about Mutex, however I lack the experience 
with multithreading.


Look at your program in a debugger and see if it does spawn 
threads.

If it does find out where and why they are spawned.


Fixing race issues the right way

2020-04-05 Thread solidstate1991 via Digitalmars-d-learn
My game engine is currently broken due to some race issue I don't 
really know how to resolve.


It seems that the compiler tries to skip instructions that are 
not locked with a `writeln()` or something similar. Usually I can 
safely remove the writeln after compiling it once with that way. 
However I've once ran into an issue when a previously working 
code just started to emit random junk data depending on CPU 
usage, and in that case the aforementioned workaround only 
partially worked (delaying crashes, etc).


I've heard something about Mutex, however I lack the experience 
with multithreading.


Re: CT BitArray

2020-04-05 Thread Johan via Digitalmars-d-learn
On Wednesday, 31 October 2018 at 23:14:08 UTC, Bastiaan Veelo 
wrote:
Currently, BitArray is not usable at compile time, so you 
cannot do

```
enum e = BitArray([1, 1, 1, 0]);
```
This gives
/dlang/dmd/linux/bin64/../../src/phobos/std/bitmanip.d(1190): 
Error: `bts` cannot be interpreted at compile time, because it 
has no available source code


IIUC, that is because `bts` comes from core.bitop but no source 
code is there. I am guessing these are filled in by compiler 
intrinsics or the like, and they are unavailable at CT, correct?


I suppose that alternative implementations of `btc`, `bts`, 
`btr`, `bsf` and `bt` could exist that do not use the runtime 
that could be used if(__ctfe) in the implementation of 
BitArray, that would make the above code work. Is this 
feasible? Is there precedent in phobos? Are there complications?


https://github.com/ldc-developers/druntime/pull/182



Re: Linear array to matrix

2020-04-05 Thread p.shkadzko via Digitalmars-d-learn

On Sunday, 5 April 2020 at 18:58:17 UTC, p.shkadzko wrote:
On Saturday, 4 April 2020 at 09:25:14 UTC, Giovanni Di Maria 
wrote:

[...]


Why not use "chunks" from std.range?

import std.range: chunks;

void main() {
int[] arr = [10,20,30,40,50,60,70,80,90,100,110,120];
auto matrix1 = arr.chunks(3).chunks(4); // no allocation
int[][][] matrix2 = arr.chunks(3).array.chunks(4).array;
}

But, keep in mind using array of arrays is not efficient.
For multidimensional arrays use Mir Slices.
If you need more information on how to create matrices, see 
this article: 
https://tastyminerals.github.io/tasty-blog/random/2020/03/22/multidimensional_arrays_in_d.html


it should be just one call to chunks --> arr.chunks(3), otherwise 
you'll get two nested arrays while you need only one. Sorry for 
confusion.




Re: Linear array to matrix

2020-04-05 Thread p.shkadzko via Digitalmars-d-learn
On Saturday, 4 April 2020 at 09:25:14 UTC, Giovanni Di Maria 
wrote:

Hi.
Is there a Built-in function (no code, only a built-in function)
that transform a linear array to a Matrix?

For example:

From

[10,20,30,40,50,60,70,80,90,100,110,120];


To

[
[10,20,30],
[40,50,60],
[70,80,90],
[100,110,120]
];

Thank You very much
Cheers.
Giovanni


Why not use "chunks" from std.range?

import std.range: chunks;

void main() {
int[] arr = [10,20,30,40,50,60,70,80,90,100,110,120];
auto matrix1 = arr.chunks(3).chunks(4); // no allocation
int[][][] matrix2 = arr.chunks(3).array.chunks(4).array;
}

But, keep in mind using array of arrays is not efficient.
For multidimensional arrays use Mir Slices.
If you need more information on how to create matrices, see this 
article: 
https://tastyminerals.github.io/tasty-blog/random/2020/03/22/multidimensional_arrays_in_d.html





Re: D on android and d_android

2020-04-05 Thread burt via Digitalmars-d-learn

On Thursday, 2 April 2020 at 17:16:56 UTC, burt wrote:

On Thursday, 2 April 2020 at 12:13:27 UTC, Adam D. Ruppe wrote:

On Thursday, 2 April 2020 at 11:29:24 UTC, burt wrote:
Anyway, I don't think this fails to work because of an error 
in the d_android library. If you find anything else that may 
cause it, I am glad to know, but thank you for your help.


Well, it is supposed to be a "just works" setup helper, so 
anything in it is a problem! There was an off-by-one bug in 
the downloader, maybe that missing byte made ldc ignore the 
corrupted library file.


I think I managed to get phobos2 and druntime to link. However, 
I still get linker errors saying that the following symbols are 
undefined: statvfs, fmodl, modfl, getdelim, _tlsend, 
__bss_end__, _tlsstart, __libc_current_sigrtmin, 
__libc_current_sigrtmax, strtold. I'm not sure what to do about 
that; did I forget to link something or are these symbols not 
in the Android runtime?


I managed to narrow it down to just one error. The missing 
`_tlsstart` and `_tlsend` symbols were because of the missing 
`void main() {}`, that used to be added automatically in 
d_android v0.0.5 but not in v0.1.0. It worked when I added an 
empty main function.


Most of the other errors were because of the API level of 
Android; for whatever reason, Android Studio chose API level 16 
instead of at least 21, so changing minSdkVersion to 21 in 
build.gradle made those errors go away.


However, I still get one undefined reference to __bss_end__, and 
I don't know how to fix this. Is this also a problem with TLS or 
the API level?


Thanks.


Re: How user dub packages in dmd without dub.exe ?

2020-04-05 Thread WebFreak001 via Digitalmars-d-learn

On Sunday, 5 April 2020 at 14:02:19 UTC, Baby Beaker wrote:

On Saturday, 4 April 2020 at 21:54:34 UTC, Andre Pany wrote:

On Saturday, 4 April 2020 at 20:21:03 UTC, Marcone wrote:

[...]


[...]

If you can copy the D packages from the Dub packages into your 
main source folder, the command maybe is just:


[...]


When I run with command dmd -i -run app.d I get this error:
app.d(4): Error: module `vibe` is in file 'vibe\vibe.d' which 
cannot be read


did you do the "copy the D packages from the Dub packages into 
your main source folder" part?


Re: How user dub packages in dmd without dub.exe ?

2020-04-05 Thread Baby Beaker via Digitalmars-d-learn

On Saturday, 4 April 2020 at 21:54:34 UTC, Andre Pany wrote:

On Saturday, 4 April 2020 at 20:21:03 UTC, Marcone wrote:
I want import modules from dub packages in my program.d and 
run using dmd.exe without dub.exe. How can I make it? Becouse 
when I try to import it says that can not found.


Ag the end dub is calling DMD/LDC with some arguments. You can 
run dub with verbose output and check the arguments in your 
scenario.


If you can copy the D packages from the Dub packages into your 
main source folder, the command maybe is just:


dmd -i -run app.d

(-i will find the module dependencies without explicitly 
mentioning them as command line args).


Kind regards
Andre


When I run with command dmd -i -run app.d I get this error:
app.d(4): Error: module `vibe` is in file 'vibe\vibe.d' which 
cannot be read


Re: How user dub packages in dmd without dub.exe ?

2020-04-05 Thread Marcone via Digitalmars-d-learn

On Sunday, 5 April 2020 at 14:02:19 UTC, Baby Beaker wrote:

On Saturday, 4 April 2020 at 21:54:34 UTC, Andre Pany wrote:

On Saturday, 4 April 2020 at 20:21:03 UTC, Marcone wrote:

[...]


Ag the end dub is calling DMD/LDC with some arguments. You can 
run dub with verbose output and check the arguments in your 
scenario.


If you can copy the D packages from the Dub packages into your 
main source folder, the command maybe is just:


dmd -i -run app.d

(-i will find the module dependencies without explicitly 
mentioning them as command line args).


Kind regards
Andre


When I run with command dmd -i -run app.d I get this error:
app.d(4): Error: module `vibe` is in file 'vibe\vibe.d' which 
cannot be read


Me too, same error


Re: Vibe-d Error Message and failed with exit code 1

2020-04-05 Thread WebFreak001 via Digitalmars-d-learn

On Saturday, 4 April 2020 at 14:40:16 UTC, Baby Beaker wrote:

Program.d

#!/usr/bin/env dub
/+ dub.sdl:
   name "hello_vibed"
   dependency "vibe-d" version="~>0.8.0"
+/
import vibe.vibe;
import std;

[...]


First of all try using the latest vibe.d release instead:

/+ dub.sdl:
   name "hello_vibed"
   dependency "vibe-d" version="~>0.9.0-alpha.2"
+/


then additionally try installing Visual C++ 2015 runtime: 
https://www.microsoft.com/en-us/download/details.aspx?id=48145


and after you done that and it still doesn't work, try using 
ldc2. It should definitely work at that point when VC++ 2015 
runtime is installed then.


Re: There is Dlang Telegram Bot based on the official Telegram Bot API?

2020-04-05 Thread Dan Cirnat via Digitalmars-d-learn

On Friday, 3 April 2020 at 16:10:55 UTC, Baby Beaker wrote:
I create Bots for Telegram using Python or PHP. But I love 
Dlang and would like to create my Bots in Dlang. Is there any 
support for Dlang to create Telegram Bots?


Hi,

A quick search yielded this dub package: 
https://code.dlang.org/packages/tg-d


AFAIR the Telegram BOT API is HTTP and very simple. Should be 
straight forward to write your own client.
I found out some code I've written while playing with it a while 
ago: 
https://gist.github.com/cirnatdan/7d8cb26759f349579995c2703bbc1996


Have fun!