1. booleans

Here is an example of the trouble i have with Eu's comparisons:

result = ""
-- i had to give it "", or else "&=" gives an error getlost
-- code doing things, but not changing result

if ( result = "" ) then
if equal(result,"") then

both "if" statements give the same result:

variable result has not been assigned a value 

So what i want to know is: how do i find out if result is still empty? length()
is the only
way? Ack!

Kat

new topic     » topic index » view message » categorize

2. Re: booleans

On 4 Feb 2001, at 23:52, Kat wrote:

> Here is an example of the trouble i have with Eu's comparisons:
> 
> result = ""
> -- i had to give it "", or else "&=" gives an error getlost
> -- code doing things, but not changing result
> 
> if ( result = "" ) then
> if equal(result,"") then
> 
> both "if" statements give the same result:
> 
> variable result has not been assigned a value 
> 
> So what i want to know is: how do i find out if result is still empty?
> length() is the
> only way? Ack!

No, because length() gives the same error, result has no value!

Kat

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

3. Re: booleans

Kat wrote:

> result = ""
> if ( result = "" ) then
> if equal(result,"") then

If I write:

   object result
   result = ""
   if equal( result, "" ) then
       puts( 1, "empty" )
   else
       puts( 1, "not empty" )
   end if

it will run correctly. It's only if I comment out the line:

   -- result = ""

that I get an error. I can only assume that, in fact, result is not getting
assigned before the if statement, just like Euphoria is telling you.

I believe the larger question (how can I tell that a variable is unassigned)
is: you can't without crashing your code. One option would be to initialize
your variables to a different data type. For example, if you were dealing
with strings, you could write:

   object string
   string = -1
   ...
   if equal( string, -1 ) then
      puts( 1, "string is not initialized.\n" )
      abort(0)
   end if

For example, see gets() and dir().

These sorts of things are prone to causing errors, though. For example, I
always expect dir() to return an empty sequence instead of -1. And I never
catch that kind of bug until after the code has been released...

-- David Cuny

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

4. Re: booleans

Dear Kat:

> No, because length() gives the same error,
> result has no value!

Try please:

---------
sequence s
s={}
? length(s)

sequence t
t=""
? length(t)
---------


Regards,
Igor Kachan

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

5. Re: booleans

Dear Igor,

Igor Kachan wrote:
> 
> Dear Kat:
> 
> > No, because length() gives the same error,
> > result has no value!
> 
> Try please:
> 
> ---------
> sequence s
> s={}
> ? length(s)
> 
> sequence t
> t=""
> ? length(t)
> ---------
> ...

please try this:

---------
sequence s
s={}
? t
? length(s)
---------

Have a nice day, Rold

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

6. Re: booleans

Rolf Schroeder wrote:

nonsense, forget it, please!

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

7. Re: booleans

On 5 Feb 2001, at 1:09, Igor Kachan wrote:

> Dear Kat:
> 
> > No, because length() gives the same error,
> > result has no value!
> 
> Try please:
> 
> ---------
> sequence s
> s={}
> ? length(s)
> 
> sequence t
> t=""
> ? length(t)
> ---------

Ok, i declared 
result = {}
and with 
result = ""
and both died at the same place
if ( length(result) = 0 )
with the same error:
variable result has not been assigned a value 

ex.err has this:
 result = <no value>

Changing result from a sequence to an object didn't help. 

Neither did
if ( result = "" ) then <-- same error
neither did:
if equal(result,"") then <-- same error
neither did:
if compare(result,"") then <-- same error
neither did:
if match(result,"") then <-- same error

I even checked ex.err trace to verify i had saved the new lines after editing
them, to
make sure i was running the code i thought i was!

Robert, how do i do this?

result = "" -- only so the &= operator will work getlost
-- misc code that doesn't change result in this pass
--now how to tell if result is still "" or not?

Kat,
wringing her paws,
recoding with:
result = "-1" -- cause it will never be this, i hope
-- code modified to not use the &= , 
-- but instead to replace result if "-1"
-- and &= if not "-1"
-- then check if result = "-1"

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

8. Re: booleans

Kat wrote:

> Ok, i declared
> result = {}
> and with
> result = ""
> and both died at the same place
> if ( length(result) = 0 )
> with the same error:
> variable result has not been assigned a value
>
> ex.err has this:
>  result = <no value>

To point out the obvious: if ex.err says that result hasn't been assigned a
value, then it hasn't been. There are a couple possibilities:

1. The initialization is in a conditional statement that gets bypassed.

2. The execution order isn't what you expect, and you reach the test before
the initialization.

3. You are initializing a local variable and testing a global, or vice
versa. (I'm guessing this is what's happening to you).

I'd stick a trace before the initialization and test, to make sure they were
executing in order. If that doesn't work, reduce the code to a minimum and
post it - I'd love to see it.

-- David Cuny

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

9. Re: booleans

Dear Kat:

> Changing result from a sequence to an object didn't help. 

Post me please fragment of your
booleans program that gives error.

Regards,
Igor Kachan
kinz at peterlink.ru

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

10. Re: booleans

OK Kat,

try this; new file, on it's own.

-----<start>-------
sequence s
s=""
?s
?length(s)
-------<end>----------

outputs:

{}
0



As you can see, the s="" line _does_ initialize
the sequence, therefore there _must_ be an error 
somewhere in your code. Unless this is a version 
specific bug (I use 2.1) but I would be very
surprised if that section of the interpreter
has been touched in the last few releases.


Here's what I'd be looking for.

Do you have, perhaps two vars, one called "Result"
and one called "result"

Do you have a local called "result" that you are,
initializing and a private also called "result" that
you are not? (or vice versa)

Is the result="" DEFINATELY being executed?
try putting this immediately berfore the line:

if message_box("Initializing result","Debug",0) then end if
(or under DOS)
puts(1,"\n\nINITIALIZING result") if wait_key() then end if

Then you will be SURE the line is executed as the program 
will halt and display a message.

BTW: (result="") will always fail as logic tests must 
equate to an integer. Sequences can be compared using the '='
operator but they must be the same length ("MAN"="CAN") 
equates to {0,1,1} 


Graeme

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

11. Re: booleans

Hi Kat,
I do this sort of thing all the time, and it works just fine.
eg.
   sequence result result = ""

Of course, it would be neater if one could do ...

  sequence result = ""

but RDS does not believe in that particular 'heresy'.

One possible problem that you might have is this type of coding...

  sequence result
  result = ""

  procedure xyz()
     sequence result

     if length(result) = 0 then ...

  end procedure

here we have the identifier 'result' defined twice, once as a file-scoped
variable and another as a procedure-scoped variable. The procedure one is
being tested but the file one is being initialised.

------
Derek Parnell
Melbourne, Australia
(Vote [1] The Cheshire Cat for Internet Mascot)

----- Original Message -----
From: "Kat" <gertie at PELL.NET>
To: <EUforum at topica.com>
Sent: Tuesday, February 06, 2001 6:39 PM
Subject: Re: booleans


> On 5 Feb 2001, at 1:09, Igor Kachan wrote:
>
> > Dear Kat:
> >
> > > No, because length() gives the same error,
> > > result has no value!
> >
> > Try please:
> >
> > ---------
> > sequence s
> > s={}
> > ? length(s)
> >
> > sequence t
> > t=""
> > ? length(t)
> > ---------
>
> Ok, i declared
> result = {}
> and with
> result = ""
> and both died at the same place
> if ( length(result) = 0 )
> with the same error:
> variable result has not been assigned a value
>
> ex.err has this:
>  result = <no value>
>
> Changing result from a sequence to an object didn't help.
>
> Neither did
> if ( result = "" ) then <-- same error
> neither did:
> if equal(result,"") then <-- same error
> neither did:
> if compare(result,"") then <-- same error
> neither did:
> if match(result,"") then <-- same error
>
> I even checked ex.err trace to verify i had saved the new lines after
editing them, to
> make sure i was running the code i thought i was!
>
> Robert, how do i do this?
>
> result = "" -- only so the &= operator will work getlost
> -- misc code that doesn't change result in this pass
> --now how to tell if result is still "" or not?
>
> Kat,
> wringing her paws,
> recoding with:
> result = "-1" -- cause it will never be this, i hope
> -- code modified to not use the &= ,
> -- but instead to replace result if "-1"
> -- and &= if not "-1"
> -- then check if result = "-1"
>

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

Search



Quick Links

User menu

Not signed in.

Misc Menu