[clean-list] Help Please: Beginner to Clean.. Console I/O

Khurram Khan kkjcid at hotmail.com
Wed May 4 15:46:31 MEST 2011






Many thanks for your reply. I've read through let-before section and it has developed a bit more understanding now on what is happening the "hello1" example. I should've been more specific with my question last time. Actually me and a couple of my classmates are working together to learn Clean and finding it very hard to understand I/O operations in Clean. We believe that probably Clean user-guides are written for people who have some previous knowledge of functional programming, but we are very keen to learn the language and we have up til now found it very interesting, specially the fact that it, in many ways, resembles to how you write functions in pure mathematical sense. 

However, as we are so much used to C/C++, we were thinking that Clean must also have some basic way of doing simple I/O operations, like we have "cout" and "cin" in C++, but we are unable to develop that understanding from examples "hello1" and "hello2". We have also looked at some code provided with Clean IDE software as examples, but those examples are also on intermediate/advanced level, compared to where we are at the moment. 

We were thinking if its possible for you to translate this simple code of C++ in Clean and provide some comments on it as well. We are certain that it will help solve I/O dilemma for us, and we are deeply thankful for the time you take out to help us.

/* Just a simple program performing input/output to user console and performing a calculation*/

void main ()
{
      double FirstNumber=0.0;
      double SecondNumber=0.0;
      double ThirdNumber =0.0;
      double Result =0.0;

      cout << "This program will accept three integer numbers and find their average value\n\n";
    
      cout << "Enter First Number: ";
      cin >> FirstNumber;

      cout << "\nEnter Second Number: ";
      cin >> SecondNumber;

      cout << "\nEnter Third Number: ";
      cin >> ThirdNumber;

      Result = (FirstNumber+SecondNumber+ThirdNumber)/3;

      cout << "\nThe result is : " << Result << "\n\n";

      system("pause");
}



Kind regards
Khurram

> Subject: Re: [clean-list] Help Please: Beginner to Clean.. Console I/O
> From: rthappe at web.de
> Date: Wed, 4 May 2011 00:23:25 +0200
> CC: kkjcid at hotmail.com
> To: clean-list at cs.ru.nl
> 
> Khurram Khan wrote:
> 
> > Now if we consider the example "hello1" from the CleanBook1, chapter 5.1.1
> ...
> >     # (console,world) = stdio world
> ...
> > but I find it hard to understand the meaning of each line of the code.
> 
> Your questions are not specific to I/O.  The code snippet quoted above binds the tuple (CONSOLE,WORLD) to the value of STDIO WORLD, or more precisely, the value of STDIO WORLD is a two-part tuple (a pair), and the expression binds the variable CONSOLE to its first part, the variable WORLD to its second part, reusing by the way the variable name WORLD already bound in the outer scope.
> [The underscore in (_,CONSOLE) is a don't-care variable: you don't care for its value.]
> 
> I'd suggest you read the section on let-before expressions in the language report and come back with your questions.
> 
> 	http://wiki.clean.cs.ru.nl/Documentation
> 
> 
> Best, rt
> 

 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/clean-list/attachments/20110504/65f224af/attachment.html>


More information about the clean-list mailing list