Re: Definition of terms

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

------=_NextPart_000_0001_01C01670.C069EED0
        charset="iso-8859-1"

  Subject: Definition of terms

  Can someone tell me and give me an example of; a constant, a procedure and
a function. Also, I'd like to know what the difference between " and ' is.

Constant : A special "variable" that can only be assigned a value once.
Typically used for things that you never want to change after it has been
set. The use of constants rather than literals in source code is to make the
code more readible.

Examples...
    constant DaysPerWeek = 7,
                  DaysPerFortnight = (DaysPerWeek * 2),
                  DaysPerStdMonth = 30,
                  MonthsPerYear  = 12

Procedure : A named piece of source code that can be invoked by other code,
and receive parameters (data) from the invoking code.
Function :  A named piece of source code that can be invoked by other code,
receive parameters (data) from the invoking code, and return data to the
invoking code.

The main uses of procedures and functions are to reduce the duplication of
commonly used bits of code, to aid readiblity, to generalise certain
behaviours, to limit the scope (and quantity) of bugs, among other things.
The only effective difference between procedures and functions is that
functions must return a value and procedures must not return a value.
However, this often means that functions can be used in the same places that
variables or expressions can. With Euphoria there are some exceptions to
this concept, but often its okay to interchange variables and functions in
expressions.

The names of the parameters on the function and procedure statements, do not
have to be the same as the names of the variables passed to them. However,
the datatype and the number of parameters passed must be exactly as
specified in the function or procedure statement. It is possible to pass
"expressions" to procedures and functions. Euphoria does this by calculating
the result of the expression, silently defining a temporary variable and
passing the variable to the function. The temporary variable is always
hidden from your code, and is removed after it is passed.

The code represented by a procedure or function, often called a routine,
must have a start and and end. The function statement is used to mark the
start of functions and the procedure statement marks the start of
procedures.  These statements also name the routine and define the
parameters it must receive. The routine's end is marked by an end function /
end procedure statement respectively. Each routine in a program must be
uniquely named - no two routines can have the same name. Also, a routine
must be defined earlier in the source code before it can be invoked. You
cannot refer to a routine that comes further on down in the same file.

Examples...

integer vLineCounter
vLineCounter = 0 -- Initialise line counter.

-- This procedure prints a test line with line numbering.
procedure PrintFormatedLine (integer pOutputFile, sequence pData)

    vLineCounter += 1
    printf(pOutputFile, "%5d: %s\n", {vLineCounter, pData})

end procedure

-- This function gets the next non-blank, non-comment line.
function GetaLine (integer pInputFile)
object lLine

 while 1 do
   lLine = gets(pInputFile)
   if atom(lLine) then
     lLine = {}  -- Indicate end-of-file by an "empty" line.
     exit
   end if

   lLine = lLine[1 .. length(lLine) - 1) -- Strip off end-of-line char.
   if length(lLine) = 1 then
     exit -- All one char lines are okay.
   end if

   if length(lLine >= 2) then
     if not equal("--", lLine[1 ..2]) then
      exit
     end if
   end if

 end while

 return lLine  -- This is the data returned to the invoking code.
end function


constant InputFileHandle = open(...., "r")
constant OutputFileHandle = open(..., "w")
sequence theLine

while 1 do
   theLine = GetaLine(InputFileHandle)
   if length(theLine) = 0 then
        exit
   end if

  PrintFormattedLine(OutputFileHandle, theLine)

end while

Double Quotation Marks  " (quotes)
These are used to define a sequence of characters - commonly called a
string.

Single Quotation Marks  ' (apostrophes)
These are used to define a character as an atom.

Examples...
   'C' is the character C as an atom - namely the value 67 in ASCII
   "Thomas"  is a sequence of characters and equivalent to
               {'T', 'h', 'o', 'm', 'a', 's'}
        which is equilalent to
              { 84, 104, 111, 109, 97, 115} in ASCII

These quotation marks provide a simple way of entering strings of characters
and single characters, but note carefully
that  "C" is definitely not the same as 'C' - the first is the sequence {67}
while the second is the atom 67.

----
cheers,
Derek.






------=_NextPart_000_0001_01C01670.C069EED0
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3105.105" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px">
  <DIV class=3DOutlookMessageHeader><FONT face=3D"Times New Roman"=20
  size=3D2><B>Subject:</B> Definition of terms<BR></DIV></FONT>
  <DIV><FONT face=3DArial size=3D2>Can someone tell me and give me an =
example of; a=20
  constant, a procedure and a function. Also, I'd like to know what the=20
  difference between " and ' is.</FONT></DIV>
  <DIV>&nbsp;</DIV></BLOCKQUOTE>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000><STRONG>Constant&nbsp;: </STRONG>A special =
"variable"=20
that can only be assigned a value once. Typically used for things that =
you=20
never&nbsp;want to change after it has been set. The use of =
<STRONG>constants=20
</STRONG>rather than literals in source code is to make the code more=20
readible.</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp;&nbsp; constant DaysPerWeek =3D=20
7,</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
DaysPerFortnight =3D (DaysPerWeek * 2),</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
DaysPerStdMonth =3D 30,</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
MonthsPerYear&nbsp; =3D 12</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000><STRONG>Procedure : </STRONG>A named piece of =
source=20
code that can be invoked by other code, and receive parameters (data) =
from the=20
invoking code. </SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000><STRONG>Function :</STRONG>&nbsp; A named =
piece of=20
source code that can be invoked by other code,&nbsp;receive parameters =
(data)=20
from the invoking code, <STRONG>and</STRONG> return data to the invoking =
code.=20
</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D380464800-04092000>The=20
main uses of procedures and functions are to reduce the duplication of =
commonly=20
used bits of code, to aid readiblity, to generalise certain behaviours, =
to limit=20
the scope (and quantity) of bugs, among other things. The only effective =

difference between procedures and functions is that functions must =
return a=20
value and procedures must not return a value. However, this often means =
that=20
functions can be used in the same places that variables or expressions =
can. With=20
Euphoria there are some exceptions to this concept, but often its okay =
to=20
interchange variables and functions in expressions.</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D380464800-04092000>The=20
names of the parameters on the function and procedure statements, do not =
have to=20
be the same as the names of the variables passed to them. However, the =
datatype=20
and the number of parameters passed must be exactly as specified in the =
function=20
or procedure statement. It is possible to pass "expressions" to =
procedures and=20
functions. Euphoria does this by calculating the result of the =
expression,=20
silently defining a temporary variable and passing the variable to the =
function.=20
The temporary variable is always hidden from your code, and is removed =
after it=20
is passed.</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D380464800-04092000>The=20
code represented by a procedure or function, often called a routine, =
must have a=20
start and and end. The <STRONG>function</STRONG> statement is used to =
mark the=20
start of functions and the <STRONG>procedure</STRONG> statement marks =
the=20
start&nbsp;of procedures.&nbsp; These statements also name the routine =
and=20
define the parameters it must receive. The routine's end is marked by an =

<STRONG>end function</STRONG> / <STRONG>end procedure</STRONG> statement =

respectively. Each routine in a program must be uniquely named - no two =
routines=20
can have the same name. Also, a routine must be defined earlier in the =
source=20
code before it can be invoked. You cannot refer to a routine that comes =
further=20
on down in the same file.</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>integer vLineCounter</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>vLineCounter =3D 0 -- Initialise=20
line&nbsp;counter.</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D380464800-04092000>--=20
This procedure prints a test line with line =
numbering.</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000><STRONG>procedure</STRONG> PrintFormatedLine =
(integer=20
pOutputFile, sequence pData)</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp;&nbsp; vLineCounter +=3D=20
1</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp;&nbsp; printf(pOutputFile, "%5d: =
%s\n",=20
{vLineCounter, pData})</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000><STRONG>end =
procedure</STRONG></SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D380464800-04092000>--=20
This function gets the next non-blank, non-comment =
line.</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000><STRONG>function</STRONG> GetaLine (integer=20
pInputFile)</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV>&nbsp;</DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;while 1 do</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp; lLine =3D=20
gets(pInputFile)</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp; if atom(lLine) =
then</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lLine =3D =
{}&nbsp; --=20
Indicate end-of-file by an "empty" line.</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp;&nbsp;&nbsp; =
exit</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp; end if</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp; lLine =3D lLine[1 .. =
length(lLine) - 1) --=20
Strip off end-of-line char.</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp; if length(lLine)&nbsp;=3D 1=20
then</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit -- All one =
char=20
lines are okay.</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp; end if</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp; if length(lLine &gt;=3D 2)=20
then</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp;&nbsp;&nbsp; if not equal("--", =
lLine[1=20
..2]) then</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
exit</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp;&nbsp;&nbsp; end =
if</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp; end if</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;end while</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;return lLine&nbsp; -- This is the data =
returned=20
to the invoking code.</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000><STRONG>end=20
function</STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>constant InputFileHandle =3D open(....,=20
"r")</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>constant OutputFileHandle =3D open(...,=20
"w")</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>sequence theLine</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D380464800-04092000>while=20
1 do</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp; theLine =3D=20
GetaLine(InputFileHandle)</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp; if length(theLine) =3D 0=20
then</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
exit</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp; end if</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D380464800-04092000>&nbsp;=20
PrintFormattedLine(OutputFileHandle, theLine)</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D380464800-04092000>end=20
while</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000><STRONG>Double Quotation Marks&nbsp; "=20
(quotes)</STRONG></SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D380464800-04092000>These=20
are used to define a sequence of characters - commonly called a string.=20
</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D380464800-04092000>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000><STRONG>Single Quotation Marks&nbsp; '=20
(apostrophes)</STRONG></SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D380464800-04092000>These=20
are used to define a character as an atom.=20
</SPAN></FONT></DIV></SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp; 'C' is the character C as an =
atom - namely=20
the value&nbsp;67 in ASCII</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp; "Thomas"&nbsp; is a sequence of =
characters=20
and equivalent to </SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
{'T', 'h', 'o', 'm', 'a', 's'}</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
which is=20
equilalent to</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
{ 84, 104, 111, 109, 97, 115} in ASCII</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D380464800-04092000>These=20
quotation marks provide a simple way of entering strings of characters =
and=20
single characters, but note carefully</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>that&nbsp; <STRONG>"C"</STRONG> is definitely =
not the=20
same as <STRONG>'C'</STRONG> - the first is the sequence {67} while the =
second=20
is the atom 67.</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D380464800-04092000>&nbsp;&nbsp; </SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20

------=_NextPart_000_0001_01C01670.C069EED0--

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

Search



Quick Links

User menu

Not signed in.

Misc Menu