1. Hi I am back and some ?'s
Hi all
I am back trying to learn Euphoria,but I have some ?'s about it so here
goes.
(1) Are procedures like gosubs( they do a certian thing then go from there)
like this
procedure (screen_print,sequnce t)-- if you put seq t here then when the
procedure ends then ends the seq t varable
t=({hi})
puts (1,t)
end procedure
then you can call on sreen_print any time you want it.
(2) Are include files like calling a dll?
When you call a dll you pass the info too the dll then it does it's
thing then returns back the result,What would make a good include file
something that I will use in the furture,or just for this program.I know
that when I make a file called data.e then make it like this
globle procedure (data,seq q1,q2,q3)
q1=({time})
q2=({for})
q3=({lunch})
end procedure
then I can call data in the program and it will return the seq to the
program is this right.
Thanks in advance for the help.
David Mosley
david1 at geocities.com
or
pmosley at infoway.lib.nm.us
2. Re: Hi I am back and some ?'s
>Hi all
>I am back trying to learn Euphoria,but I have some ?'s about it so here
>goes.
Kewl. :)
>(1) Are procedures like gosubs( they do a certian thing then go from
there)
>like this
Far as I know, the procedure is called upon by something in the
designated main procedure, and when the procedure is complete, it goes
back to the main procedure.
>(2) Are include files like calling a dll?
Umm... Its like include files in C, I guess. Just important procedures
to be defined before the actual program. Sorta like this:
include get.e <--- first, has i/o procedures
include whatever.e <-- second, but still important. no such thing that I
know of, but who's counting?
program:
get(0) -- keyboard input, called from get.e procedures.
blahblahblahetcetcetc, whoopee...
Yah. if you know, includes are before the program, etc, and you don't
put program: to define the main part of the program... :) Whether E
files pass info like DLL's, I wouldn't know, but they probably don't.
Yeah... that sounds right...
>Thanks in advance for the help.
>David Mosley
We're here to help! :)
===>=>"LEVIATHAN"<=<===
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
3. Re: Hi I am back and some ?'s
David Mosley asked:
>(1) Are procedures like gosubs( they do a certian thing then go from there)
>like this
>
>procedure (screen_print,sequnce t)-- if you put seq t here then when the
>procedure ends then ends the seq t varable
>t=({hi})
>puts (1,t)
>end procedure
>then you can call on sreen_print any time you want it.
Well, you are right in that a subroutine encapsulates a chunk of code so
that it can be called any time you want it. But a GOSUB is the wrong analogy
for a number of reasons:
- a GOSUB is basically a GOTO with a RETURN. Euphorioa has no GOTOs.
- You can't pass a local parameter list with a GOSUB, like:
GOSUB screen_print, "Print me!"
- A GOSUB routine can't have local (private) variables
A procedure is akin to a subroutine. For example:
QBasic:
SUB screen_print( x AS INTEGER, y AS INTEGER, text AS STRING )
LOCATE( x, y )
print text
END SUB
Euphoria:
procedure screen_position( integer x, integer y, sequence text )
position( x, y )
puts( 1, text )
end procedure
>(2) Are include files like calling a dll?
Sort of - on a very high conceptual level. The main differences between a
DLL and include file are:
1. A DLL is a compiled set of libraries (read: in binary). An include file
is just plain text, like your program.
2. Attaching a DLL routine means linking the DLL, defining a prototype to
the DLL function, and writing a wrapper for that prototype. With a routine
from a include file, you just call it - much less effort.
3. Only the code and variables defined as 'global' can be accessed from the
include file If you don't declare variables and constants within the include
file as global, can only be seen (and used) by code in the include file.
> I know that when I make a file called data.e then make it like this
>
>globle procedure (data,seq q1,q2,q3)
>q1=({time})
>q2=({for})
>q3=({lunch})
>end procedure
>then I can call data in the program and it will return the seq to the
>program is this right.
>
Euphoria can only pass parameters *by value*. That means that a *copy* of
the value is passed to the routine, not the actual variable. Altering a
value of a parameter does not change the value for the caller.
For example:
global procedure data( sequence q1 )
q1 = "time for lunch"
end procedure
sequence q
q = "time for breakfast"
data( q )
puts( 1, q )
would print "time for breakfast", *not* "time for lunch". If you want to get
data back from a routine, you need to define a function, not a procedure.
Euphoria routines can only return a *single* value, You can get around this
by having a function return a sequence filled with values, but then you have
to unpack the sequence. For example:
global function data()
return { "time", "for", lunch" }
end function
sequence result, q1, q2, q3
result = data()
q1 = result[1]
q2 = result[2]
q3 = result[3]
=== WISH LIST ITEM ===
It would look a lot cleaner if you could write:
{ q1, q2, q3 } = data()
instead of:
result = data()
q1 = result[1]
q2 = result[2]
q3 = result[3]
but Euphoria doesn't support it (yet).
=== END WISH LIST ITEM ===
Hope this helps!
-- David Cuny