1. Calling Procedure in an .e file

I have a perfectly working program, and I want to turn it into an include=

file.  So I put procedure module_3() at the top, and end procedure at the=

bottom.  And I make sure that all the variable declarations in the includ=
e
file are outside the procedure.  (One can't declare stuff in a procedure?=
) =

If this is so, how can I declare private variables.  And of course, I
rename the file with an .e extention.

Than I have the following test.ex program:
The test program and the procedure include file are in the same directory=
,
the current directory, but it is not \euphoria\include.

-----test.ex-----
include 33matrix.e
procedure module_3()
-----end test.ex-----

Of course, for those expert Euphorians, you know this didn't work.  =


But when I added end procedure to the .ex file, it executed fine, which
means (I think) that it assumed that procedure module_3 was in the main .=
ex
file.  OK, so what are include files good for?  I don't get it.  How can =
I
call a procedure in an .e file?

--Alan
 =

new topic     » topic index » view message » categorize

2. Re: Calling Procedure in an .e file

At 06:34 PM 5/28/98 -0400, you wrote:
[What are include files?]

Alan:
You have probably figured this out by now
(having a long, quiet weekend without the listserver)

In order to call a function or procedure in an include
file, you have to make it visible to the program that
"includes" it:
-----------------------
--howdy.e
global procedure SayHi()
atom x
  x = 5 * 2
  printf(1,"Hi! Did you know the value of x is: %d ?",x)
end procedure

-----------------------
--main.ex

include howdy.e

SayHi()

------------------------

And yes, you can declare variables within a function or
procedure! In fact, you should generally do that. Global
variables should be very rare, if you want code that
is easy to follow, and doesn't break.


That's all, folks!

Irv

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

3. Re: Calling Procedure in an .e file

>But when I added end procedure to the .ex file, it executed fine, which
>means (I think) that it assumed that procedure module_3 was in the main .ex
>file.  OK, so what are include files good for?  I don't get it.  How can I
>call a procedure in an .e file?


Alan, did you declare your .e procedure as global? If you didn't, module_3()
would be a LOCAL procedure to that file (in this case module33.e I think).
If you declare it global (on the .e file), you can call it from the file
that includes it (in this case your .ex file).

Regards,
    Daniel Berstein
    daber at pair.com

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

4. Re: Calling Procedure in an .e file

Make the procedure global in your include file then simply call it thus:

include 33matrix.e
module_3()


> -----Original Message-----
> From: Euphoria Programming for MS-DOS
> [mailto:EUPHORIA at cwisserver1.mcs.muohio.edu]On Behalf Of Alan Tu
> Sent: Thursday, May 28, 1998 5:34 PM
> To: EUPHORIA at cwisserver1.mcs.muohio.edu
> Subject: Calling Procedure in an .e file
>
>
> I have a perfectly working program, and I want to turn it
> into an include
> file.  So I put procedure module_3() at the top, and end
> procedure at the
> bottom.  And I make sure that all the variable declarations
> in the include
> file are outside the procedure.  (One can't declare stuff in
> a procedure?)
> If this is so, how can I declare private variables.  And of course, I
> rename the file with an .e extention.
>
> Than I have the following test.ex program:
> The test program and the procedure include file are in the
> same directory,
> the current directory, but it is not \euphoria\include.
>
> -----test.ex-----
> include 33matrix.e
> procedure module_3()
> -----end test.ex-----
>
> Of course, for those expert Euphorians, you know this didn't work.
>
> But when I added end procedure to the .ex file, it executed
> fine, which
> means (I think) that it assumed that procedure module_3 was
> in the main .ex
> file.  OK, so what are include files good for?  I don't get
> it.  How can I
> call a procedure in an .e file?
>
> --Alan
>

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

Search



Quick Links

User menu

Not signed in.

Misc Menu