Dear Khurram,

You can find more information about "cin" and "cout" like operations in section 5.1.1. To 
get access to console I/O, you need to open the "stdio" file. Consider the example on page 116, 
hello1.

First, to get access at all to the external environment of any program, the main function, that is called Start in Clean, receives a special argument of type *World. World is an opaque type. The * in front of it indicates that it is special: it is a so-called unique value. Unique means that a value can only be used in a sensible way if it is not shared, i.e. there exists at any time only one reference to that value. Any value that satisfies this criterion can be updated in place, as you are used to in C(++). This is the only exception in a pure functional language to update values in place. The World is unique because the external environment of a program is unique: any update in place on the external environment can be observed by other entities in the external world.

Second, the function stdio takes the external world and returns a read-write file value that is connected with your console, and a modified external world. You can use the function fwrites to write any string value to this read-write file, and thus the console. Note how this function updates the read-write file and hence returns a modified value. For hygienic reasons, every time you are done with a file (be it for reading, writing, or console) you close it with the fclose function. This updates the external environment such that the read-write console file is available for other functions as well. Finally, for hygienic reasons, the modified external environment value of type World must be returned by the Start function.

Third, the hello2 example below the hello1 example shows how to read string input. The function freadline reads an entire line of input from the console, including the terminating newline character. For further processing Clean provides a number of conversions functions to turn a string value into an Integer (toInt) and a Real (toReal). Conversely, the following idiom makes it easy to write values to a write or read-write file. For instance:

     file <<< 42 <<< " is eqal to " <<< 84.0 / 2.0 <<< '\n'

which writes an integer, string, real, and character value subsequently to file.

I hope this helps. For further question, please use the clean-list mailing list 
(clean-list AT cs DOT ru DOT nl). I am hard to reach the coming week due to 
holidays.

Regards,
Peter

On 4/29/2011 6:50 PM, Khurram Khan wrote:
Dear Peter,

Thanks for your quick reply. Yes, I had a look at the link and it does provide very useful information about Clean programming. However, I was unable to understand how input/output operations are done in Clean. For example if i want to input some data and then want the software to do some operations on it, how would that be done? Is there a way to do that in Clean, just like in C++ we can use "cin" and "cout" commands to perform those functions to print or read data to/from the console.

Best regards
Khurram




--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Date: Fri, 29 Apr 2011 17:31:33 +0200
From: [email protected]
To: [email protected]
CC: [email protected]
Subject: Re: Books/learning material on Clean for a beginner?

Dear Khurram,

Thank you for your interest in Clean and functional programming. This style of 
programming is indeed very different when you're exposed to C and C++ only.

Have you found the following book on the Clean wiki?

http://wiki.clean.cs.ru.nl/Functional_Programming_in_Clean

This is the same text that we use to teach our students Clean and functional 
programming.

Best regards,
Peter

On 4/29/2011 5:16 PM, Khurram Khan wrote:

    Hi

    I am a college student, who is interested in learning functional 
programming and Clean in particular regarding an academic project. I do not 
have any previous experience of functional
    programming and I am finding it very difficult to understand Clean. I have 
many years of programming experience with C and C++, but it seems to be totally 
different when it comes to programming
    in Clean. Moreover I am not able to find any books on Clean which provide a 
good introduction to beginners, such as creating basic programs.

    Can you please suggest what approach should I have in order to learn Clean 
effectively? I've read some of the documentation provided on your website but I 
find it difficult to understand, as I
    think it doesnt provide enough explanation for a begineer (functional 
programmer)

    Kind regards
    Khurram

_______________________________________________
clean-list mailing list
[email protected]
http://mailman.science.ru.nl/mailman/listinfo/clean-list

Reply via email to