1. Two possible bugs in docs!
- Posted by Alan Tu <ATU5713 at COMPUSERVE.COM> Jun 19, 1998
- 711 views
1. This is an example program under the <seek> library routine in library.doc 1. = include file.e integer fn fn =3D open("mydata", "r") -- read and display first line of file 3 times: for i =3D 1 to 3 do puts(1, gets(fn)) = if seek(fn, 0) then puts(1, "rewind failed!\n") end if end for Or is this so that the loop will be performed three times? i is not mentioned anywhere within the for loop. 2. I've noticed this for a while. This is the <atom> routine (but if th= is is a bug, sequence and integer have the same bug). line =3D gets(0) if atom(line) then puts(SCREEN, "end of file\n") end if As I understand it, atom returns a 0 or 1. So if atom(line) then doesn't make sense. --Alan =
2. Re: Two possible bugs in docs!
- Posted by "Graeme." <hmi at POWERUP.COM.AU> Jun 20, 1998
- 725 views
At 08:54 AM 6/19/98 -0400, Alan wrote something. Despite the smoewhat off-topic heading for this message, I believe you are looking for clarification on 1) for loops and 2) using variable types as functions. 1) For loops >include file.e > >integer fn >fn = open("mydata", "r") --<opens file > >-- read and display first line of file 3 times: > >for i = 1 to 3 do --<declares i = 1 > puts(1, gets(fn)) --<gets and displays a line > if seek(fn, 0) then --<rewinds to offset 0 > puts(1, "rewind failed!\n") > end if >end for --<i=i+1 do it again until i=3 The variable i is declared when the for loop is declared and exists only inside the loop. This loop executes 3 times, so the code inside it is repeated 3 times. Try this: for number=0 to 9 do puts(1,"\nnumber :") print(1,number) end for 2) Using Types as Functions A type such as atom and integer or a user defined type can be called like a normal function to check a value against the defined limits of the type. > line = gets(0) > if atom(line) then > puts(SCREEN, "end of file\n") > end if the second line here means: If the variable "line" is an atom then... The gets() function will return a sequence unless it reaches the end of file, when it will return -1 (an atom), So if variable "line" is an atom and not a sequence then the end of the file has been reached. Graeme. ----------------------------------------------------
3. Re: Two possible bugs in docs!
- Posted by Daniel Berstein <daber at PAIR.COM> Jun 19, 1998
- 735 views
>2. I've noticed this for a while. This is the <atom> routine (but if this >is a bug, sequence and integer have the same bug). > line = gets(0) > if atom(line) then > puts(SCREEN, "end of file\n") > end if >As I understand it, atom returns a 0 or 1. So It's a wayt to test the data type of a variable. If atom(line) return 1 that means that lines IS an atom, else atom is a sequence. The same aplies to sequence... I'm not sure but I think you can also make use of your own created types for this purpose too. Regards, Daniel Berstein daber at pair.com