1. Bugs (my program, not yours)

Hello all -

Euphoria at times can be very confusing.

I have written a program and am now trying to make it run.  Here are some
segments from the program:

clear_screen
kb = open("CON","r")
puts(1,"Do you want hard copy? - y/n\n")
hcopy = getc(kb)
        [snip]
puts(1,"Specify  output... ")
outspec = getc(kb)
        [snip]
puts(1,"Number to be analyzed\n")
puts(1,"Enter 0 to end program\n")
x = gets(kb)
if x = 0 then
        abort(0)
end if
        [snip]

Yesterday (Tuesday) I kept getting error messages, "Euphoria expects 'this',
not 'that' with a line number.  In that line I found something that looked
irregular, and changed it to 'this'.  Then I tried to run the program again,
and I found an error message in the same line, "What is 'this'?"  That is,
Euphoria said it 'expected' something; I gave it what it 'expected' and it
didn't know what to do with it.  Euphoria found an 'error' in several
different kinds of 'this'.

I got around that somehow -- I don't know what I did, but the program
stopped generating such error messages.

Today (Wednesday) it's hanging up on 'gets'.  The sequence entered from the
keyboard ends when I press the 'return' key.  If I enter two numeric digits,
which should be a two-element sequence, and press the 'return' key, the
program hangs up again.  (The program should be able to handle any input up
to a billion or so, the top of Euphoria's normal range.)  'ex.err' says the
sequence has three elements, the third one being an extra 'line feed'
character (ASCII 10).  This happens repeatedly, even when I press the
'return' key *very* gently, to prevent its possible 'bouncing'.

The manual says x should be declared as an object, so that x can be either
an atom or a sequence.  I had x defined as an atom; I changed it to an
object.  That made the program hang up on the very next statement, 'if x = 0
then abort(0)'.  Euphoria says x must be an atom.

Like Hamlet, Euphoria apparently can't make up its mind.

What's going on here?

Wally Riley
wryly at mindspring.com

new topic     » topic index » view message » categorize

2. Re: Bugs (my program, not yours)

At 05:35 PM 6/3/98 -0400, you wrote:
>Hello all -
>
>Euphoria at times can be very confusing.
>
>I have written a program and am now trying to make it run.
>Here are some segments from the program:
>
include get.e -- added by Irv to enable the get()
object hcopy, outspec, x -- added by Irv to make it work for testing

clear_screen()

--kb = open("CON","r") -- you don't need this - device 0 IS the kbd!

puts(1,"Do you want hard copy? - y/n\n")

--hcopy = getc(kb) -- try instead getc(0)
hcopy = getc(0) -- this is easier

puts(1,"Specify  output... ")

--outspec = getc(kb)
outspec = getc(0) -- easier

puts(1,"Number to be analyzed\n")
puts(1,"Enter 0 to end program\n")

--x = gets(kb)   -- gets() gets a string, you want a number

x = get(0) -- use get() to get a number
if x[1] = GET_SUCCESS
  then x = x[2] -- checks for a good input
  else x = 0
end if
if x = 0 then
        abort(0)
end if

>
>Today (Wednesday) it's hanging up on 'gets'.  The sequence entered from the
>keyboard ends when I press the 'return' key.  If I enter two numeric digits,
>which should be a two-element sequence, and press the 'return' key, the
>program hangs up again.  (The program should be able to handle any input up
>to a billion or so, the top of Euphoria's normal range.)  'ex.err' says the
>sequence has three elements, the third one being an extra 'line feed'
>character (ASCII 10).
---------------------------------------------------------------
When you read in a string, you always get a 10 at the end.
Nothing to do with keyboard bounce.
---------------------------------------------------------------

 This happens repeatedly, even when I press the
>'return' key *very* gently, to prevent its possible 'bouncing'.
>
>The manual says x should be declared as an object, so that x can be either
>an atom or a sequence.  I had x defined as an atom; I changed it to an
>object.  That made the program hang up on the very next statement, 'if x = 0
>then abort(0)'.  Euphoria says x must be an atom.
>
>Like Hamlet, Euphoria apparently can't make up its mind.
>
>What's going on here?
-----------------------------------------------------------------
To quote from the manual:
  get - input from file fn, a human readable string of characters
        representing a Euphoria object. Convert the string into
        the numeric value of that object. s will be a 2-element
        sequence {error status,value}.....
------------------------------------------------------------------
It's just a matter of using the right command. Nothing to be
ashamed of here, this is the hardest part of Euphoria to
grasp, because it is different from what we're used to.
There is some sound reasoning behind the way RDS did this,
however.

I think.

Irv

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

3. Re: Bugs (my program, not yours)

>clear_screen
>kb = open("CON","r")
>puts(1,"Do you want hard copy? - y/n\n")
>hcopy = getc(kb)
>        [snip]
>puts(1,"Specify  output... ")
>outspec = getc(kb)
>        [snip]
>puts(1,"Number to be analyzed\n")
>puts(1,"Enter 0 to end program\n")
>x = gets(kb)
>if x = 0 then
>        abort(0)
>end if
>        [snip]

I think the erros you described are from the kb = open("CON","r") line.
Try something more like this:

clear_screen()
puts(1,"Do you want hard copy? - y/n\n")
hcopy = wait_key()      -- getc() isn't too reliable in my experience

----

puts(1,"Specify  output... ")
outspec = wait_key()

----

puts(1,"Number to be analyzed\n")
puts(1,"Enter 0 to end program\n")

x = get(0)                  -- Accept numeric input from STDIN
                            -- (the keyboard unless redirected)
if x[1] = GET_SUCCESS then
    if x[2] = 0 then
        abort(0)
    end if
end if


_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]

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

Search



Quick Links

User menu

Not signed in.

Misc Menu