1. While statement
- Posted by "sixs" <sixs at ida.net> Oct 25, 2003
- 357 views
This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C39AF0.3915E2B0 charset="iso-8859-1" Hello, I have this routine in two programs. one runs ok. the other gets an error message " type_check failure, line is-1" . I read in the documentation the short circuit could be involved. Is it involved and how does it work? jvandal ===== code=========== buffer = {} tries = 0 countlines = 0 clear_record() while 1 do line = gets(Handlers) if atom(line) then exit end if line[length(line)] = 32 buffer = buffer & line end while ------=_NextPart_000_0007_01C39AF0.3915E2B0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 8bit <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"> <META content="MSHTML 6.00.2800.1264" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT face=Arial size=2>Hello,</FONT></DIV> <DIV><FONT face=Arial size=2>I have this routine in two programs. one runs ok. the other gets an error message </FONT></DIV> <DIV><FONT face=Arial size=2>" type_check failure, line is-1"</FONT></DIV> <DIV><FONT face=Arial size=2>. I read in the documentation the short circuit could be involved. Is it involved and how does it work?</FONT></DIV> <DIV><FONT face=Arial size=2>jvandal</FONT></DIV> <DIV><FONT face=Arial size=2>===== code===========</FONT></DIV> <DIV><FONT face=Arial size=2> buffer = {}<BR> tries = 0<BR> countlines = 0<BR> clear_record()<BR> while 1 do<BR> line = gets(Handlers)<BR> if atom(line) then<BR> exit<BR> end if<BR> line[length(line)] = 32<BR> buffer = buffer & ------=_NextPart_000_0007_01C39AF0.3915E2B0--
2. Re: While statement
- Posted by "Juergen Luethje" <j.lue at gmx.de> Oct 25, 2003
- 340 views
sixs <sixs at ida.net> wrote: > Hello, > I have this routine in two programs. one runs ok. the other gets an > error message " type_check failure, line is-1". > I read in the documentation the short circuit could be involved. Is > it involved and how does it work? > jvandal > ===== code=========== > buffer = {} > tries = 0 > countlines = 0 > clear_record() > while 1 do > line = gets(Handlers) > if atom(line) then > exit > end if > line[length(line)] = 32 > buffer = buffer & line ^^^^^^--- You can write this shorter, BTW: buffer &= line > end while This piece of code isn't complete, the variable declarations are missing. I assume that 'line' was declared as sequence. But if you use 'line' this way (which is very common in Euphoria), it must be declared as object: If 'atom(line)' is TRUE, then 'line' holds -1, otherwise 'line' holds a sequence. This has nothing got to do with short-circuit evaluation. Regards, Juergen PS: Please don't send e-mail containing any HTML code to this list. Send plain text only. Thanks in advance. -- /"\ ASCII ribbon campain | |\ _,,,---,,_ \ / against HTML in | /,`.-'`' -. ;-;;,_ X e-mail and news, | |,4- ) )-,_..;\ ( `'-' / \ and unneeded MIME | '---''(_/--' `-'\_)
3. Re: While statement
- Posted by "Elliott S. de Andrade" <quantum_analyst at hotmail.com> Oct 25, 2003
- 350 views
I am assuming that line is declared as a sequence. gets() can return a sequence, which is the line, or -1 at the end of the file. In this case, it is returning -1, which cannot be assigned to a sequence. The solution is to declare line as an object, and then check if it is an atom, in which case, you would exit the loop. This is already done in the code, though. >From: sixs <sixs at ida.net> >Subject: While statement > >Hello, >I have this routine in two programs. one runs ok. the other gets an error >message >" type_check failure, line is-1" >. I read in the documentation the short circuit could be involved. Is it >involved and how does it work? >jvandal >===== code=========== > buffer = {} > tries = 0 > countlines = 0 > clear_record() > while 1 do > line = gets(Handlers) > if atom(line) then > exit > end if > line[length(line)] = 32 > buffer = buffer & line > end while >