Re: Definition of terms
- Posted by Michael Nelson <MichaelANelson at WORLDNET.ATT.NET> Sep 03, 2000
- 468 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--