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

Isaac Gouy igouy2 at yahoo.com
Fri May 6 22:10:04 MEST 2011


--- On Mon, 5/2/11, Khurram Khan <kkjcid at hotmail.com> wrote:

> Code Line 1   - why does we write (console,world) in the first 
> line of the code?

    # (console,world) = stdio world

As Peter Achten told you - "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."

The function stdio <see page 202> returns 2 values, those 2 values are returned in a tuple <see page 60>.

On line 1, the # begins a let-before local definition <see page 11>, and that local definition uses pattern matching <see page 8>.

On line 1, a pattern (a,b) will match a tuple with 2 elements, and define the new name "a" to be the value of the first element of the tuple, and define the new name "b" to be the value of the second element of the tuple.

On line 1, the pattern (console,world) will define the new name "console" to be the value of the first element of the tuple returned by the function stdio.

On line 1, the pattern (console,world) will define the new name "world" to be the value of the second element of the tuple returned by the function stdio.

We write (console,world) so we can refer to the read-write file value returned by the  stdio function using some name like "console" (the name doesn't have to be "console").



> Code Line 3 - is the line read from the console stored in "name"?

    # (name,console) = freadline console

The let-before local definition will pattern match a tuple with 2 elements, and define the new name "name" to be the value of the first element of the tuple, and define the new name "console" to be the value of the second element of the tuple.

The function freadline <see page 203> returns 2 values in a tuple, the first value will be a line read from the read-write file value named "console".

We have defined the new name "name" to be the line read from the read-write file value named "console".



> Code Line 3 - is "name" a variable or an list/array

    # (name,console) = freadline console

"name" is the name of a value.

This let-before local definition defines the new name "name" to be the value of the first element from the 2 element tuple returned by the function freadline - and that value will have the type *{#Char} <see page 203>



> Code Line 3 - can we perform any operation on it before printing
> it back to the console?

    # (name,console) = freadline console

We can create new values from the value defined by the name "name".

For example, we can create a new value that begins with a couple of line feeds and some other characters

    "\n\nHello " +++ name



> Code Line 6   - What does (ok,world) mean?

    # (ok,world) = fclose console world

The let-before local definition will pattern match a tuple with 2 elements, and define the name "ok" to be the value of the first element of the tuple, and define the name "world" to be the value of the second element of the tuple.

The function fclose <see page 202> returns 2 values in a tuple, the first value will be a boolean output parameter reporting the success or failure of closing the read-write file value named "console".

We have defined the new name "ok" to be the boolean value reporting the success or failure of closing the read-write file value named "console", and the new name "world" to be the external world after applying the function fclose.



> prints out the value 65536 on the console at the end, 
> before terminating. What does this value represent and why
> is it output?

    Start :: *World -> *World

65536 is the value returned by "Start", it represents the external world.

If you are using the CleanIDE then look for "Project Options..." in the Project menu, click the "Application" radio button, look for the "Console" radio buttons and click either "No Return Type" or "No Console" - rebuild and rerun the project.


More information about the clean-list mailing list