1. Re: Discard
Ad wrote:
...
>if my_func() then
>end if
>I've seen this used with graphics_mode(), text_rows() etc. etc.
>Does this explanation make things clear?
Ain't it a little bit awkward to do it this way? Why Euphoria doesn't =
simply allow function call outside an expression? The substitute using =
"if" is very unclear since I (the reader) don't know if the programmer =
doesn't forget to write a code inside "if" body. Maybe this will be =
clearer:
if my_func() then
-- discard
end if
Anyway Ralf's approach using "discard" is more clearer (but, for me, =
still verbose):
discard =3D my_func()
It could be simply implemented in the current version of Euphoria by (as =
Einar wrote):
global object discard
An unpleasant side-effect of this is that the return value is not really =
discarded since it is placed in the global variable.
The "if" substitute hasn't this side-effect; on the other hand it is =
time-consuming - it tests the return value every time (Can I discard =
sequences this way?!).
>But why should you use functions when you are not interested in the =
result?
>In that case you've got procedures!
Since you cannot return from a procedure any additional information =
(like error code etc.)! In some cases, as you can see in real code =
(graphics_mode() etc.), you are interested in the result, in the other =
ones you are not.
From the functional point of view, functions cannot have side-effects =
(Euphoria breaks this rule) - so it's logical not to use function if I =
don't want it's value (the return value is the only function's =
communication channel to the ouside world). In Euphoria, where functions =
can have side-effects, is a procedure only the special kind of function =
with no return value (or vice versa?!). Since the procedure is in fact a =
function, it can't return a value (except its side-effects) by no other =
means than by "return" statement - but it lacks this feature!
If we want to have an consistent language we have to have these code =
catogories:
functions
- no side-effects (cannot change global value, cannot call procedure)
- must return an value (even void)
procedure
- side-effects allowed
- the return value optional
and function calls are not permitted "alone".
This, unfortunately, doesn't correspond with current Euphoria language, =
so I should very appreciate if Euphoria allows function call as a =
statement:
my_func()
The implementation could be simple - the interpreter knows that my_func =
is function so it simply discards the return value.
Tom
=00=00