1. Definition of terms
- Posted by Paul Kerslake <paulk at UNISERVE.COM> Sep 03, 2000
- 422 views
------=_NextPart_000_0007_01C015CE.5680C5E0 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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. 8-) puts(1,"Thanks") --Thomas ------=_NextPart_000_0007_01C015CE.5680C5E0 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.2614.3500" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <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 = difference=20 between " and ' is.</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>8-)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>puts(1,"Thanks")</FONT></DIV> <DIV><FONT face=3DArial size=3D2>--Thomas</FONT></DIV> <DIV> </DIV> ------=_NextPart_000_0007_01C015CE.5680C5E0--
2. Re: Definition of terms
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET> Sep 03, 2000
- 440 views
Thomas: A constant is just like a variable, in that it can be assigned a value by the programmer, but once assigned, it can't be changed like other variables can: constant pi = 3.141529 ---------------------------------- A procedure is a named routine which accomplishes some task; whenever you call it by putting its name in your main line of code, it activates the routine: procedure Add(integer a, integer b) print(1, a + b) end procedure -- to use it: Add(1,1)-- screen shows "2" ------------------------------------- A function is a named routine which returns a value when called: function Added(integer a, integer b) return a + b end function -- now use it: x = Added(3,4)-- x would be 7 ---------------------------------------------------- As for your last question, "Also, I'd like to know what the difference between " and ' is.", you'll have to finish it first! :) HTH, Dan ----- Original Message ----- From: "Paul Kerslake" <paulk at UNISERVE.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Sunday, September 03, 2000 5:42 PM 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. 8-) puts(1,"Thanks") --Thomas
3. Re: Definition of terms
- Posted by Michael Nelson <MichaelANelson at WORLDNET.ATT.NET> Sep 03, 2000
- 470 views
------=_NextPart_000_000B_01C015D3.F3150E20 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Thomas, Here are some examples: constant TRUE=3D1 constant FALSE=3D0 so we can write: if flag=3DTRUE then . . . rather than if flag=3D1 then . . . A constant simply gives a symbolic name to a value, which is useful for = the readability of the code, but makes no differnce to the running of = the program. A constant is given its value when it is defined and that = value may not be changed. By contrast, a variable's value may change = many times during a program: atom x,y x=3D5 y=3D7 x+=3D1 x=3D(3-x)+(y/2) y*=3D4 Procedures and functions are both examples of subroutines (also known as = routines). These are like small programs of their own which accept = input (the parameters), and in the case of functions produce output (the = return value). Procedures ndo not return a value. function max(object x, object y) if compare(x,y)=3D1 then return x else return y end if end function procedure print_to_screen(sequence text,integer row, integer column, = integer t_color,integer b_color) position(row,column) text_color(t_color) bk_color(b_color) puts(1,text) end rpocedure Procedurers are invoked by the procedure name and the parameters for = example: print_to_screen("This is a procedure",5,25,BRIGHT_WHITE,BLUE) Functions are used in assignments, if statements, and while statements: z=3Dmax(x,y) w=3D{max(x,y),max(p,q)} if max(x,y)>10 then . . . while max(x,y)<5 do=20 Procedures are used to allow the actions in their code to be performed = from anywhere in the program without having to repeat the code. = Functions are primarily used to compute a value from anywhere in the = program without repeating code, but can also perform actions. For = example, I could have written print_to_screen as a function, done some = error checking for valid parameters and returned TRUE or FALSE (as = defined above) to indicate whether the printing was successful or not. = In that case it would be used like this: if print_to_screen("This is a function",5,25,BRIGHT_WHITE,BLUE)=3DTRUE = then -- Printed correctly else -- Printing error end if -- Mike Nelson ----- Original Message -----=20 From: Paul Kerslake=20 To: EUPHORIA at LISTSERV.MUOHIO.EDU=20 Sent: Sunday, September 03, 2000 5:42 PM 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. 8-) puts(1,"Thanks") --Thomas ------=_NextPart_000_000B_01C015D3.F3150E20 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.2919.6307" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT size=3D2>Thomas,</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>Here are some examples:</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>constant TRUE=3D1</FONT></DIV> <DIV><FONT size=3D2>constant FALSE=3D0</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>so we can write:</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>if flag=3DTRUE then . . .</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>rather than</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>if flag=3D1 then . . .</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>A constant simply gives a symbolic name to a value, = which is=20 useful for the readability of the code, but makes no differnce to the = running of=20 the program. A constant is given its value when it is defined and = that=20 value may not be changed. By contrast, a variable's value may = change many=20 times during a program:</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>atom x,y</FONT></DIV> <DIV><FONT size=3D2>x=3D5</FONT></DIV> <DIV><FONT size=3D2>y=3D7</FONT></DIV> <DIV><FONT size=3D2>x+=3D1</FONT></DIV> <DIV><FONT size=3D2>x=3D(3-x)+(y/2)</FONT></DIV> <DIV><FONT size=3D2>y*=3D4</FONT></DIV> <DIV> </DIV> <DIV> </DIV> <DIV><FONT size=3D2>Procedures and functions are both examples of = subroutines=20 (also known as routines). These are like small programs of their = own which=20 accept input (the parameters), and in the case of functions produce = output (the=20 return value). Procedures ndo not return a value.</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>function max(object x, object y)</FONT></DIV> <DIV><FONT size=3D2> if compare(x,y)=3D1 = then</FONT></DIV> <DIV><FONT size=3D2> return = x</FONT></DIV> <DIV><FONT size=3D2> else</FONT></DIV> <DIV><FONT size=3D2> return = y</FONT></DIV> <DIV><FONT size=3D2> end if</FONT></DIV> <DIV><FONT size=3D2>end function</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>procedure print_to_screen(sequence text,integer row, = integer=20 column, integer t_color,integer b_color)</FONT></DIV> <DIV><FONT size=3D2> position(row,column)</FONT></DIV> <DIV><FONT size=3D2> text_color(t_color)</FONT></DIV> <DIV><FONT size=3D2> bk_color(b_color)</FONT></DIV> <DIV><FONT size=3D2> puts(1,text)</FONT></DIV> <DIV><FONT size=3D2>end rpocedure</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>Procedurers are invoked by the procedure name and = the=20 parameters for example:</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>print_to_screen("This is a=20 procedure",5,25,BRIGHT_WHITE,BLUE)</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>Functions are used in assignments, if statements, = and while=20 statements:</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>z=3Dmax(x,y)</FONT></DIV> <DIV><FONT size=3D2>w=3D{max(x,y),max(p,q)}</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>if max(x,y)>10 then . . .</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>while max(x,y)<5 do </FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>Procedures are used to allow the actions in their = code to be=20 performed from anywhere in the program without having to repeat the = code. =20 Functions are primarily used to compute a value from anywhere in the = program=20 without repeating code, but can also perform actions. For example, = I could=20 have written print_to_screen as a function, done some error checking for = valid=20 parameters and returned TRUE or FALSE (as defined above) to indicate = whether the=20 printing was successful or not. In that case it would be used like=20 this:</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>if print_to_screen("This is a=20 function",5,25,BRIGHT_WHITE,BLUE)=3DTRUE then</FONT></DIV> <DIV><FONT size=3D2> -- Printed=20 correctly</FONT></DIV> <DIV><FONT size=3D2>else</FONT></DIV> <DIV><FONT size=3D2> -- Printing=20 error</FONT></DIV> <DIV><FONT size=3D2>end if</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>-- Mike Nelson</FONT></DIV> <BLOCKQUOTE=20 style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: = 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px"> <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV> <DIV=20 style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: = black"><B>From:</B>=20 <A href=3D"mailto:paulk at UNISERVE.COM" title=3Dpaulk at UNISERVE.COM>Paul = Kerslake</A>=20 </DIV> <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A=20 href=3D"mailto:EUPHORIA at LISTSERV.MUOHIO.EDU"=20 title=3DEUPHORIA at LISTSERV.MUOHIO.EDU>EUPHORIA at LISTSERV.MUOHIO.EDU</A> = </DIV> <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Sunday, September 03, = 2000 5:42=20 PM</DIV> <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Definition of = terms</DIV> <DIV><BR></DIV> <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> </DIV> <DIV><FONT face=3DArial size=3D2>8-)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>puts(1,"Thanks")</FONT></DIV> <DIV><FONT face=3DArial size=3D2>--Thomas</FONT></DIV> <DIV> </DIV> ------=_NextPart_000_000B_01C015D3.F3150E20--
4. Re: Definition of terms
- Posted by Michael Nelson <MichaelANelson at WORLDNET.ATT.NET> Sep 03, 2000
- 388 views
------=_NextPart_000_001F_01C015D4.7FA147A0 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Thomas, Forgot to answer your last question: ' is used for an atom, thus atom x x=3D 'A' is the same as atom x x=3D65 -- (65 is the ASCII code for A) while " is used for a sequence sequence y y=3D"AB" is the same as sequence y y=3D{65,66} and sequence y y=3D"A" is the same as sequence y y=3D{65} -- Mike Nelson ----- Original Message -----=20 From: Paul Kerslake=20 To: EUPHORIA at LISTSERV.MUOHIO.EDU=20 Sent: Sunday, September 03, 2000 5:42 PM 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. 8-) puts(1,"Thanks") --Thomas ------=_NextPart_000_001F_01C015D4.7FA147A0 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.2919.6307" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT size=3D2>Thomas,</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>Forgot to answer your last question:</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>' is used for an atom, thus</FONT></DIV> <DIV><FONT size=3D2></FONT> </DIV> <DIV><FONT size=3D2>atom x</FONT></DIV> <DIV><FONT size=3D2>x=3D 'A'</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>is the same as</FONT></DIV> <DIV><FONT size=3D2>atom x</FONT></DIV> <DIV><FONT size=3D2>x=3D65 -- (65 is the ASCII code for A)</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>while " is used for a sequence</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>sequence y</FONT></DIV> <DIV><FONT size=3D2>y=3D"AB"</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>is the same as</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>sequence y</FONT></DIV> <DIV><FONT size=3D2>y=3D{65,66}</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>and</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>sequence y</FONT></DIV> <DIV><FONT size=3D2>y=3D"A"</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>is the same as</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>sequence y</FONT></DIV> <DIV><FONT size=3D2>y=3D{65}</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>-- Mike Nelson</FONT></DIV> <BLOCKQUOTE=20 style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: = 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px"> <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV> <DIV=20 style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: = black"><B>From:</B>=20 <A href=3D"mailto:paulk at UNISERVE.COM" title=3Dpaulk at UNISERVE.COM>Paul = Kerslake</A>=20 </DIV> <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A=20 href=3D"mailto:EUPHORIA at LISTSERV.MUOHIO.EDU"=20 title=3DEUPHORIA at LISTSERV.MUOHIO.EDU>EUPHORIA at LISTSERV.MUOHIO.EDU</A> = </DIV> <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Sunday, September 03, = 2000 5:42=20 PM</DIV> <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Definition of = terms</DIV> <DIV><BR></DIV> <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> </DIV> <DIV><FONT face=3DArial size=3D2>8-)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>puts(1,"Thanks")</FONT></DIV> <DIV><FONT face=3DArial size=3D2>--Thomas</FONT></DIV> <DIV> </DIV> ------=_NextPart_000_001F_01C015D4.7FA147A0--
5. Re: Definition of terms
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET> Sep 03, 2000
- 393 views
Thomas, Sorry, I misread your last question! But I'm glad you asked it, because Michael gave a useful answer (ie, I didn't know the difference, & now I do!). Dan ----- Original Message ----- From: "Paul Kerslake" <paulk at UNISERVE.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Sunday, September 03, 2000 5:42 PM 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. 8-) puts(1,"Thanks") --Thomas
6. Re: Definition of terms
- Posted by chris bensler <bensler at Mailops.Com> Sep 03, 2000
- 406 views
- Last edited Sep 04, 2000
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. > >8-) > >puts(1,"Thanks") >--Thomas > > > > A constant is simply a variable that connot be changed after it is defined. IE. ----------- constant PI=3.1415..etc... ----------- PI is always the same value. So rather than entering 3.1415.... every place you need it, you can just enter PI. A procedure is a user defined command that calls other commands and has no return value. IE ----------- constant Yes=1, No=0 procedure Test(atom YesOrNo) if YesOrNo = Yes then puts(1,"The value entered for Test() was Yes") else puts(1,"The value entered for Test() was No") end if end procedure ------------ A function is the same as a procedure except it returns a value. The main difference between procedures and functions, is that you can use a function in an equation, but not procedures. IE ---------- constant Yes=1, No=0 function Test(atom YesOrNo) return YesOrNo end function if Test(1) = Yes then puts(1,"The value entered for Test() was Yes") else puts(1,"The value entered for Test() was No") end if --------- " is a double quote. Use this the specify a sequence of characters or a string in other words. ' is an apostrophe or single quote. Use this to specify an individual character. IE "This needs to be in double quotes" -- Valid 'A' -- Valid 'These quotes should be surrounding only a single charcter. This is not valid syntax.' -- Invalid Hope th
7. Re: Definition of terms
- Posted by Derek Parnell <derekp at solace.com.au> Sep 04, 2000
- 418 views
------=_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> </DIV></BLOCKQUOTE> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 class=3D380464800-04092000><STRONG>Constant : </STRONG>A special = "variable"=20 that can only be assigned a value once. Typically used for things that = you=20 never 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> 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 =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> A named = piece of=20 source code that can be invoked by other code, 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 of procedures. 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 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> vLineCounter +=3D=20 1</SPAN></FONT></DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 class=3D380464800-04092000> 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> </DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 class=3D380464800-04092000> while 1 do</SPAN></FONT></DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 class=3D380464800-04092000> lLine =3D=20 gets(pInputFile)</SPAN></FONT></DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 class=3D380464800-04092000> if atom(lLine) = then</SPAN></FONT></DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 class=3D380464800-04092000> lLine =3D = {} --=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> = exit</SPAN></FONT></DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 class=3D380464800-04092000> 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> 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> if length(lLine) =3D 1=20 then</SPAN></FONT></DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 class=3D380464800-04092000> 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> 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> if length(lLine >=3D 2)=20 then</SPAN></FONT></DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 class=3D380464800-04092000> 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> = exit</SPAN></FONT></DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 class=3D380464800-04092000> end = if</SPAN></FONT></DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 class=3D380464800-04092000> 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> 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> return lLine -- 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> </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> theLine =3D=20 GetaLine(InputFileHandle)</SPAN></FONT></DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 class=3D380464800-04092000> 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> 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> =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 "=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 '=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> 'C' is the character C as an = atom - namely=20 the value 67 in ASCII</SPAN></FONT></DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 class=3D380464800-04092000> "Thomas" is a sequence of = characters=20 and equivalent to </SPAN></FONT></DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 p; =20 {'T', 'h', 'o', 'm', 'a', 's'}</SPAN></FONT></DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 class=3D380464800-04092000> = which is=20 equilalent to</SPAN></FONT></DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 p; =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 <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> </SPAN></FONT></DIV> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20 ------=_NextPart_000_0001_01C01670.C069EED0--