1. While statement

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&nbsp; could&nbsp; be involved. Is it&nbsp; 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>&nbsp;buffer = {}<BR>&nbsp;tries = 
0<BR>&nbsp;countlines = 0<BR>&nbsp;clear_record()<BR>&nbsp;while 1 
do<BR>&nbsp;&nbsp;line = gets(Handlers)<BR>&nbsp;&nbsp;if atom(line) 
then<BR>&nbsp;&nbsp;&nbsp;exit<BR>&nbsp;&nbsp;end 
if<BR>&nbsp;&nbsp;line[length(line)] = 32<BR>&nbsp;&nbsp;buffer = buffer &amp; 

------=_NextPart_000_0007_01C39AF0.3915E2B0--

new topic     » topic index » view message » categorize

2. Re: While statement

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     |  '---''(_/--'  `-'\_)

new topic     » goto parent     » topic index » view message » categorize

3. Re: While statement

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
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu