1. Unusual EU Problem (must see)

Hello again,

Either i posted this already and it didnt make it to the 
unique Topica, or i couldnt sign in to post it, but in any case...


Very unexpected behavior when i accidentally used:

function FunctionAAA()
  atom param
  param=1
  return FunctionBBB(param)
end function

Looks normal, doesnt it?
Well, you would think so anyway...but

FunctionBBB() never executes!

Why not?

procedure FunctionBBB(atom param)
  ?param
end procedure


FunctionBBB() was written as a procedure, not a function,
(in another file in some remote corner of the desktop)
and when called via
    "return FunctionBBB(param)"
nothing prints out, because the procedure never gets called.
You dont realize that (updating an older program) 
a value cant be returned from a procedure, because it
was once a function and that was remembered instead,
but no real error comes up as usual in Euphoria.
<<Now why cant that happen with an invalid sequence arg?>> smile

Shouldnt there be an error message or something?
It's not that important once you know it exists,
but i spent about 30 minutes trying to figure out why 
FunctionBBB() wouldnt execute because i figured calling
a function/procedure was more basic to the language then that.
What i would have expected is to have it call the function,
but when it returns some error message like
"cant return a value from a procedure in file xxx line nnn"
or something to that effect smile



Take care for now,
Al

new topic     » topic index » view message » categorize

2. Re: Unusual EU Problem (must see)

On Thu, 14 Aug 2003 06:39:51 +0000, Al Getz <Xaxo at aol.com> wrote:

>Very unexpected behavior when i accidentally used:
>
>function FunctionAAA()
>  atom param
>  param=3D1
>  return FunctionBBB(param)
>end function
>
<snip>
>procedure FunctionBBB(atom param)
>  ?param
>end procedure

>but no real error comes up as usual in Euphoria.
well, I got Syntax error - expected to see an expression, not a
procedure. If I change FunctionAAA() to a procedure, which is what I
think you meant, there is no error or warning.

The correct warning to report in this case is unreachable code, or
"will never be executed".

While I'm here, probably my biggest bugbear:

The warning system in Euphoria is so OTT that virtually every program
ever written has without warning as the top line, something which
should only be done for release code (possibly if the proposed shroud
-fullsource option is implemented, which creates a single releaseable
source with all the comments etc left intact). A warning system is not
much use if most people turn it off, during development!


=46irstly, I'd like warnings to be classified, eg:

unused parameters
unused parameters on routines referenced by routine_id
unused variables
unused constants
unused constants created with side effects
short circuit warnings
unreachable code

I think that in much the same way you can have with/without trace
covering sections of code, but still need the trace() command, you
need with/without warning and a warning() command, to set the classes
of warnings you are (locally) interested in.

My code ends up littered with things like:
	procedure onClickButton(int self, int event, seq params)
		if self or event or length(params) end if -- suppress warnings

	constant menu=3Dcreate(Menu,"File",0,...)
	crud=3Dmenu	-- suppress warnings

	-- if isVisible(x) or isVisible(y) then
	flag=3DisVisible(x) or isVisible(y)
	if flag then

	(And no Rob, you are not allowed to add that extremely annoying=20
	warning to the second case to make them consistent blink


There is definitely something wrong with
without warning
	constant A=3D1
with warning
having no effect; whether or not you get a warning about A and all
other unused constants depends solely on whether warning is in force
at the end of the file, which is counter-intuitive. Maybe I'm being
simple-minded, but somewhere in the above it must set a flag to
indicate A has never been referenced to True, should be False.


Also, if the program dies with an error, it should definitely prompt
before dumping out the warnings and scrolling the error message off
the screen.


My other vote would be for a win32 style debugger, with display of
subscripts and slices.

Pete

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

3. Re: Unusual EU Problem (must see)

On Thu, 14 Aug 2003 12:50:18 +0100, Pete Lomax
<petelomax at blueyonder.co.uk> wrote:

Sorry, replying to my own post:
<snip>
>The correct warning to report in this case is unreachable code, or
>"will never be executed".
Actually, it does exactly that, "warning - statement after return will
never be executed" is correctly reported.

What I did, as I often do, is paste the code at the top of an existing
file and insert abort(0). That always gives me the warning "statement
after abort() will never be executed", and my brain didn't register
the first warning because I was already expecting to get an almost
identically worded warning.

I suppose I should add that to my list as another class of warnings
(statement after abort) which I may not want to be told about.

I think I'm going to claim this as a good example of the little mental
hiccups the warning system causes me all day, every day.

Pete

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

4. Re: Unusual EU Problem (must see)

Al wrote:

<snip>

> function FunctionAAA()
>   atom param
>   param=1
>   return FunctionBBB(param)
> end function
>
> Looks normal, doesnt it?
> Well, you would think so anyway...but
>
> FunctionBBB() never executes!
>
> Why not?
>
> procedure FunctionBBB(atom param)
>   ?param
> end procedure

<snip>

> but no real error comes up as usual in Euphoria.
> <<Now why cant that happen with an invalid sequence arg?>> smile
>
> Shouldnt there be an error message or something?

I get the error message:
   FunctionBBB has not been declared
     return FunctionBBB(param)
                      ^

After changing the order of both routines, so that I have ...

----------=----------=----------=----------=---------
procedure FunctionBBB(atom param)
   ?param
end procedure

function FunctionAAA()
   atom param
   param=1
   return FunctionBBB(param)
end function
----------=----------=----------=----------=---------

... I get the error message:
   Syntax error - expected to see an expression, not a procedure
     return FunctionBBB(param)
                      ^
as expected.

If you meant the following, though (as Pete also supposed) ...

----------=----------=----------=----------=---------
procedure FunctionBBB(atom param)
   ?param
end procedure

procedure FunctionAAA()
   atom param
   param=1
   return FunctionBBB(param)
end procedure
----------=----------=----------=----------=---------

... I get a warning:
   Unusual EU Problem.exw:8 - statement after return will never
   be executed

So Eu raises a warning, not an error here. Maybe you didn't get the
warning, because you used "without warning" in your program?

BTW: I tested this, using the Windows interpreter 2.4.

<snip>

Best regards,
   Juergen

-- 
 /"\  ASCII ribbon campain  | "Everything should be made as simple
 \ /  against HTML in       |  as possible, but not simpler."
  X   e-mail and news,      |
 / \  and unneeded MIME     | [Albert Einstein]

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

5. Re: Unusual EU Problem (must see)

Al wrote:

> Juergen Luethje wrote:
>>
>>
>> Al wrote:
>>
>> <snip>
>>
>>> function FunctionAAA()
>>>   atom param
>>>   param=1
>>>   return FunctionBBB(param)
>>> end function
>>>
>>> Looks normal, doesnt it?
>>> Well, you would think so anyway...but
>>>
>>> FunctionBBB() never executes!
>>>
>>> Why not?
>>>
>>> procedure FunctionBBB(atom param)
>>>   ?param
>>> end procedure
>>
>> <snip>
>>
>>> but no real error comes up as usual in Euphoria.
>>> <<Now why cant that happen with an invalid sequence arg?>> smile
>>>
>>> Shouldnt there be an error message or something?

<big snip>

> Yes, the function (procedure) gets declared beforehand of course.
> The strange thing happens when you try to call a procedure with
> "return ProcedureName()"
> as the procedure never gets called, and you dont even see that
> warning you were talking about until you stop debugging
> (from trace mode).

You did not mention before that you were using trace mode.

With your both routines in the intended order, and using trace mode,
we have:

----------=----------=----------=----------=---------
with trace
trace(1)

procedure FunctionBBB(atom param)
   ?param
end procedure

function FunctionAAA()
   atom param
   param=1
   return FunctionBBB(param)
end function

FunctionAAA()
----------=----------=----------=----------=---------


> Now i know what to look for, but before i found that i didnt
> know what was causing the problem, so i thought i would
> mention it so it could raise an error in 2.5 perhaps.

Running my code above, exw.exe 2.4 says:
   Syntax error - expected to see an expression, not a procedure
      return FunctionBBB(param)
                       ^

So there _is_ an error message.


You wrote:
| try to call a procedure with
| "return ProcedureName()"
| as the procedure never gets called

This is neither true nor false, but it depends.
If the statement "return ProcedureName()" is inside a _function_ (as in
your code), then Eu _does_ try to call "ProcedureName()", and correctly
raises an error, because the correct syntax is "return <expression>",
and the name of a procedure is not a valid expression.


If "return ProcedureName()" is inside a _procedure_, then these are
actually _two_ statements. We better write:
   return
   ProcedureName()

That's the same for Euphoria, but I think humans so can better see the
difference between this and "return <expression>", as used in functions.


Therefore again I guess -- as Pete and me did before, but you neither
confirmed nor contradicted -- that the code you posted is _not_ the
code, that you used in your program.

_If_ you actually used "procedure FunctionAAA()" instead of
"function FunctionAAA()" then I see what you mean.

AFAIK warnings are _never_ shown until the end of the program (CMIIW).
Your point is, that inside a procedure
   return
   ProcedureName()
should raise an error rather than a warning, right?

Best regards,
   Juergen

-- 
 /"\  ASCII ribbon campain  | "Everything should be made as simple
 \ /  against HTML in       |  as possible, but not simpler."
  X   e-mail and news,      |
 / \  and unneeded MIME     | [Albert Einstein]

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

6. Re: Unusual EU Problem (must see)

Al Getz wrote:

> Juergen Luethje wrote:
>>
>>
>> Al wrote:
>>
>>> Juergen Luethje wrote:
>>>>
>>>>
>>>> Al wrote:
>>>>
>>>> <snip>
>>>>
>>>>> function FunctionAAA()
>>>>>   atom param
>>>>>   param=1
>>>>>   return FunctionBBB(param)
>>>>> end function
>>>>>
>>>>> Looks normal, doesnt it?
>>>>> Well, you would think so anyway...but
>>>>>
>>>>> FunctionBBB() never executes!
>>>>>
>>>>> Why not?
>>>>>
>>>>> procedure FunctionBBB(atom param)
>>>>>   ?param
>>>>> end procedure
>>>>
>>>> <snip>
>>>>
>>>>> but no real error comes up as usual in Euphoria.
>>>>> <<Now why cant that happen with an invalid sequence arg?>> smile
>>>>>
>>>>> Shouldnt there be an error message or something?
>>
>> <big snip>
>>
>>> Yes, the function (procedure) gets declared beforehand of course.
>>> The strange thing happens when you try to call a procedure with
>>> "return ProcedureName()"
>>> as the procedure never gets called, and you dont even see that
>>> warning you were talking about until you stop debugging
>>> (from trace mode).
>>
>> You did not mention before that you were using trace mode.
>>
>> With your both routines in the intended order, and using trace mode,
>> we have:
>>
>> ----------=----------=----------=----------=---------
>> with trace
>> trace(1)
>>
>> procedure FunctionBBB(atom param)
>>    ?param
>> end procedure
>>
>> function FunctionAAA()
>>    atom param
>>    param=1
>>    return FunctionBBB(param)
>> end function
>>
>> FunctionAAA()
>> ----------=----------=----------=----------=---------
>>
>>
>>> Now i know what to look for, but before i found that i didnt
>>> know what was causing the problem, so i thought i would
>>> mention it so it could raise an error in 2.5 perhaps.
>>
>> Running my code above, exw.exe 2.4 says:
>>    Syntax error - expected to see an expression, not a procedure
>>       return FunctionBBB(param)
>>                        ^
>>
>> So there _is_ an error message.
>>
>>
>> You wrote:
>>| try to call a procedure with
>>| "return ProcedureName()"
>>| as the procedure never gets called
>>
>> This is neither true nor false, but it depends.
>> If the statement "return ProcedureName()" is inside a _function_ (as in
>> your code), then Eu _does_ try to call "ProcedureName()", and correctly
>> raises an error, because the correct syntax is "return <expression>",
>> and the name of a procedure is not a valid expression.
>>
>>
>> If "return ProcedureName()" is inside a _procedure_, then these are
>> actually _two_ statements. We better write:
>>    return
>>    ProcedureName()
>>
>> That's the same for Euphoria, but I think humans so can better see the
>> difference between this and "return <expression>", as used in functions.
>>
<snip>

In my last posts, I tried to clarify, what you actually mean.
Now, instead of answering my questions, you say I shall forget about the
last posts. And again you post some text, that is far from clear.

You are trying to tell us something about some code. It doesn't help,
to describe an Eu program with normsal human language.
Why don't you simply post that code (or better a stripped down version
that is logically equivalent, as far as the effect is concernd, that you
want to show)?

> Write a short program with at least one procedure in it
> and try to call it while you are tracing the program
> with a line like this:
>
> "return ProcedureName()"
>
> without the quotes.

___Where___ shall I write such a line? Euphoria will behave different,
whether I write such a line inside a function, or inside a procedure.
Did you actually read what I wrote??

Well, I don't care any more, I'll give up. sad

<snip>

Regards,
   Juergen

-- 
 /"\  ASCII ribbon campain  |
 \ /  against HTML in       |  This message has been ROT-13 encrypted
  X   e-mail and news,      |  twice for higher security.
 / \  and unneeded MIME     |

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

7. Re: Unusual EU Problem (must see)

On Sat, 16 Aug 2003 19:18:12 +0000, Al Getz <Xaxo at aol.com> wrote:

>with trace
>trace(1)
>
>procedure DoThis()
>  ?1
>end procedure
>
>procedure DoThisToo()
>  ?2
>  return DoThis()
>end procedure
>
>DoThisToo()
>-----------------------------------
>
>--Note that in line 10 when DoThis() is called
Ah! There is your misunderstanding.
Line 10 is not executed.
The "return" on line 10 is executed, not "return DoThis()".
OK, it is quite confusing, a good example of bad coding style making a
program virtually unreadable, and also a good reason to avoid the evil
"without warning" and/or ignore those pesky helpful hints Eu tries to
give you once the program finishes blink

Your example is the opposite of:

?4

+

5-3

*
10

which prints -21 (think about it, not 4 and an error, and not 60 or
perhaps even 24, which are other ways a human might read it...)

and your example is a bit similar to:

function max(integer a, integer b)
	if a>b then return a else return b end if
end function

Maybe someone should write a style checker for Eu code.
HTH

Pete

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

Search



Quick Links

User menu

Not signed in.

Misc Menu