August 03, 2012
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!

August 03, 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");
    }
}


August 03, 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

August 03, 2012
On Fri, 03 Aug 2012 08:05:46 +0200, Ali Çehreli <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 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
>

What 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 the input
    while(true) { // loop until we get true/false
        write(message, " (false or true): "); // avoid concat allocation
        string input;
        do { // no need to check input on entering
            input = 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 = read_bool("Do it?");
    writeln(input ? "Hell yeah, do it!" : "No way!");
}
August 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

August 03, 2012
On Fri, 03 Aug 2012 19:30:25 +0200, Ali Çehreli <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
>
> Ali
>

Ah, 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? Your selling the Turkish version, right?
August 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

August 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
August 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).
August 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

« First   ‹ Prev
1 2
Top | Discussion index | About this forum | D home