<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
Khurram Khan:<br>
<blockquote>We believe that probably Clean user-guides are written
for people who have some previous knowledge of functional
programming (...)<br>
</blockquote>
<br>
Yes, I believe you are right. If you and your friends have problems
with the <b>understanding</b> of the IO issues, please, instead of
following the advice to read about some syntactic structures in
Clean, look into some general articles on functional programming,
purity and laziness, otherwise you will be constantly perplexed
(which is not so bad after all). The first thing to understand is
the IMPLICATIONS of the fact that a functional program does not
modify your data structures. <br>
<br>
<blockquote>we are also aware of the fact that by doing regular I/O
operations in functional programming might defeat the purpose of
writing a program in a functional language because it will then
resemble procedural programming style,(...)<br>
</blockquote>
<br>
This is not exact. Psychologically, perhaps (that's why in Haskell
we have the "do" block), but the functional IO is ... functional.
Even the global environment of your program has a functional avatar.
That's why you write:<br>
<br>
<font face="Courier New, Courier, monospace">(console, wrld) = stdio
wrld</font><br>
<br>
A file (here: the console) must be picked out of this environment
(the class: FileSystem, whose instance is the World, a possible
parameter of Start). But the referential transparency forbids you to
write, say : <font face="Courier New, Courier, monospace">console =
stdio(), or console=Stdio(world)</font> since making a link to
your file system changes the world. So, you create a new world, and
the "uniqueness" property of Clean ensures that you cannot reach the
previous one, it is "destroyed". So, you may reuse its name. Of
course "in reality" (btw., somebody knows what is "reality"?), this
reduces to the modification of the unique world exemplar.<br>
And the Ship Sails On.<br>
To read a line from the console, you write<br>
<br>
<font face="Courier New, Courier, monospace">(line, console) =
freadline console</font><br>
<br>
Since reading modifies the console, its "new instantiation" is
passed as a part of the result. If you want to write something, you
have to write<br>
<br>
<font face="Courier New, Courier, monospace">console = fwrites "And
the Ship Sails On\n" console</font><br>
<br>
and not just:<font face="Courier New, Courier, monospace"> fwrites
"something"</font>. This IS SIMPLE, you need only to keep in your
mind, that nothing is implicit, under the rug, and nothing is
"modified", rather "recreated".<br>
<br>
I believe that we could help you in a more efficient way, if you
pose some concrete questions, detailed, and "atomic".<br>
<br>
All the best<br>
<br>
Jerzy Karczmarczuk<br>
<br>
</body>
</html>