Re: Coming From QBasic

new topic     » goto parent     » topic index » view thread      » older message » newer message

Lynn Kilroy wrote:
> 
> How would I know something was declared at the right time in the include=
> 
> file?  

If it is declared before it is used.

> I've looked in those files, and the subroutines, AKA procedures, wer=
> e
> in apparently random order.  What's more, the code doesn't look as neat as=
> 
> it could to me.  Mebbe I'm just a finiky coder.  For example, in my
> Graphics.E file, there appears to me some variable definitions {a def type=
> 
> statement, I think} near the bottom of the file.  Is this a normal
> procedure?  Or is it a sign that the file is corrupted?

Looking at my copy of graphics.e I see the following:

type frequency(integer x)
    return x >= 0
end type

global procedure sound(frequency f)
-- turn on speaker at frequency f
-- turn off speaker if f is 0
    machine_proc(M_SOUND, f)
end procedure


What this is doing is defining a type called frequency. This is a function that
returns a value. Because it is defined as a 'type', the interpreter also calls it
to validate a value declared as a 'frequency'. What it does is to ensure that its
input is greater than zero. If it is, it returns true or one (same thing in
Euphoria). Else it returns false or zero.

If you make a call
z = frequency(x)
then it checks if x is greater than zero and sets z to one or zero accordingly.

However it you do this:
frequency f -- declare variable f to be a frequency
f = -100 -- program will fail with a typecheck error

It is supposed to help you debug or catch errors in your program.

'frequency' is declared where it is because it is only used by the 'sound'
procedure immediately following it. Since frequency is not declared as 'global'
it cannot be used outside of graphics.e. But since sound *is* declared as global
it will be visible to any file that has the statement
include graphics.e
in it.

Make sense?

--

Have you tried running the examples? Can you tell us what kind of error you are
getting?

I understand you are comparing Euphoria to QBasic and trying to match up what
you know in order to learn what Euphoria provides. But I don't understand your
problems exactly.

Not trying to be unfriendly!

--
"Actually, I'm sitting on my butt staring at a computer screen."
                                                  - Tom Tomorrow

j.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu