Re: Why is this happening to my software? An illegal instruction error.
On Wednesday, 19 June 2024 at 00:02:38 UTC, H. S. Teoh wrote: Among the above causes, I'd say (1) is the most likely, (2) is the 2nd most likely if (1) isn't the cause. Thank you, I will try this software on other computers to see if it's number 2. I've reviewed the code and I don't think it could be number 1.
Re: Why is this happening to my software? An illegal instruction error.
On Wednesday, 19 June 2024 at 07:46:07 UTC, ryuukk_ wrote: why do you convert the number to string? My mistake, I thought BigInt() only took strings, I've corrected the code.
Why is this happening to my software? An illegal instruction error.
I've created a software which performs the Fermat's Primality Test, however if I input a very big number it causes an error saying "Illegal instruction (core dumped)". Does anyone know why? I've used GDB and here is the message: Program received signal SIGILL, Illegal instruction. 0x555e40b0 in _D3std8internal4math11biguintcore7BigUint3powFNaNbNfNkMSQCcQCbQBvQBtQBjmZQs () Here is the link to the source code: https://github.com/MuriloMir/Fermat-primality-test
Re: Does anyone here know how to create a Telegram bot in D?
On Saturday, 30 July 2022 at 05:12:23 UTC, AnimusPEXUS wrote: so basically you have to do http-client programming also there's some outdated tg packages in repo https://code.dlang.org/search?q=telegram Thanks you very much.
Does anyone here know how to create a Telegram bot in D?
Hi guys, I need to create a Telegram bot in D, does anyone here know how to do it? Is it possible to do it using arsd?
Re: How do I check if a type is assignable to null at compile time?
On Friday, 26 February 2021 at 05:25:14 UTC, Jack wrote: I started with: enum isAssignableNull(T) = is(T : Object) || isPointer(T); but how do I cover all cases? You can check if it's null with this `variable is null` and you can test it with assert as in `assert(variable is null);`
Re: DConf 2017 Videos
On Friday, 24 April 2020 at 20:24:47 UTC, matheus wrote: Hi, please could someone tell me where can I find videos from DConf 2017? I pretty sure I watched them on Youtube sometime ago, but I can't find anymore. By the way, I'm looking from one video where someone shows some "C flaws" and how to D as Better C could solve that. I think it was the second talk in this list: https://dconf.org/2017/schedule/ Any idea? Thanks. They are all here: https://www.youtube.com/channel/UC5DNdmeE-_lS6VhCVydkVvQ
Re: GUI library for DMD 2.090 or DMD 2.091
On Friday, 24 April 2020 at 13:45:22 UTC, Phrozen wrote: I'm too new to DLang and I have a lot to learn. Probably that's why I have a lot of difficulties. Has anyone tried using a GUI library to the latest DMD 2.090 or DMD 2.091? I plan to use this language for a specific Thermal calculator application for Windows, but for two days I've been struggling with dub and elementary examples in GUI libraries. I need something simple - a modal window with 3 buttons and a two text boxes. So far I have tested DWT, TKD, DFL, dlangui without success. Can anyone help me with advice or some more recent tutorial. Thank you! Here is everything you need to know: https://madscientisthaven.blogspot.com/2020/01/beginning-multimedia-with-arsd.html
Re: Best way to learn 2d games with D?
On Sunday, 15 March 2020 at 17:58:58 UTC, Steven Schveighoffer wrote: I want to try and learn how to write 2d games. I'd prefer to do it with D. I've found a ton of tutorials on learning 2d gaming with other languages. Is there a place to look that uses D for learning? Should I just start with another language and then migrate to D later? Anyone recommend any specific tutorial/book? -Steve Hi Steve, I have written a nice tutorial on that. Here is the link to it: https://themindofmurilomiranda.blogspot.com/2020/01/beginning-multimedia-with-arsd.html I have also written a very elaborated Space Invaders game as an example of how to use what you will learn in the tutorial above, here is the link to it: https://themindofmurilomiranda.blogspot.com/2020/01/space-invaders-game-example-to-learn.html
Re: 2d graphic and multimedia
On Thursday, 12 March 2020 at 04:33:42 UTC, Noor Wachid wrote: I usually go with SFML (C++) library to write simple visualization. Is there any similiar library in D? I use the arsd library for everything. It allows multimedia and much more, it's light, fast, small and very easy to use since it doesn't even require DUB. You just download it into the project's folder and import the modules you want. In your case you want to import the module arsd.simpledisplay. Here is a link to its documentation: http://dpldocs.info/experimental-docs/arsd.html Here is a link to download it: https://github.com/adamdruppe/arsd And here is a link to a tutorial teaching you the basics of how to use it for multimedia: https://themindofmurilomiranda.blogspot.com/2020/01/beginning-multimedia-with-arsd.html And here is a link to a space invaders game made solely with this library, this game was made for Windows environment, it may not work well on Linux: https://themindofmurilomiranda.blogspot.com/2020/01/space-invaders-game-example-to-learn.html
So, you want to be a programmer? Here is the way to go.
Hi everyone. I've received so many people asking me about how to learn programming, or complaining about how difficult it is, that I wrote a small text teaching the way to go for those who want to learn programming. I tried to write it in a funny and straight forward way. Here it is: https://themindofmurilomiranda.blogspot.com/2020/01/the-path-of-programmer.html
Re: What kind of Editor, IDE you are using and which one do you like for D language?
On Sunday, 22 December 2019 at 17:20:51 UTC, BoQsc wrote: There are lots of editors/IDE's that support D language: https://wiki.dlang.org/Editors What kind of editor/IDE are you using and which one do you like the most? I use Notepad++ on Windows and Bluefish on Linux. I'm a minimalist guy, I prefer a light text editor than a heavy IDE.
Re: How can I make a program which uses all cores and 100% of cpu power?
On Friday, 11 October 2019 at 06:18:03 UTC, Ali Çehreli wrote: Your threads must allocate as little memory as possible because memory allocation can trigger garbage collection and garbage collection stops all threads (except the one that's performing collection). We studied the effects of different allocation schemes during our last local D meetup[1]. The following program has two similar worker threads. One allocates in an inner scope, the other one uses a static Appender and clears its state as needed. The static Appender is thread-safe because each thread gets their own copy due to data being thread-local by default in D. However, it doesn't mean that the functions are reentrant: If they get called recursively perhaps indirectly, then the subsequent executions would corrupt previous executions' Appender states. Thanks for the information, they were very helpful.
Re: How can I make a program which uses all cores and 100% of cpu power?
On Friday, 11 October 2019 at 06:57:46 UTC, Russel Winder wrote: A neural net is, at it's heart, a set of communicating nodes. This is as much an I/O bound model as it is compute bound one – nodes are generally waiting for input as much as they are computing a value. The obvious solution architecture for a small computer is to create a task per node on a thread pool, with a few more threads in the pool than you have processors, and hope that you can organise the communication between tasks so as to avoid cache misses. This can be tricky when using multi-core processors. It gets even worse when you have hyperthreads – many organisations doing CPU bound computations switch off hyperthreads as they cause more problems than theysolve. Thanks, that helped a lot. But I already figured out a new training algorithm that is a lot faster, no need to use parallelism anymore.
Re: Help playing sounds using arsd.simpleaudio
On Wednesday, 30 October 2019 at 19:11:00 UTC, Adam D. Ruppe wrote: On Saturday, 26 October 2019 at 19:48:33 UTC, Murilo wrote: I play a sound the program never ends, the terminal continues to run the program and I have to end it manually. Any ideas what could be causing this? I am using it just as you had instructed. That happens if you don't call .stop() and .join() in order at the right time. Did you use the scope(exit) like I said? Thanks for the help. I did use the scope. Here is my code: AudioPcmOutThread audio = new AudioPcmOutThread(); audio.start(); scope (exit) { audio.stop(); audio.join(); } audio.playOgg("bell.ogg"); The problem persists.
Re: Help playing sounds using arsd.simpleaudio
On Saturday, 19 October 2019 at 13:08:49 UTC, Adam D. Ruppe wrote: try it now with the new version of simpleaudio.d from git Hi Adam, sorry to bother you, but I'm having a problem with simpleaudio.d. This problem was happening on Windows too. When I play a sound the program never ends, the terminal continues to run the program and I have to end it manually. Any ideas what could be causing this? I am using it just as you had instructed.
Re: Help playing sounds using arsd.simpleaudio
On Saturday, 19 October 2019 at 13:08:49 UTC, Adam D. Ruppe wrote: try it now with the new version of simpleaudio.d from git Ahh, now it works! Thank you so much man. I really appreciate the work you do with your library, I have been using it for everything, I'm now training a neural network using your library.
Re: Help playing sounds using arsd.simpleaudio
On Saturday, 19 October 2019 at 02:10:54 UTC, Adam D. Ruppe wrote: On Saturday, 19 October 2019 at 01:48:57 UTC, Murilo wrote: init: Operation not permitted Your system probably uses PulseAudio which I don't like, so I don't support it in my code. It *might* work to run `pasuspender -- ./your_program_here` but I don't know. I can check more tomorrow. That unfortunately didn't work. I would be very grateful if you could find out a way around it and tell me.
Re: Help playing sounds using arsd.simpleaudio
but at the beginning of main() set it up with auto audio = new AudioPcmOutThread(); audio.start(); scope(exit) { audio.stop(); audio.join(); } Thanks Adam. That worked on Windows, but now that I have switched to Linux Mint it is throwing this: arsd.simpleaudio.AlsaException@arsd/simpleaudio.d(1170): params init: Operation not permitted ??:? arsd.simpleaudio.snd_pcm_t* arsd.simpleaudio.openAlsaPcm(arsd.simpleaudio.snd_pcm_stream_t) [0x55eab05a0f4a] ??:? ref arsd.simpleaudio.AudioOutput arsd.simpleaudio.AudioOutput.__ctor(int) [0x55eab059f7ec] ??:? void arsd.simpleaudio.AudioPcmOutThread.run() [0x55eab059f23d] ??:? void core.thread.Thread.run() [0x55eab05c10d1] ??:? thread_entryPoint [0x55eab05d809b] ??:? [0x7fb40e4ff6da] What should I do?
How can I make a program which uses all cores and 100% of cpu power?
I have started working with neural networks and for that I need a lot of computing power but the programs I make only use around 30% of the cpu, or at least that is what Task Manager tells me. How can I make it use all 4 cores of my AMD FX-4300 and how can I make it use 100% of it?
Re: Help making a game with transparency
On Tuesday, 1 October 2019 at 12:45:35 UTC, Adam D. Ruppe wrote: On Monday, 30 September 2019 at 23:52:27 UTC, Murilo wrote: { window.redrawOpenGlSceneNow; like I said on email, this is the ONLY thing you should to in the event loop to trigger the redraw. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT); glLoadIdentity; ship.draw(20, 20, 41, 47); All this actual drawing stuff should be attached to the `window.redrawOpenGlScene` delegate. Just do `window.redrawOpenGlScene = { that stuff } ` after creating the window but before the event loop to set it up. It worked! :D Thank you so much man. Now I will finish refactoring the code and then I will be able to finish your tutorial.
Re: Help making a game with transparency
On Tuesday, 1 October 2019 at 12:46:58 UTC, Adam D. Ruppe wrote: On Monday, 30 September 2019 at 20:14:56 UTC, Murilo wrote: What are your pages that you want people subscribing to? I'm just trolling. And what is your patreon page? https://www.patreon.com/adam_d_ruppe but as you'll notice, it is currently $58. To reach "quit my job and work for y'all all the time" I put $8000. Realistically, that is never going to happen. thus why i troll. Alright, sending you money every month on Patreon would be a problem for me so I figure I can patron you in another way, I am writing a tutorial for your library and I have showed lots of people how useful your library can be, I have also sent several PR to add stuff to it. That will be my way of contributing.
Re: Help making a game with transparency
Hi everyone, I tried creating a program which simply shows the image of the ship near the corner of the screen, just for testing sake. Here it is: import arsd.gamehelpers, arsd.image; void main() { SimpleWindow window = create2dWindow("Space Invaders", 1000, 400); OpenGlTexture ship = new OpenGlTexture(loadImageFromFile("images/ship_normal.png").getAsTrueColorImage()); window.eventLoop(40, (/*no events*/) { window.redrawOpenGlSceneNow; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT); glLoadIdentity; ship.draw(20, 20, 41, 47); }); } But the screen stays all white, nothing appears in it. Any ideas what needs to be changed?
Re: Help making a game with transparency
On Saturday, 28 September 2019 at 14:33:03 UTC, Adam D. Ruppe wrote: But if you all want that, on your schedule, smash that like button, comment, subscribe, and be sure to ring that bell so you get a notification every time I parrot what people say on Youtube at the end of their videos. Then head on over my patreon page and give me all your money today. If everyone who downloaded my libraries contributed just $3 / month, I'd be able to devote myself to expanding these libraries to support more use cases. What are your pages that you want people subscribing to? And what is your patreon page? I may buy your book "D cookbook" next year, that will probably be a good contribution.
Re: Help making a game with transparency
On Saturday, 28 September 2019 at 13:41:24 UTC, matheus wrote: Ok, I took a look over my old projects and I found exactly what you want, by the way it's from 2012. It uses Derelict 2.0 bindings and will draw a PNG image where you can move around with cursor keys. If you want I can send you the whole project (Makefile, DLL's) and everything else to build it. Code: /* 02/10/2012 */ import std.stdio; import derelict.sdl.sdl; import derelict.sdl.image; Matheus. Thank you very much.
Re: Help playing sounds using arsd.simpleaudio
On Sunday, 29 September 2019 at 22:52:02 UTC, Adam D. Ruppe wrote: On Sunday, 29 September 2019 at 21:06:02 UTC, Murilo wrote: .stop() will stop the thread More specifically, stop tells the audio output to stop. It finishes what it is doing and then exits. At this point, the thread terminates. join() waits for the thread to finish terminating (which it won't do if you don't tell it to stop *first*) and then cleans it up. join will return any exception/error it happened to throw while ending. ahh, okay, thanks. Now, one last question, if stop() actually makes the output, not the thread, stop, then start() makes the output, not the thread, begin?
Re: Help playing sounds using arsd.simpleaudio
On Sunday, 29 September 2019 at 20:57:09 UTC, Adam D. Ruppe wrote: On Sunday, 29 September 2019 at 20:51:40 UTC, Murilo wrote: Are you sure it is like this: join waits for it to finish before returning. You need to stop before joining otherwise join may never return. Alright, thanks. So let me see if I get this straight, .stop() will stop the thread and then .join() will return. But what exactly does .join() return?
Re: Help playing sounds using arsd.simpleaudio
On Saturday, 28 September 2019 at 14:03:53 UTC, Adam D. Ruppe wrote: On Saturday, 28 September 2019 at 03:21:38 UTC, Murilo wrote: Can anyone just please show me how to play a background sound(like those in games) using arsd.simpleaudio? I'd like something simple with a code snippet please. it is really minimal be warned but at the beginning of main() set it up with auto audio = new AudioPcmOutThread(); audio.start(); scope(exit) { audio.stop(); audio.join(); } and then when you want it to make sounds, call its functions like audio.beep(); or audio.playOgg("my-file.ogg"); you can convert things like wav and mp3 into the ogg format with various tools of the internet. that's about all it does. Are you sure it is like this: audio.stop(); audio.join(); and not like this: audio.join(); audio.stop(); ?
Re: Help playing sounds using arsd.simpleaudio
On Sunday, 29 September 2019 at 13:24:40 UTC, Adam D. Ruppe wrote: On Sunday, 29 September 2019 at 04:37:43 UTC, Murilo wrote: Thanks. Now, I would like to know if I could just use it like this instead: What happens if an exception is thrown in the middle of your function? It shouldn't really matter (at least not with the newer versions) since it will automatically exit the audio thread when the main thread exits, but still there's definitely no benefit to writing it without the scope guard. I'm very minimalistic, I hate unnecessary complexity, I believe that simple is better than complex so I always try to use the least syntax and lines of code when I'm making a program. That is why I don't like the scope guard. Could I simply add the lines `audio.stop(); audio.join();` to the very end of main()?
Re: Help playing sounds using arsd.simpleaudio
On Sunday, 29 September 2019 at 09:25:59 UTC, JN wrote: On Saturday, 28 September 2019 at 03:21:38 UTC, Murilo wrote: Can anyone just please show me how to play a background sound(like those in games) using arsd.simpleaudio? I'd like something simple with a code snippet please. I recommend SoLoud - bindings are available here http://code.dlang.org/packages/bindbc-soloud . It's more powerful than simpleaudio, supports multiple formats, 3D audio, etc. Thanks.
Re: Help playing sounds using arsd.simpleaudio
On Saturday, 28 September 2019 at 14:03:53 UTC, Adam D. Ruppe wrote: On Saturday, 28 September 2019 at 03:21:38 UTC, Murilo wrote: Can anyone just please show me how to play a background sound(like those in games) using arsd.simpleaudio? I'd like something simple with a code snippet please. it is really minimal be warned but at the beginning of main() set it up with auto audio = new AudioPcmOutThread(); audio.start(); scope(exit) { audio.stop(); audio.join(); } and then when you want it to make sounds, call its functions like audio.beep(); or audio.playOgg("my-file.ogg"); you can convert things like wav and mp3 into the ogg format with various tools of the internet. that's about all it does. Thanks. Now, I would like to know if I could just use it like this instead: import arsd.simpleaudio; void main() { AudioPcmOutThread audio = new AudioPcmOutThread; audio.start; audio.playOgg("shock.ogg"); audio.join; audio.stop; }
Re: Help playing sounds using arsd.simpleaudio
On Saturday, 28 September 2019 at 14:03:53 UTC, Adam D. Ruppe wrote: On Saturday, 28 September 2019 at 03:21:38 UTC, Murilo wrote: Can anyone just please show me how to play a background sound(like those in games) using arsd.simpleaudio? I'd like something simple with a code snippet please. it is really minimal be warned but at the beginning of main() set it up with auto audio = new AudioPcmOutThread(); audio.start(); scope(exit) { audio.stop(); audio.join(); } and then when you want it to make sounds, call its functions like audio.beep(); or audio.playOgg("my-file.ogg"); you can convert things like wav and mp3 into the ogg format with various tools of the internet. that's about all it does. Thank you sooo much. Now it works. That is pretty much what I was looking for.
Re: Help making a game with transparency
On Saturday, 28 September 2019 at 05:57:55 UTC, Mike Parker wrote: On Friday, 27 September 2019 at 22:55:22 UTC, Murilo wrote: You might consider using SDL and SDL_image: Thank you very much. But I want to use only the arsd library.
Help playing sounds using arsd.simpleaudio
Can anyone just please show me how to play a background sound(like those in games) using arsd.simpleaudio? I'd like something simple with a code snippet please.
Re: Help making a game with transparency
On Friday, 27 September 2019 at 22:40:14 UTC, Adam D. Ruppe wrote: On Friday, 27 September 2019 at 22:13:43 UTC, matheus wrote: https://github.com/adamdruppe/arsd/blob/b0d21de148ef0b23ea845be322af5e6931ca4cb6/screen.d I really should just remove that file as it is no longer well maintained. I haven't used it for anything in years and doubt anyone else is either. He's using the simpledisplay.d lib which DOES NOT SUPPORT transparency in its drawImage function. It does NOT use opengl functions and are not compatible with them. To do opengl stuff with simpledisplay, there is a separate flow. You use opengl functions on a redraw scene delegate instead of using any of the Image or Painter objects. It is quite different and there is no easy fix on that end. but the gdi+ functions in sdpy MIGHT be able to be ported to alpha blend on Windows easily enough. I just haven't gotten around to it yet. Ahhh, that clears everything up. I will then leave the program without the transparency and wait until you get around to implement the fixes to it, I am not a developer, I am a scientist, I only use libraries, I don't know how to make them properly.
Re: Help making a game with transparency
On Friday, 27 September 2019 at 22:13:43 UTC, matheus wrote: On Friday, 27 September 2019 at 21:16:07 UTC, Murilo wrote: ... Here it is, how do I make the ship have a transparent background? First: Your PNG file has transparency data information right? Second: I was Looking into the drawImage function (Line 854): https://github.com/adamdruppe/arsd/blob/b0d21de148ef0b23ea845be322af5e6931ca4cb6/screen.d And I'd suggest you to try to add the glEnable(GL_ALPHA_TEST); before glBegin(GL_QUADS); In fact you should do this only once, maybe inside the constructor, but just try it there to see if it works. Matheus. Thanks for trying to help me but unfortunately you are suggesting I use arsd.screen which is supposed to be obsolete, I am using arsd.simpledisplay instead and it is very different although many functions have the same name.
Re: Help making a game with transparency
On Friday, 27 September 2019 at 17:53:33 UTC, matheus wrote: On Friday, 27 September 2019 at 16:36:14 UTC, Murilo wrote: ...Do you know the arsd library? Yes but I use mostly terminal.d and others. On the other hand I use to code games too using SDL and OpenGL. I know for example in OpenGL you can do: glEnable(GL_ALPHA_TEST); to enable alpha channel and set transparency. Matheus. Thanks, but I don't know how that will fit in my code. I will show up a code snippet and you tell me how I can use your idea in it, okay? import arsd.image, arsd.simpledisplay; void main() { auto memImgShip = loadImageFromFile("ship.png"), memImgBackground = loadImageFromFile("background.png"); auto imgShip = Image.fromMemoryImage(memImgShip), imgBackground = Image.fromMemoryImage(memImgBackground); auto window = new SimpleWindow; window.eventLoop(10, { auto painter = window.draw; painter.drawImage(Point(0, 0), imgBackground); painter.drawImage(Point(100, 100), imgShip); }); } Here it is, how do I make the ship have a transparent background?
Re: Help making a game with transparency
On Friday, 27 September 2019 at 11:32:53 UTC, Adam D. Ruppe wrote: On Friday, 27 September 2019 at 11:28:35 UTC, matheus wrote: Sorry this is a bit vague. I suppose you're using engine.d or screen.d directly right? those two are obsolete, new stuff should use simpledisplay but with simpledisplay you need to use opengl for transparency since the xlib/gdi+ impl doesn't support it (though they probably could if someone wanted to write some code) i just am doing 4 other things at once right now and can't do it myself at the moment Alright, thanks, the problem is that I was unable to figure out the opengl functions. Later when you have the time see if you can help me out, then I will add this to your library's tutorial.
Re: Help making a game with transparency
Sorry this is a bit vague. I suppose you're using engine.d or screen.d directly right? Depending on your setup (OpenGL or Software) transparency will be different. For example take a look at line 733, putpixel function and you'll see that It handle Color differently if it's OpenGL x Software and for the latter it checks if 32bpp or less. Now if it's OpenGL take a look for "Alpha". Matheus. Thanks for the reply. Do you know the arsd library?
Help making a game with transparency
Hi guys, I am making a game but for some reason the sprites do not show with the transparent background that they were supposed to. I'm using the arsd library. Can anyone help me?
Re: Help me decide D or C
On Wednesday, 31 July 2019 at 18:38:02 UTC, Alexandre wrote: Hi everyone, I would like an honest opinion. I have a beginner level (able to do very small programs) in a few languages such as python, go, C, guile(scheme) and common lisp. I want to pick a language and go deep with it and focus on only one for at least the next 2 years or so. Should I go for C and then when I become a better programmer change to D? Should I start with D right now? Here goes something that may help you. A multimedia tutorial in D with a lib called arsd. I am nearly done with the tutorial and it is now very complete, it now teaches how to use the arsd library to draw all sorts of stuff and to receive mouse and keyboard input. I think you will like it. If you use it and like it please let me know because I would be very happy to see my work being spread. Cheers. Here is the GitHub page: https://github.com/MuriloMir/arsd_multimedia_tutorial
Re: Elegant way to test if members of array A are present in array B?
On Tuesday, 11 June 2019 at 17:12:17 UTC, Robert M. Münch wrote: Is there a simple and elegant way to do this? Or is just using a foreach(...) with canFind() the best way? I made it this way, I consider it elegant. I don't know if others will like it. Here it is: import std.stdio : writeln; import std.algorithm.searching; import std.algorithm.sorting; void main() { int[] a = [3, 9, 1, 4, 7, 6, 5, 8, 2]; int[] b = [5, 4, 6]; //first we sort both of them sort(a); sort(b); //now we check them using slices writeln(b == a[a.countUntil(b[0]) .. a.countUntil(b[$ - 1]) + 1]); } It should output `true`
Re: Block statements and memory management
On Saturday, 16 March 2019 at 15:53:26 UTC, Johan Engelen wrote: On Saturday, 16 March 2019 at 03:47:43 UTC, Murilo wrote: Does anyone know if when I create a variable inside a scope as in {int a = 10;} it disappears complete from the memory when the scope finishes? Or does it remain in some part of the memory? I am thinking of using scopes to make optimized programs that consume less memory. Others have made good points in this thread, but what is missing is that indeed scopes _can_ be used beneficially to reduce memory footprint. -Johan I would like to thank everyone for your help, those informations were very helpful.
Block statements and memory management
Does anyone know if when I create a variable inside a scope as in {int a = 10;} it disappears complete from the memory when the scope finishes? Or does it remain in some part of the memory? I am thinking of using scopes to make optimized programs that consume less memory.
Re: Easiest way to display images
Hi Adam, how do I set the color of the SimpleWindow background?
How to cast arrays?
How do I cast a ubyte[] into uint[]? It keeps raising an error, I have read the documentation saying there are restrictions for that concerning the length of the arrays.
Using arsd.simpledisplay module
I need help with the arsd.simpledisplay module. Is there anyone there who knows about it? I have doubts concerning SimpleWindow.eventLoop().
Re: Easiest way to display images
On Tuesday, 12 February 2019 at 01:31:48 UTC, Adam D. Ruppe wrote: On Tuesday, 12 February 2019 at 01:16:21 UTC, Murilo wrote: Hi Adam. I have been using your arsd library and I have noticed that compiling with -m64 causes this error: huh, only on 64 bit windows. well, pushed a fix up, try the new version Hi Adam. I am using your library. There is the ScreenPainter struct and it has a method called .eventLoop(), how do I make it stop after a certain amount of loops? I would like to be able to call it several times in the program.
Re: Easiest way to display images
On Tuesday, 12 February 2019 at 01:31:48 UTC, Adam D. Ruppe wrote: On Tuesday, 12 February 2019 at 01:16:21 UTC, Murilo wrote: Hi Adam. I have been using your arsd library and I have noticed that compiling with -m64 causes this error: huh, only on 64 bit windows. well, pushed a fix up, try the new version Forget about it, I just fixed it myself. :) I am so happy, I did not think I would be able to do it on my own, I guess all those years of studying were worth the effort, I read the error message and figured it was something wrong in the module jpeg.d so I opened it, read the code(in a very fast manner) and discovered that the calls to core.stdc.stdlib.alloca() were causing the problem apart from being unnecessary so I just commented all of them out(just like you did with the very first instance) and then there was a problem with the buffer variable which was only defined by you in the first instance so I just defined it in the other instances following the same method you used and it all worked in the end. I will submit a pull request on your GitHub page. Cheers.
Re: Easiest way to display images
On Tuesday, 12 February 2019 at 01:31:48 UTC, Adam D. Ruppe wrote: On Tuesday, 12 February 2019 at 01:16:21 UTC, Murilo wrote: Hi Adam. I have been using your arsd library and I have noticed that compiling with -m64 causes this error: huh, only on 64 bit windows. well, pushed a fix up, try the new version Hi, unfortunately the problem persists. I have sent you an e-mail on your destructiona...@gmail.com account. I would prefer to talk there rather than here. I would just like to understand what is causing the problem so I can figure out a bypass.
Re: Easiest way to display images
On Sunday, 10 February 2019 at 21:26:56 UTC, Adam D. Ruppe wrote: On Sunday, 10 February 2019 at 18:42:59 UTC, Murilo wrote: Adam, is there a place where we can chat? I don't like chatting via this forum. I would like to talk to you about your modules and about the D lang. get on the freenode irc, i am in #d like all the time (and will see messages when i am back on my computer) or you can dm me adam_d_ruppe there if i am online Hi Adam. I have been using your arsd library and I have noticed that compiling with -m64 causes this error: Error: cannot mix core.std.stdlib.alloca() and exception handling in _D4arsd4jpeg27detect_jpeg_image_from_fileFAxaJiJiJiZb() May I know why that happens? How can I bypass it?
Re: Handling big FP numbers
On Sunday, 10 February 2019 at 21:27:43 UTC, Dennis wrote: On Sunday, 10 February 2019 at 20:25:02 UTC, Murilo wrote: It seems this is a feature of D I will have to get used to and accept the fact I can't always get the same number as in C What compilers and settings do you use? What you're actually comparing here are different implementations of the C runtime library. ``` #include int main() { double a = 991234307654329925.7865; printf("%f\n", a); return 0; } ``` I compiled this with different C compilers on Windows 10 and found: DMC: 99123429947200.00 GCC: 9912342990.00 CLANG: 991234299470108672.00 As for D: ``` import core.stdc.stdio: printf; int main() { double a = 991234307654329925.7865; printf("%f\n", a); return 0; } ``` DMD: 99123429947200.00 LDC: 991234299470108672.00 DMC and DMD both use the Digital Mars runtime by default. I think CLANG and LDC use the static libcmt by default while GCC uses the dynamic msvcrt.dll (not sure about the exact one, but evidently it's different). So it really hasn't anything to do with D vs. C but rather what C runtime you use. Ahhh, alright, I was not aware of the fact that there are different runtimes, thanks for clearing this up.
Re: Easiest way to display images
On Sunday, 10 February 2019 at 21:26:56 UTC, Adam D. Ruppe wrote: On Sunday, 10 February 2019 at 18:42:59 UTC, Murilo wrote: Adam, is there a place where we can chat? I don't like chatting via this forum. I would like to talk to you about your modules and about the D lang. get on the freenode irc, i am in #d like all the time (and will see messages when i am back on my computer) or you can dm me adam_d_ruppe there if i am online okay, I will try that, but do you have a facebook account? I usually chat with people on facebook.
Re: Handling big FP numbers
On Saturday, 9 February 2019 at 05:46:22 UTC, H. S. Teoh wrote: On Sat, Feb 09, 2019 at 03:52:38AM +, Murilo via Digitalmars-d-learn wrote: On Saturday, 9 February 2019 at 03:28:24 UTC, Adam D. Ruppe wrote: [...] > But you can change this with the format specifiers (use > `writefln` instead of `writeln` and give a precision > argument) or, of course, you can use the same C printf > function from D. Thanks, but which precision specifier should I use? I already tried "%.20f" but it still produces a result different from C? Is there a way to make it identical to C? I say again, you're asking for far more digits than are actually there. The extra digits are only an illusion of accuracy; they are essentially garbage values that have no real meaning. It really does not make any sense to print more digits than are actually there. On the other hand, if your purpose is to export the double in a textual representation that guarantees reproduction of exactly the same bits when imported later, you could use the %a format which writes out the mantissa in exact hexadecimal form. It can then be parsed again later to reproduce the same bits as was in the original double. Or if your goal is simply to replicate C behaviour, there's also the option of calling the C fprintf directly. Just import core.stdc.stdio or declare the prototype yourself in an extern(C) declaration. T Thanks, but even using core.stdc.stdio.fprintf() it still shows a different result on the screen. It seems this is a feature of D I will have to get used to and accept the fact I can't always get the same number as in C even though in the end it doesn't make a difference cause as you explained the final digits are just garbage anyway.
Re: Easiest way to display images
On Wednesday, 6 February 2019 at 03:35:03 UTC, Adam D. Ruppe wrote: On Wednesday, 6 February 2019 at 01:04:43 UTC, Murilo wrote: You should later joing the facebook group Programming in D. Eh, I don't really like facebook groups. With my libraries too, I don't really care if anyone uses them. I make them for myself and put them online because it is easy for me. I don't count downloads or anything; it just means nothing to me. Adam, is there a place where we can chat? I don't like chatting via this forum. I would like to talk to you about your modules and about the D lang.
Re: Handling big FP numbers
On Saturday, 9 February 2019 at 04:36:26 UTC, DanielG wrote: On Saturday, 9 February 2019 at 04:32:44 UTC, Murilo wrote: Thank you very much for clearing this up. But how do I make D behave just like C? Is there a way to do that? Off the top of my head, you'd have to link against libc so you could use printf() directly. But may I ask why that is so important to you? That is important because there are some websites with problems for you to send them your code and it automatically checks if you got it right, in D it will always say "Wrong Answer" cause it outputs a different string than what is expected.
Re: Handling big FP numbers
On Saturday, 9 February 2019 at 04:30:22 UTC, DanielG wrote: On Saturday, 9 February 2019 at 03:33:13 UTC, Murilo wrote: Thanks but here is the situation, I use printf("%.20f", 0.1); in both C and D, C returns 0.1555 whereas D returns 0.10001000. So I understand your point, D rounds off more, but that causes loss of precision, isn't that something bad if you are working with math and physics for example? 0.1 in floating point is actually 0.10001490116119384765625 behind the scenes. So why is it important that it displays as: 0.1555 versus 0.10001000 ? *Technically* the D version has less error, relative to the internal binary representation. Since there's no exact way of representing 0.1 in floating point, the computer has no way of knowing you really mean "0.1 decimal". If the accuracy is that important to you, you'll probably have to look into software-only number representations, for arbitrary decimal precision (I've not explored them in D, but other languages have things like "BigDecimal" data types) Thank you very much for clearing this up. But how do I make D behave just like C? Is there a way to do that?
Re: Handling big FP numbers
On Saturday, 9 February 2019 at 03:28:24 UTC, Adam D. Ruppe wrote: On Saturday, 9 February 2019 at 03:21:51 UTC, Murilo wrote: Now, changing a little bit the subject. All FPs in D turn out to be printed differently than they are in C and in C it comes out a little more precise than in D. Is this really supposed to happen? Like I said in my first message, the D default rounds off more than the C default. This usually results in more readable stuff - the extra noise at the end is not that helpful in most cases. But you can change this with the format specifiers (use `writefln` instead of `writeln` and give a precision argument) or, of course, you can use the same C printf function from D. Thanks, but which precision specifier should I use? I already tried "%.20f" but it still produces a result different from C? Is there a way to make it identical to C?
Re: Handling big FP numbers
On Saturday, 9 February 2019 at 03:28:24 UTC, Adam D. Ruppe wrote: On Saturday, 9 February 2019 at 03:21:51 UTC, Murilo wrote: Now, changing a little bit the subject. All FPs in D turn out to be printed differently than they are in C and in C it comes out a little more precise than in D. Is this really supposed to happen? Like I said in my first message, the D default rounds off more than the C default. This usually results in more readable stuff - the extra noise at the end is not that helpful in most cases. But you can change this with the format specifiers (use `writefln` instead of `writeln` and give a precision argument) or, of course, you can use the same C printf function from D. Thanks but here is the situation, I use printf("%.20f", 0.1); in both C and D, C returns 0.1555 whereas D returns 0.10001000. So I understand your point, D rounds off more, but that causes loss of precision, isn't that something bad if you are working with math and physics for example?
Re: Handling big FP numbers
On Saturday, 9 February 2019 at 03:03:41 UTC, H. S. Teoh wrote: On Sat, Feb 09, 2019 at 02:12:29AM +, Murilo via Digitalmars-d-learn wrote: Why is it that in C when I attribute the number 991234307654329925.7865 to a double it prints 991234299470108672. and in D it prints 9912342990. ? Apparently both languages cause a certain loss of precision(which is part of converting the decimal system into the binary system) but why is it that the results are different? It's not only because of converting decimal to binary, it's also because double only has 64 bits to store information, and your number has far more digits than can possibly fit into 64 bits. Some number of bits are used up for storing the sign and exponent, so `double` really can only store approximately 15 decimal digits. Anything beyond that simply doesn't exist in a `double`, so attempting to print that many digits will inevitably produce garbage trailing digits. If you round the above outputs to about 15 digits, you'll see that they are essentially equal. As to why different output is produced, that's probably just an artifact of different printing algorithms used to output the number. There may be a small amount of difference around or after the 15th digit because D implicitly converts to `real` (which on x86 is the 80-bit proprietary FPU representation) for some operations and rounds it back, while C only operates on 64-bit double. This may cause some slight difference in behaviour around the 15th digit or so. Now, changing a little bit the subject. All FPs in D turn out to be printed differently than they are in C and in C it comes out a little more precise than in D. Is this really supposed to happen?
Re: Handling big FP numbers
On Saturday, 9 February 2019 at 02:54:18 UTC, Adam D. Ruppe wrote: On Saturday, 9 February 2019 at 02:46:52 UTC, Murilo wrote: But I used the type double in D which is supposed to be only 64 bits long and not 80 bits long, the type real is the one which is supposed to be 80 bits long. Right? Right, BUT the compile time stuff is done before that. double a = 1.0 * 2.0; The 1.0*2.0 is done as real inside the compiler, then the *result* is assigned to the 64 bit double. Whereas in a C++ compiler, that would be done 64 bit throughout. So the different intermediate rounding can give a different result. (The `real` thing in D was a massive mistake. It is slow and adds nothing but confusion.) ahhh okay, thanks for clearing it up. is there a way to bypass that?
Re: Handling big FP numbers
On Saturday, 9 February 2019 at 02:42:09 UTC, Adam D. Ruppe wrote: On Saturday, 9 February 2019 at 02:12:29 UTC, Murilo wrote: prints Two likely reasons: the D compiler does compile time stuff at 80 bit, whereas the C++ one probably uses 64 bit, and the D default print rounds more aggressively than default C++ printing. It is useful to put stuff in runtime variables of type `double` to avoid the differnt bit stuff, and print with printf in both languages to ensure that is the same. Hi, thanks for the information. But I used the type double in D which is supposed to be only 64 bits long and not 80 bits long, the type real is the one which is supposed to be 80 bits long. Right?
Handling big FP numbers
Why is it that in C when I attribute the number 991234307654329925.7865 to a double it prints 991234299470108672. and in D it prints 9912342990. ? Apparently both languages cause a certain loss of precision(which is part of converting the decimal system into the binary system) but why is it that the results are different?
Re: Easiest way to display images
On Wednesday, 6 February 2019 at 04:36:12 UTC, DanielG wrote: On Wednesday, 6 February 2019 at 01:04:43 UTC, Murilo wrote: You should later joing the facebook group Programming in D. The D community is small enough that it's unlikely anybody in that Facebook group, isn't already using the newsgroups / IRC / etc to discuss D. Even the official subreddit barely gets any traffic. What I'm trying to say is, you're not going to have much luck getting that Facebook group off the ground. FB adds nothing to the existing options, and worse it's just an elaborate scheme to harvest personal information which one can safely assume the vast majority of D programmers are privacy-savvy enough to avoid. The facebook group already has 82 members, some of which are experienced users of D. There has been some reasonable amount of discussions going on there in the last weeks. And you don't need to worry about the "information harvesting" if you don't post personal stuff. It is a group to talk about a language and not about your life.
Re: Easiest way to display images
On Tuesday, 5 February 2019 at 21:25:54 UTC, Adam D. Ruppe wrote: On Tuesday, 5 February 2019 at 21:11:52 UTC, Murilo wrote: What would be the easiest way to simply display a jpg or png image on the screen for a few seconds in Windows? That's a little more complex than playing a sound, there's no one function to do it. You can in... oh about 50 lines, but I can't write them off the top of my head. You should later joing the facebook group Programming in D. There you could show your library, lots of people would like to use it. https://www.facebook.com/groups/662119670846705/
Re: Easiest way to display images
On Tuesday, 5 February 2019 at 21:25:54 UTC, Adam D. Ruppe wrote: On Tuesday, 5 February 2019 at 21:11:52 UTC, Murilo wrote: What would be the easiest way to simply display a jpg or png image on the screen for a few seconds in Windows? That's a little more complex than playing a sound, there's no one function to do it. You can in... oh about 50 lines, but I can't write them off the top of my head. However, I do have a library that can do it in 5 lines. --- import arsd.simpledisplay; import arsd.image; void main() { displayImage(Image.fromMemoryImage(loadImageFromFile("filename here"))); } Thank you so but so much. I tested it here and it works.
Easiest way to display images
What would be the easiest way to simply display a jpg or png image on the screen for a few seconds in Windows?
Re: How do I use libraries manually?
On Tuesday, 5 February 2019 at 19:46:32 UTC, H. S. Teoh wrote: Thank you very much, I will try what you just explained. And yes I would really appreciate it if people would make single file libraries that I can just import as if it were any other .d file.
Re: Converting a type to a char
On Friday, 25 January 2019 at 15:53:10 UTC, Thomas Gregory wrote: I would like to check that a char (unknown at compile time) matches a particular type but I would like to do so without if statements or a hash map as I would like it to be as fast as possible. Ideally I would choose something like this: enum typeIndex{ byte = 0, ubyte, short, ushort, int, uint } char[6] typechars="cCsSiI"; bool check(T)(char c){ return typechars[typeIndex(typeof(T))]==c; } Though I know this is implementation is not remotely correct D. Join this group https://www.facebook.com/groups/662119670846705/ , it is the D lang facebook group, there we can help you out with any doubts.
How do I use libraries manually?
Can anyone teach me how to download and use a library manually without having to use DUB?
Re: Simple way to play sounds using D
On Tuesday, 5 February 2019 at 17:14:05 UTC, Adam D. Ruppe wrote: On Tuesday, 5 February 2019 at 17:09:10 UTC, Murilo wrote: When I compile the code above the compiler says Error: linker exited with status 1 What should I do? It might have to be "shoot.wav"w, notice the w on the end. But I am guessing the main problem is not linking in the winmm lib and dll. It will probably work to add pragma(lib, "winmm"); to your file right after the import. You were right :) No need for the w but it was necessary the pragma(lib, "winmm"); It worked! Thanks so much man, all the best to you.
Re: Simple way to play sounds using D
On Tuesday, 5 February 2019 at 17:01:54 UTC, Adam D. Ruppe wrote: On Tuesday, 5 February 2019 at 16:50:36 UTC, Murilo wrote: Hi guys, I would like to play simple sounds but I want something easy to use, can you show me the simplest way to do that? Like a function that just loads a .wav and plays it. If you are on Windows, the OS has a nice function for little ones: https://docs.microsoft.com/en-us/previous-versions//dd743680(v=vs.85)#examples Hi, thanks for the reply. import std.stdio, core.sys.windows.mmsystem; void main() { PlaySound("shoot.wav", null, SND_FILENAME); } When I compile the code above the compiler says Error: linker exited with status 1 What should I do?
Simple way to play sounds using D
Hi guys, I would like to play simple sounds but I want something easy to use, can you show me the simplest way to do that? Like a function that just loads a .wav and plays it.
Re: Working with randomSample
On Friday, 28 December 2018 at 03:59:52 UTC, Ali Çehreli wrote: It's because randomSample returns either an input range or a forward range depending both on the kind of range that it gets and the random number generator used. Documented here: Ali Thank you very much, now it all makes sense.
Working with randomSample
Why is it that when I type "auto choice = randomSample(array);" and later when I try to index choice as in choice[1] it gives an error message?
Re: How do I install a library?
On Tuesday, 11 December 2018 at 07:25:49 UTC, Seb wrote: On Monday, 10 December 2018 at 00:18:52 UTC, Murilo wrote: Hi guys, thank you for helping me out here, there is this facebook group for the D language, here we can help and teach each other. It is called Programming in D. Please join. https://www.facebook.com/groups/662119670846705/?ref=bookmarks Please stop this spam. It is not spam, I really created this group, it has 80 members now, I would like more members so we could help each other there rather than here, facebook is a better communication tool than this mailing list. But since you asked me to stop then I will stop.
Re: Which character set does D use?
Hi guys, thank you for helping me out here, there is this facebook group for the D language, here we can help and teach each other. It is called Programming in D. Please join. https://www.facebook.com/groups/662119670846705/?ref=bookmarks
Re: How do I install a library?
Hi guys, thank you for helping me out here, there is this facebook group for the D language, here we can help and teach each other. It is called Programming in D. Please join. https://www.facebook.com/groups/662119670846705/?ref=bookmarks
Re: Why pow() won't go beyond 2^31?
Hi guys, thank you for helping me out here, there is this facebook group for the D language, here we can help and teach each other. It is called Programming in D. Please join. https://www.facebook.com/groups/662119670846705/?ref=bookmarks
Re: Working with ranges
Hi guys, thank you for helping me out here, there is this facebook group for the D language, here we can help and teach each other. It is called Programming in D. Please join. https://www.facebook.com/groups/662119670846705/?ref=bookmarks
Re: Working with ranges
On Saturday, 8 December 2018 at 04:16:25 UTC, Adam D. Ruppe wrote: On Saturday, 8 December 2018 at 04:11:03 UTC, Murilo wrote: What is the difference between declaring "int[3] a = [1,2,3];" and declaring "int[] a = [1,2,3];"? Is the first an array and the second a range? They are both arrays, just the former one has a fixed size and the latter does not. Ranges require a way to iterate and consume elements, meaning they cannot be fixed size. I always thought that leaving the square brackets empty would create an array of flexible size, it never occurred to me that it was creating something else. That's what it is, just a flexible array also happens to be an array, whereas a fixed-size array is not one. But a slice of a fixed size one yields a flexible one.. which is why the ps[] thing works to create a range out of it. Thank you guys so much for the explanation, it is all making more sense now.
Re: Working with ranges
On Saturday, 8 December 2018 at 03:51:02 UTC, Adam D. Ruppe wrote: On Saturday, 8 December 2018 at 03:48:10 UTC, Murilo wrote: Try passing `ps[]` to the function instead of plain `ps` and see what happens. How do I transform an array into a range? With the slicing operator, []. Thank you very much, it worked now. What is the difference between declaring "int[3] a = [1,2,3];" and declaring "int[] a = [1,2,3];"? Is the first an array and the second a range? I always thought that leaving the square brackets empty would create an array of flexible size, it never occurred to me that it was creating something else.
Re: Working with ranges
On Saturday, 8 December 2018 at 03:46:11 UTC, Adam D. Ruppe wrote: On Saturday, 8 December 2018 at 03:37:56 UTC, Murilo wrote: Hi guys, I have created an array of strings with "string[12] ps string[12] isn't a range, but string[] is. Try passing `ps[]` to the function instead of plain `ps` and see what happens. How do I transform an array into a range?
Working with ranges
Hi guys, I have created an array of strings with "string[12] ps = ["cat", "dog", "lion", "wolf", "coin", "chest", "money", "gold", "A", "B", "C", "D"];". I want to use the array as a range and I want to randomize it, like I want to transform that into several other ranges with the same elements but in different orders, how do I do that? I tried using the function choice() from std.random but it gives an error message for some reason.
Why pow() won't go beyond 2^31?
I am using the function pow() from std.math but if I try pow(2, 32) it returns 0, it doesn't compute beyond the maximum value of an int(2^31) and I am working with long. What should I do?
Re: How do I install a library?
On Thursday, 8 November 2018 at 23:28:05 UTC, Steven Schveighoffer wrote: On 11/8/18 6:07 PM, Steven Schveighoffer wrote: If you want to build the dlangui library directly and install it on your own without dub, you would need to download the source (probably from github) and build it using dub. When I said without using dub, I meant without using dub to build your project. You still need to use dub to build the library. -Steve It finally worked, but I can't just compile it normally, I have to use dub run, I wish it were something simple that I just download into the folder and then use an import statement and then compile it like any other program. I wish it were as simple as using std.stdio for example.
Re: How do I install a library?
On Thursday, 8 November 2018 at 22:28:38 UTC, Steven Schveighoffer wrote: On 11/8/18 4:46 PM, Murilo wrote: I want to install the library DlangUI but I don't know how to do it. In python I just type pip and it works, but in D I don't know how to do it. Can anyone help me? dlangui will be fetched if you make it a dependency of your project. When you run dub init on your project, it will ask for dependencies, just type dlangui in there. -Steve Thanks, I tried that but when I add the import dlangui in the beginning it doesn't work. I wanted to just type import dlangui in the beginning of the file so I can call the dlangui functions.
How do I install a library?
I want to install the library DlangUI but I don't know how to do it. In python I just type pip and it works, but in D I don't know how to do it. Can anyone help me?
Which character set does D use?
Does D use ASCII or UNICODE? It seems to use ASCII since it causes error whenever I use a non-ASCII character.