digitalmars.D.learn - How to use "read_bool"?
- Zeh (28/28) Aug 02 2012 Hi, i am just a newbie trying learn D. But, i get having some
- Timon Gehr (10/36) Aug 02 2012 presumably read_bool is part of the tutorial. Otherwise you may use this...
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (20/22) Aug 02 2012 As Timon said, read_bool() is a separate function on the same page, a
- simendsjo (25/48) Aug 03 2012 =
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (4/5) Aug 03 2012 The function is at the very end of the following chapter:
- simendsjo (6/12) Aug 03 2012 Ah, ok. I still haven't read the chapters you've translated.
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (10/13) Aug 03 2012 I think all of the following: This is my project for fun. I don't think
- bearophile (9/11) Aug 03 2012 Human psychology is not linear :-) Sometimes if you pay some (a
- Philippe Sigaud (9/10) Aug 03 2012 Well money is nothing but effect in our mind...
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (6/9) Aug 03 2012 How timely! Crimson Sphere has just started the Korean translation:
- Era Scarecrow (6/14) Aug 03 2012 Ouch those pages just hurt my eyes. I had enough of the Korean
- Zeh (10/10) Aug 03 2012 Thanks for the help, but i tryed both solutions posted and still
- simendsjo (36/44) Aug 04 2012 This works:
- Zeh (3/54) Aug 06 2012 Very interesting way to solve the problem (at least for a noobie
- Timon Gehr (2/7) Aug 06 2012 Works for me. Maybe readln behaves differently on windows?
Hi, i am just a newbie trying learn D. But, i get having some trouble with "read_bool". More specifically on program of this lesson: import std.stdio; import std.conv; import std.string; void main() { write("How many are we? "); int personCount; readf(" %s", &personCount); write("How many bicycles are there? "); int bicycleCount; readf(" %s", &bicycleCount); write("What is the distance to the beach? "); int distance; readf(" %s", &distance); bool existsCar = read_bool("Is there a car? "); bool existsLicense = read_bool("Is there a driver license? "); When i try compile this, i get the following errors: hello.d|43|Error: undefined identifier read_bool| hello.d|44|Error: undefined identifier read_bool| ||=== Build finished: 2 errors, 0 warnings (0 minutes, 0 seconds) ===| So, someone know what's happening? What is the correct way to use the Read_bool? Thanks for everyone!
Aug 02 2012
On 08/03/2012 06:17 AM, Zeh wrote:Hi, i am just a newbie trying learn D. But, i get having some trouble with "read_bool". More specifically on program of this lesson: import std.stdio; import std.conv; import std.string; void main() { write("How many are we? "); int personCount; readf(" %s", &personCount); write("How many bicycles are there? "); int bicycleCount; readf(" %s", &bicycleCount); write("What is the distance to the beach? "); int distance; readf(" %s", &distance); bool existsCar = read_bool("Is there a car? "); bool existsLicense = read_bool("Is there a driver license? "); When i try compile this, i get the following errors: hello.d|43|Error: undefined identifier read_bool| hello.d|44|Error: undefined identifier read_bool| ||=== Build finished: 2 errors, 0 warnings (0 minutes, 0 seconds) ===| So, someone know what's happening? What is the correct way to use the Read_bool? Thanks for everyone!presumably read_bool is part of the tutorial. Otherwise you may use this: bool read_bool(){ auto str = readln()[0..$-1]; switch(str){ case "true", "y", "ye", "yes": return true; case "false", "n", "no": return false; default: throw new Exception("please answer yes or no"); } }
Aug 02 2012
On 08/02/2012 09:17 PM, Zeh wrote:Hi, i am just a newbie trying learn D. But, i get having some trouble with "read_bool". More specifically on program of this lesson:As Timon said, read_bool() is a separate function on the same page, a little after main(): bool read_bool(string message) { // Print the message writef(message ~ "(false or true) "); // Read the line as a string string input; while (input.length == 0) { input = chomp(readln()); } // Produce a 'bool' value from that string bool result = to!bool(input); // Return the result to the caller return result; } Unlike Timon's function, you must enter either "false" or "true" with the one above. Ali
Aug 02 2012
On Fri, 03 Aug 2012 08:05:46 +0200, Ali =C3=87ehreli <acehreli yahoo.com=wrote:On 08/02/2012 09:17 PM, Zeh wrote: > Hi, i am just a newbie trying learn D. But, i get having some troub=le> with "read_bool". More specifically on program of this lesson: As Timon said, read_bool() is a separate function on the same page, a ==little after main(): bool read_bool(string message) { // Print the message writef(message ~ "(false or true) "); // Read the line as a string string input; while (input.length =3D=3D 0) { input =3D chomp(readln()); } // Produce a 'bool' value from that string bool result =3D to!bool(input); // Return the result to the caller return result; } Unlike Timon's function, you must enter either "false" or "true" with ==the one above. AliWhat tutorials is this? Here's another version: import std.stdio, std.string, std.conv; bool read_bool(in string message) { // in as we don't escape or modify t= he = input while(true) { // loop until we get true/false write(message, " (false or true): "); // avoid concat allocatio= n string input; do { // no need to check input on entering input =3D readln().chomp(); // UFCS } while(!input); // no need to check length try return input.to!bool; catch {} // don't care if it's not true/false. Keep nagging } } void main() { auto input =3D read_bool("Do it?"); writeln(input ? "Hell yeah, do it!" : "No way!"); }
Aug 03 2012
On 08/03/2012 09:12 AM, simendsjo wrote:What tutorials is this?The function is at the very end of the following chapter: http://ddili.org/ders/d.en/logical_expressions.html Ali
Aug 03 2012
On Fri, 03 Aug 2012 19:30:25 +0200, Ali =C3=87ehreli <acehreli yahoo.com=wrote:On 08/03/2012 09:12 AM, simendsjo wrote: > What tutorials is this? The function is at the very end of the following chapter: http://ddili.org/ders/d.en/logical_expressions.html AliAh, ok. I still haven't read the chapters you've translated. Guess I should do this as you give away all your hard work for free. Do you mind me asking why you give away the translation for free btw? Yo= ur = selling the Turkish version, right?
Aug 03 2012
On 08/03/2012 10:58 AM, simendsjo wrote:Guess I should do this as you give away all your hard work for free.Thank you! I am making it better little by little every day.Do you mind me asking why you give away the translation for free btw?I think all of the following: This is my project for fun. I don't think the gains would make any difference anyway. It is not complete yet.Your selling the Turkish version, right?No, the Turkish version is free as well. :) Some people complain that there is no way of showing material appreciation. There are some thoughts and efforts by others to make it a paper book. Ali -- D Programming Language Tutorial: http://ddili.org/ders/d.en/index.html
Aug 03 2012
Ali Çehreli:No, the Turkish version is free as well. :) Some people complain that there is no way of showing material appreciation.Human psychology is not linear :-) Sometimes if you pay some (a little) money you think of it as more important. Sometimes if you have a way to give back to the author you feel better, and this makes you appreciate more the work. Money isn't just for money. Money has also effects on the mind of people :-) Bye, bearophile
Aug 03 2012
On Fri, Aug 3, 2012 at 8:59 PM, bearophile <bearophileHUGS lycos.com> wrote:Money isn't just for money. Money has also effects on the mind of people :-)Well money is nothing but effect in our mind... I know that, for quite some time now, whenever I find a book as a free pdf and I like it, I make a point to buy it anew, as a paper version, so as to transmit some money to the author. Going back to the current subject, we cannot help Ali any, without knowing Turkish. I *guess* some of us could start a 2nd level translation (japanese, russian, italian, german and french are likely possibilities).
Aug 03 2012
On 08/03/2012 12:17 PM, Philippe Sigaud wrote:some of us could start a 2nd level translation (japanese, russian, italian, german and french are likely possibilities).How timely! Crimson Sphere has just started the Korean translation: http://p-crimsonsphere.blogspot.kr/p/programming-in-d.html The "Hello World" chapter has some recognizable code: :) http://p-crimsonsphere.blogspot.kr/2012/08/hello-world.html Ali
Aug 03 2012
On Friday, 3 August 2012 at 19:25:21 UTC, Ali Çehreli wrote:On 08/03/2012 12:17 PM, Philippe Sigaud wrote:Ouch those pages just hurt my eyes. I had enough of the Korean language when I was in Korea. However it is a good thing it's getting translated and more coverage; I just hope most of the comments (and code) stay in english since it's kinda de-facto for most computer languages.some of us could start a 2nd level translation (japanese, russian, italian, german and french are likely possibilities).How timely! Crimson Sphere has just started the Korean translation: http://p-crimsonsphere.blogspot.kr/p/programming-in-d.html The "Hello World" chapter has some recognizable code: :) http://p-crimsonsphere.blogspot.kr/2012/08/hello-world.html
Aug 03 2012
Thanks for the help, but i tryed both solutions posted and still not working. :/ I get erros to compile the code posted by simendsjo. I try modify at my own, but without success. The code suggest by Timon Gehr compiles, but not work. Honestly speaking, i didn't have enough knowledge to understand the solutions offered (yet). What is the smallest way to use the "read_bool"? Besides, one version of that tutorial in portuguese would be great =D
Aug 03 2012
On Sat, 04 Aug 2012 03:01:31 +0200, Zeh <zecacu yahoo.com.br> wrote:Thanks for the help, but i tryed both solutions posted and still not working. :/ I get erros to compile the code posted by simendsjo. I try modify at my own, but without success. The code suggest by Timon Gehr compiles, but not work. Honestly speaking, i didn't have enough knowledge to understand the solutions offered (yet). What is the smallest way to use the "read_bool"? Besides, one version of that tutorial in portuguese would be great =DThis works: import std.stdio, std.string, std.conv; bool read_bool(in string message) { while(true) { write(message, " (false or true): "); string input; do { input = readln().chomp(); } while(!input.length); writeln("INPUT: '", input, "'"); try return input.to!bool(); catch {} } } void main() { write("How many are we? "); int personCount; readf(" %s", &personCount); write("How many bicycles are there? "); int bicycleCount; readf(" %s", &bicycleCount); write("What is the distance to the beach? "); int distance; readf(" %s", &distance); bool existsCar = read_bool("Is there a car? "); bool existsLicense = read_bool("Is there a driver license? "); } $ rdmd read_bool How many are we? 10 How many bicycles are there? 1 What is the distance to the beach? 2 Is there a car? (false or true): true Is there a driver license? (false or true): false
Aug 04 2012
On Saturday, 4 August 2012 at 08:35:36 UTC, simendsjo wrote:On Sat, 04 Aug 2012 03:01:31 +0200, Zeh <zecacu yahoo.com.br> wrote:Very interesting way to solve the problem (at least for a noobie like me ^^ ). Thanks for the help!Thanks for the help, but i tryed both solutions posted and still not working. :/ I get erros to compile the code posted by simendsjo. I try modify at my own, but without success. The code suggest by Timon Gehr compiles, but not work. Honestly speaking, i didn't have enough knowledge to understand the solutions offered (yet). What is the smallest way to use the "read_bool"? Besides, one version of that tutorial in portuguese would be great =DThis works: import std.stdio, std.string, std.conv; bool read_bool(in string message) { while(true) { write(message, " (false or true): "); string input; do { input = readln().chomp(); } while(!input.length); writeln("INPUT: '", input, "'"); try return input.to!bool(); catch {} } } void main() { write("How many are we? "); int personCount; readf(" %s", &personCount); write("How many bicycles are there? "); int bicycleCount; readf(" %s", &bicycleCount); write("What is the distance to the beach? "); int distance; readf(" %s", &distance); bool existsCar = read_bool("Is there a car? "); bool existsLicense = read_bool("Is there a driver license? "); } $ rdmd read_bool How many are we? 10 How many bicycles are there? 1 What is the distance to the beach? 2 Is there a car? (false or true): true Is there a driver license? (false or true): false
Aug 06 2012
On 08/04/2012 03:01 AM, Zeh wrote:Thanks for the help, but i tryed both solutions posted and still not working. :/ I get erros to compile the code posted by simendsjo. I try modify at my own, but without success. The code suggest by Timon Gehr compiles, but not work.Works for me. Maybe readln behaves differently on windows?
Aug 06 2012