Re: How to simulate Window's "Press any key to continue..."
On Friday, 22 November 2019 at 04:45:21 UTC, Mike Parker wrote: On Friday, 22 November 2019 at 04:22:07 UTC, FireController#1847 wrote: Right, but readln will only wait until the user presses the delimiter (by default Enter/Return). I want it to wait until ANY key is pressed, not a specific key The documentation for std.stdio.File shows two functions for reading input: readln and readf. If readln isn't what you want, then readf probably is: https://dlang.org/phobos/std_stdio.html#.File.readf Also, there's a freely available book online to help get you up to speed: Programming in D. Here's the section on reading from stdin with readf: http://ddili.org/ders/d.en/input.html Sorry, I just noticed the book doesn't cover how to do what you want and it's probably not obvious. You need to call readf with a character format string (%c): import std.stdio; void main() { writeln("Press any key to continue..."); char c; readf("%c", &c); writeln("Thanks!"); }
Re: How to simulate Window's "Press any key to continue..."
On Friday, 22 November 2019 at 04:22:07 UTC, FireController#1847 wrote: Right, but readln will only wait until the user presses the delimiter (by default Enter/Return). I want it to wait until ANY key is pressed, not a specific key The documentation for std.stdio.File shows two functions for reading input: readln and readf. If readln isn't what you want, then readf probably is: https://dlang.org/phobos/std_stdio.html#.File.readf Also, there's a freely available book online to help get you up to speed: Programming in D. Here's the section on reading from stdin with readf: http://ddili.org/ders/d.en/input.html
Re: How to simulate Window's "Press any key to continue..."
On Friday, 22 November 2019 at 04:41:30 UTC, mipri wrote: ~this() { reset(); } Oh, if you don't ever call raw() this will break your terminal. I just copied some code from a toy program and adapted it, and didn't notice that until I posted.
Re: How to simulate Window's "Press any key to continue..."
On Friday, 22 November 2019 at 04:22:07 UTC, FireController#1847 wrote: Right, but readln will only wait until the user presses the delimiter (by default Enter/Return). I want it to wait until ANY key is pressed, not a specific key If curses is available you can use it, at the cost of completely changing how you do I/O (in a good way if you need lots of updates): #! /usr/bin/env dub /+ dub.sdl: dependency "nice-curses" version="~>0.2.5" +/ import std.stdio; import nice.curses: Curses; void main() { auto curses = new Curses; auto scr = curses.stdscr; curses.setCursor(0); scr.addstr("Press any key to continue..."); scr.refresh; curses.update; scr.getch; } If you really just briefly want getch-style input in a normal terminal program, and still have a posix system, you can do that with tcsetattr. https://stackoverflow.com/questions/7469139/what-is-the-equivalent-to-getch-getche-in-linux struct Terminal { import core.stdc.stdio: getchar; import core.sys.posix.termios: tcgetattr, tcsetattr, termios, ECHO, ICANON, TCSANOW, TCSAFLUSH; private termios last; int getch() { return getchar(); } int getch_once() { raw; auto r = getchar; reset; return r; } void raw() { termios term; tcgetattr(0, &last); term = last; term.c_lflag &= ~(ICANON | ECHO); tcsetattr(0, TCSANOW, &term); } void reset() { tcsetattr(0, TCSAFLUSH, &last); } ~this() { reset(); } } void main() { import std.stdio: write, writeln; Terminal term; write("Press any key to continue:"); term.getch_once(); writeln; }
Re: How to simulate Window's "Press any key to continue..."
On Friday, 22 November 2019 at 04:19:40 UTC, mipri wrote: On Friday, 22 November 2019 at 04:10:23 UTC, FireController#1847 wrote: I'm an extreme beginner to DLang (just started using it.. oh, an hour ago?), and I already can't figure out a, what I'd consider, fairly simplistic thing. This is my current code: module DTestApp1; import std.stdio; int main() { write("Press any key to continue..."); stdin.read(); return 0; } I am using Visual Studio to write it, and no matter what I do I cannot get it to work. I attempted to import std.stream;, but it said that while it could find the file, it cannot be read. Am I using the wrong function? For those who don't know, what I'm trying to do is pause the program until literally any key is pressed while in the console. The error doesn't suggest the right replacement, but it still tells you that the function you want isn't available: ./test.d(6): Error: no property read for type File, did you mean std.stdio.File.readf(alias format, Data...)(auto ref Data data) if (isSomeString!(typeof(format)))? std.stdio's documentation is here: https://dlang.org/phobos/std_stdio.html and readln is a function you can use for your purpose. stdin.readln(); Or just: readln; Right, but readln will only wait until the user presses the delimiter (by default Enter/Return). I want it to wait until ANY key is pressed, not a specific key
Re: How to simulate Window's "Press any key to continue..."
On Friday, 22 November 2019 at 04:10:23 UTC, FireController#1847 wrote: I'm an extreme beginner to DLang (just started using it.. oh, an hour ago?), and I already can't figure out a, what I'd consider, fairly simplistic thing. This is my current code: module DTestApp1; import std.stdio; int main() { write("Press any key to continue..."); stdin.read(); return 0; } I am using Visual Studio to write it, and no matter what I do I cannot get it to work. I attempted to import std.stream;, but it said that while it could find the file, it cannot be read. Am I using the wrong function? For those who don't know, what I'm trying to do is pause the program until literally any key is pressed while in the console. The error doesn't suggest the right replacement, but it still tells you that the function you want isn't available: ./test.d(6): Error: no property read for type File, did you mean std.stdio.File.readf(alias format, Data...)(auto ref Data data) if (isSomeString!(typeof(format)))? std.stdio's documentation is here: https://dlang.org/phobos/std_stdio.html and readln is a function you can use for your purpose. stdin.readln(); Or just: readln;
How to simulate Window's "Press any key to continue..."
I'm an extreme beginner to DLang (just started using it.. oh, an hour ago?), and I already can't figure out a, what I'd consider, fairly simplistic thing. This is my current code: module DTestApp1; import std.stdio; int main() { write("Press any key to continue..."); stdin.read(); return 0; } I am using Visual Studio to write it, and no matter what I do I cannot get it to work. I attempted to import std.stream;, but it said that while it could find the file, it cannot be read. Am I using the wrong function? For those who don't know, what I'm trying to do is pause the program until literally any key is pressed while in the console.
Re: The effect of ref
Adam D. Ruppe wrote: On Friday, 22 November 2019 at 03:42:26 UTC, dokutoku wrote: Is there a difference in the execution speed and stability when executing the program by rewriting the parameter of the function argument like this? the generated code the processor sees is generally identical, but the `ref` version is potentially better because then X cannot possibly be `null` which can help you write better code and might help the optimizer too. still, using explicit pointers may be good for readability. int a; foo(a); // does it chage `a`? boo(&a); // oh, yeah, now i see that it will prolly change `a` unsafe coding style, but for me pointers for `ref` are more readable.
Re: The effect of ref
On Friday, 22 November 2019 at 03:42:26 UTC, dokutoku wrote: Is there a difference in the execution speed and stability when executing the program by rewriting the parameter of the function argument like this? the generated code the processor sees is generally identical, but the `ref` version is potentially better because then X cannot possibly be `null` which can help you write better code and might help the optimizer too.
Re: The effect of ref
On Friday, 22 November 2019 at 03:42:26 UTC, dokutoku wrote: Is there a difference in the execution speed and stability when executing the program by rewriting the parameter of the function argument like this? ```d void test1 (int * X) { // some processing } void test2 (ref int X) { // some processing } ``` The Compiler Explorer supports D, so it's a good way to ask these questions. https://godbolt.org/z/gnR6Eu int example.test1(int*): mov eax, DWORD PTR [rdi] imuleax, eax add eax, 1 ret int example.test2(ref int): mov eax, DWORD PTR [rdi] imuleax, eax add eax, 1 ret
The effect of ref
Is there a difference in the execution speed and stability when executing the program by rewriting the parameter of the function argument like this? ```d void test1 (int * X) { // some processing } void test2 (ref int X) { // some processing } ```
Re: Splitting a stream of data on based on data change.
On Thursday, 21 November 2019 at 22:11:59 UTC, Alex wrote: On Thursday, 21 November 2019 at 21:36:08 UTC, Taylor R Hillegeist wrote: I was looking through the standard library for a good way to split a range into several ranges based on value changes in the stream: AAABB would be split on the AB transition into: AAA BB I just couldn't figure out an elegant way to do it? Any ideas? Like this? ´´´ void main() { import std; "AAABB" .chunkBy!((a,b) => a == b) .writeln; } ´´´ https://dlang.org/library/std/algorithm/iteration/group.html https://dlang.org/library/std/algorithm/iteration/chunk_by.html Just like that.
Re: Splitting a stream of data on based on data change.
On Thursday, 21 November 2019 at 21:36:08 UTC, Taylor R Hillegeist wrote: I was looking through the standard library for a good way to split a range into several ranges based on value changes in the stream: AAABB would be split on the AB transition into: AAA BB I just couldn't figure out an elegant way to do it? Any ideas? Like this? ´´´ void main() { import std; "AAABB" .chunkBy!((a,b) => a == b) .writeln; } ´´´ https://dlang.org/library/std/algorithm/iteration/group.html https://dlang.org/library/std/algorithm/iteration/chunk_by.html
Splitting a stream of data on based on data change.
I was looking through the standard library for a good way to split a range into several ranges based on value changes in the stream: AAABB would be split on the AB transition into: AAA BB I just couldn't figure out an elegant way to do it? Any ideas?
Re: equivalent of typeid(Class).name at compile-time
On Thursday, 21 November 2019 at 20:45:16 UTC, Steven Schveighoffer wrote: To clarify, I need the compile time string that will match typeid(instance).name, so I can match the derived type. You have to make sure that the derived type is passed to your register function, but then std.traits.fullyQualifiedName!T ought to give it to you.
Re: equivalent of typeid(Class).name at compile-time
On 11/21/19 3:44 PM, Steven Schveighoffer wrote: I thought I could do typeid(Class).name to get the class name that will be returned at runtime if you did typeid(instance).name. But it's not accessible at compile-time. What compile-time string should I use for instance in a constructed switch statement? I'm trying to implement serialization and deserialization of classes, but I really would like to avoid using a class enum if possible, since the type id is already there and generated by the compiler. To clarify, I need the compile time string that will match typeid(instance).name, so I can match the derived type. -Steve
equivalent of typeid(Class).name at compile-time
I thought I could do typeid(Class).name to get the class name that will be returned at runtime if you did typeid(instance).name. But it's not accessible at compile-time. What compile-time string should I use for instance in a constructed switch statement? I'm trying to implement serialization and deserialization of classes, but I really would like to avoid using a class enum if possible, since the type id is already there and generated by the compiler. -Steve
Re: Dmd install to new Windows 10 system can't run app.d
On Thursday, 21 November 2019 at 09:26:39 UTC, zoujiaqing wrote: On Thursday, 21 November 2019 at 08:42:39 UTC, Seb wrote: Note this line: Running .\myproject.exe Program exited with code -1073741515 Your compiled program is crashing. Could you run the compiled binary manually and obtain a stack trace? Install msvcr100.dll for x64 the question is solved, thanks! https://download.microsoft.com/download/3/2/2/3224B87F-CFA0-4E70-BDA3-3DE650EFEBA5/vcredist_x64.exe I had the same issue a while ago and reported it here https://issues.dlang.org/show_bug.cgi?id=20061
Re: Dmd install to new Windows 10 system can't run app.d
On Thursday, 21 November 2019 at 08:42:39 UTC, Seb wrote: Note this line: Running .\myproject.exe Program exited with code -1073741515 Your compiled program is crashing. Could you run the compiled binary manually and obtain a stack trace? Install msvcr100.dll for x64 the question is solved, thanks! https://download.microsoft.com/download/3/2/2/3224B87F-CFA0-4E70-BDA3-3DE650EFEBA5/vcredist_x64.exe
Re: Dmd install to new Windows 10 system can't run app.d
On Thursday, 21 November 2019 at 08:42:39 UTC, Seb wrote: Note this line: Running .\myproject.exe Program exited with code -1073741515 Your compiled program is crashing. Could you run the compiled binary manually and obtain a stack trace? x86 is OK, but x64 bad. PS D:\projects\myproject> dub run --arch=x86 Performing "debug" build using D:\Develop\dmd2\windows\bin\dmd.exe for x86. myproject ~master: building configuration "application"... Linking... Running .\myproject.exe Edit source/app.d to start your project.
Re: Dmd install to new Windows 10 system can't run app.d
On Thursday, 21 November 2019 at 08:42:39 UTC, Seb wrote: On Thursday, 21 November 2019 at 08:30:33 UTC, zoujiaqing wrote: 1. Download dmd.2.088.1.windows.7z 2. Unzip it to D:\Develop\dmd2 3. Add ENV D:\Develop\dmd2\windows\bin to System Path 4. Run `dub --version` and `dmd --version` in powershell is OK 5. dub ini myproject (no dependency) 6. Run `cd myproject` and `dub run` is error... [...] Note this line: Running .\myproject.exe Program exited with code -1073741515 Your compiled program is crashing. Could you run the compiled binary manually and obtain a stack trace? I don't install debug tools. but add mscoff flags is OK. PS D:\projects\myproject> cat .\source\app.d import std.stdio; void main() { writeln("Edit source/app.d to start your project."); } PS D:\projects\myproject> dub run --arch=x86_mscoff Performing "debug" build using D:\Develop\dmd2\windows\bin\dmd.exe for x86, x86_mscoff. myproject ~master: target for configuration "application" is up to date. To force a rebuild of up-to-date targets, run again with --force. Running .\myproject.exe Edit source/app.d to start your project.
Re: Dmd install to new Windows 10 system can't run app.d
On Thursday, 21 November 2019 at 08:30:33 UTC, zoujiaqing wrote: 1. Download dmd.2.088.1.windows.7z 2. Unzip it to D:\Develop\dmd2 3. Add ENV D:\Develop\dmd2\windows\bin to System Path 4. Run `dub --version` and `dmd --version` in powershell is OK 5. dub ini myproject (no dependency) 6. Run `cd myproject` and `dub run` is error... [...] Note this line: Running .\myproject.exe Program exited with code -1073741515 Your compiled program is crashing. Could you run the compiled binary manually and obtain a stack trace?
Dmd install to new Windows 10 system can't run app.d
1. Download dmd.2.088.1.windows.7z 2. Unzip it to D:\Develop\dmd2 3. Add ENV D:\Develop\dmd2\windows\bin to System Path 4. Run `dub --version` and `dmd --version` in powershell is OK 5. dub ini myproject (no dependency) 6. Run `cd myproject` and `dub run` is error... Error Logging infomation: PS D:\projects\myproject> dub run -v Using dub registry url 'https://code.dlang.org/' Refreshing local packages (refresh existing: true)... Looking for local package map at C:\ProgramData\dub\packages\local-packages.json Looking for local package map at C:\Users\zouji\AppData\Local\dub\packages\local-packages.json Note: Failed to determine version of package myproject at .. Assuming ~master. Refreshing local packages (refresh existing: false)... Looking for local package map at C:\ProgramData\dub\packages\local-packages.json Looking for local package map at C:\Users\zouji\AppData\Local\dub\packages\local-packages.json Refreshing local packages (refresh existing: false)... Looking for local package map at C:\ProgramData\dub\packages\local-packages.json Looking for local package map at C:\Users\zouji\AppData\Local\dub\packages\local-packages.json Generating using build Configuring dependent myproject, deps: Performing "debug" build using D:\Develop\dmd2\windows\bin\dmd.exe for x86_64. myproject ~master: target for configuration "application" is up to date. Using existing build in D:\projects\myproject\.dub\build\application-debug-windows-x86_64-dmd_2088-7987457E14148EF60F863BFBCDFB8A1F\. Copying target from D:\projects\myproject\.dub\build\application-debug-windows-x86_64-dmd_2088-7987457E14148EF60F863BFBCDFB8A1F\myproject.exe to D:\projects\myproject To force a rebuild of up-to-date targets, run again with --force. Running .\myproject.exe Program exited with code -1073741515 I think this problem has a great impact on a new person using D language under Windows system.
Re: How to get child class Type and members from parent class?
On Wednesday, 20 November 2019 at 22:26:17 UTC, Adam D. Ruppe wrote: On Wednesday, 20 November 2019 at 20:57:56 UTC, Matheus wrote: This is a different way of designing things, do people use this often? This is really only useful sometimes. It is important to notice that if you do class C : I {} I c = new C(); c.something(); the template this there will show I, not C. All it means is this is being called on an object of that *static* type. So it isn't really a substitute for traditional virtual functions. Sometimes appropriate to use, just often not. Thanks every friends :)